# Resolving nested git submodule dependencies?

**URL:** <https://ziggit.dev/t/resolving-nested-git-submodule-dependencies/8752>\
**Category:** Help\
**Tags:** c, build-system\
**Created:** [February 26, 2025, 11:43am UTC](https://ziggit.dev/t/resolving-nested-git-submodule-dependencies/8752 "2025-02-26T11:43:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tsdtas](https://ziggit.dev/user_avatar/ziggit.dev/tsdtas/32/3512_2.png) [@tsdtas](https://ziggit.dev/u/tsdtas)\
**Post date:** [February 26, 2025, 11:43am UTC](https://ziggit.dev/t/resolving-nested-git-submodule-dependencies/8752/1 "2025-02-26T11:43:40Z")

</div>

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

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

```zig
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:

```zig
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?

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [February 26, 2025, 12:03pm UTC](https://ziggit.dev/t/resolving-nested-git-submodule-dependencies/8752/2 "2025-02-26T12:03:37Z")

</div>

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](https://github.com/allyourcodebase) but they might be confusing withought explanation

@tensorush perhaps you could add that to [Build System Tricks](https://ziggit.dev/docs?topic=3531)

---

<div class="post-metadata">

**Author:** ![tsdtas](https://ziggit.dev/user_avatar/ziggit.dev/tsdtas/32/3512_2.png) [@tsdtas](https://ziggit.dev/u/tsdtas)\
**Post date:** [February 26, 2025, 12:46pm UTC](https://ziggit.dev/t/resolving-nested-git-submodule-dependencies/8752/3 "2025-02-26T12:46:37Z")

</div>

> lastly you can depend on c libraries through zigs package manager. the only docs/examples of this are in [All Your Codebase · GitHub](https://github.com/allyourcodebase) 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. 🙂

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.

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [February 26, 2025, 12:49pm UTC](https://ziggit.dev/t/resolving-nested-git-submodule-dependencies/8752/4 "2025-02-26T12:49:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tsdtas](https://ziggit.dev/user_avatar/ziggit.dev/tsdtas/32/3512_2.png) [@tsdtas](https://ziggit.dev/u/tsdtas)\
**Post date:** [February 26, 2025, 12:57pm UTC](https://ziggit.dev/t/resolving-nested-git-submodule-dependencies/8752/5 "2025-02-26T12:57:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tensorush](https://ziggit.dev/letter_avatar_proxy/v4/letter/t/6a8cbe/32.png) [@tensorush](https://ziggit.dev/u/tensorush)\
**Post date:** [February 26, 2025, 3:53pm UTC](https://ziggit.dev/t/resolving-nested-git-submodule-dependencies/8752/6 "2025-02-26T15:53:32Z")

</div>

It’s hard to maintain larger examples in a Doc here, which was the initial reason for creating [Liza](https://ziggit.dev/t/liza-zig-codebase-initializer/3486). In fact, it already has a minimal [Zig build template for building C libraries by depending on upstream repos](https://codeberg.org/tensorush/liza/src/branch/main/src/templates/bld/build.zig).

I’ve added a note on that at the end of [Build System Tricks](https://ziggit.dev/docs?topic=3531):

> [@Build System Tricks](https://ziggit.dev/t/build-system-tricks/3531#p-12644-p-s-24):
>
> This community-driven doc is an attempt to expand on the [official Zig Build System documentation](https://ziglang.org/learn/build-system/) as well as the past community contributions by [xq](https://zig.news/xq/series/2), [Sobeston](https://zig.guide/build-system/build-modes/) and others. Here you’ll find a list of tricks on how to use every part of the build system while making sure to conveniently name and lay out your build steps. I. Basic Usage 1) Declare commonly used information upfront // Resolve a query for a custom target const my\_target = b.resolveTargetQuery(.{ .cpu\_arch = .wasm32, .os\_tag =…
