Resolving nested git submodule dependencies?

I depend on a C library that is packaged through git submodules.

That is, the library git repository is more-or-less empty:

repo
|_ _ .gitmodules //list of git repositories for module1, module2...
|_ _ module1
|       //empty folder
|_ _ module2 
|       //empty folder
.
.
.

Furthermore, each of those modules are also packaged like this, with dependencies nested as submodules, and the build instructions are:

git clone <url> dirname
cd dirname
git submodule update --init --recursive //fills out the subfolders
//further build instructions

Is there a way for me to specify this behaviour in my build.zig.zon file, without having to crawl the dependency tree manually for a complete list of git repositories to download?

you can run system commands with b.addSystemCommand which returns a run step which your lib/exe compile step should depend on.

Also when passing dir/file args to commands use the respective functions instead of adding them as raw args, this is so the build system is aware of them and will cache them.

lastly you can depend on c libraries through zigs package manager. the only docs/examples of this are in All Your Codebase · GitHub but they might be confusing withought explanation

@tensorush perhaps you could add that to Build System Tricks

1 Like

lastly you can depend on c libraries through zigs package manager. the only docs/examples of this are in All Your Codebase · GitHub but they might be confusing withought explanation

I am aware, I’m trying to package a library we use at the company I work at so it’s fetchable with the package manager. :slight_smile:

If I packaged every module, then the modules could depend on each other in the “correct” way. That would resolve this, but it’d involve writing quite a lot of boilerplate build scripts.

you could just invoke whatever build system they use and just use the resulting object/library, you can still do that while using the zig package manager

I already do that when building it now, but then I depend on system tools. Part of porting the build system to Zig is (hopefully) removing those system dependencies.

Either way I think I convinced myself that the “correct” solution here is to package the dependencies of the library too, so I’m marking this solved.

It’s hard to maintain larger examples in a Doc here, which was the initial reason for creating Liza. In fact, it already has a minimal Zig build template for building C libraries by depending on upstream repos.

I’ve added a note on that at the end of Build System Tricks:

3 Likes