…and at some later point I started another experimental project to run those emulators in a terminal:
The chipz project is already split into a couple of modules which are automatically available in upstream projects:
In the upstream project I have a dependency to chipz:
…and I import the chipz module like this:
…and then import a specific submodule of chipz like this:
…Zig itself will only compile code that’s actually used into such an emulator executable, so no problems there.
But one problem I’ll need to fix is that my chipz build.zig is setup in a way to always build everything, e.g. when only the chipz dependency is used by an upstream project, it will also build all the emulator exes from the chipz project, plus code-generation and benchmark tools, even though those things are useless for the upstream project… but that’s on me, I was just dumb when writing the chipz build.zig.
If you can come up with a better way to re-export all submodules under a common chipz module than be my guest (I tried a couple of different options, but this was the cleanest).
IIRC the top-level chipz module was only added after making the chipz project available as dependency. The individual module definitions are needed for cross-import within the project, while for use as dependency only the top-level chipz module is relevant.
An import alone doesn’t cause compilation of the entire import, only of the parts that are actually used, otherwise any @import("std") in regular Zig code would explode build times.