Is there a way to compile part of a shader into a spirv? I want to have separate files for common things for shaders precompiled into a spirv.
For example PBR, I've got these functions and implementations for them
float NDFGGX(float NdotH, float roughness);
float GeometrySchlickGGX(float NdotV, float k);
float GeometrySmith(float NdotL, float NdotV, float roughness);
vec3 FresnelSchlick(float cosTheta, vec3 F0);

and I don't want to generate binaries for them every time I use it in a new shader.
What I want is to generate a SPIRV binary file once and do whatever I want with it.
Is this possible?
What I've tried is to use shaderc library and create the binary as if it were a vertex shader, but it then needs glsl version and entry point. Not every file'd have entry point, doe.
What you want is generally not possible for OpenGL's SPIR-V support. SPIR-V compiles to shader objects, and shader objects theoretically allow you to link multiple objects of the same stage in a program. However, OpenGL's usage of SPIR-V requires that each SPIR-V shader be a complete shader stage with its entrypoint function.
So the requirement of shaderc mirrors the requirements of OpenGL.
The best you could do is combine multiple SPIR-V binaries into a single binary before handing it off to OpenGL. But that's a non-trivial process, since you basically have to renumber every reference in at least one of them, and combine any references that map to the same type.