In C/C++ you can access a library's type definitions without linking the library by just including the header files. That way you can know what a library's types and definitions are and as long as you don't call any functions from the library it all works out. I sort of want to do the same thing.
I have two executables, a build tool that creates an asset pack file, and the actual game that then decodes the asset pack file. The asset packer needs a ton of heavy dependencies like glslang and zstbi and libvorbis and a gltf reader etc etc to parse the asset files and encode them, but decoding the assets needs no dependencies. And well, the whole point of the separate executable is so these libraries don't get linked into the actual game.
I am in a bit of a pickle though as I want to define every "process" of the asset pipeline (as in, hlsl to spirv, png to texture atlas, etc) in just one place. And the decoder needs to know at the very least what the packed data is and the metadata (shader reflection, texture width and height, animation speed, etc), which is defined in the process (in the module that links the dependencies)..
So far my ideas are:
- Duplicate code, but this is bad for obvious reasons
- Split off the process "definition" (types) and "implementation" into different modules, but this makes it all very annoying to code.
- Build-time option that controls whether to link the libraries or not, if false, turns all code into stub functions, keeping only type definitions. But this still would fail at any kind of
@import("glslang")-style line at the top of the file, as now the dependency isn't linked. Meaning I would have to@importthe dependencies inside the implementation's function bodies? Not even sure if you can do that.
Would love to hear more ideas on how to deal with this!