Resolving transitive dependencies in a git submodule

Note: zig version is 0.12.0-dev.152+411462e1c

This is probably an edge case but I thought it might be worth bringing up. I am fooling around with zig-gamedev, a nice collection of game and graphics libraries, which is included in my project as a git submodule in my libs/ directory. zig-gamedev has a build.zig.zon file which names Dawn, Google’s webgpu implementation, as a dependency. So far so good, building zig-gamedev fetches Dawn and all is well.

However, building my top-level project fails because of an unresolved dependency on Dawn. The obvious solution was to add the Dawn dependency to my own build.zig.zon and now the build works. But this is not great as Dawn is a transitive dependency from my project’s perspective. My code never uses Dawn directly. In other words, ideally I shouldn’t have to name Dawn in my build.zig.zon as it’s already named elsewhere in the source tree.

Is this git submodule thing a viable edge case that should be addressed by the package manager adding submodule dependencies to the dependency graph, or must we name all transitive dependencies when including git submodules in our source trees?

Or maybe in these cases, the top-level build.zig.zon could do eg “import libs/zig-gamedev/build.zig.zon” as a compromise?

Finally, my apologies if this is already on the roadmap, I haven’t kept up with package manager development.

I think the package manager and build system are supposed to be more than enough to handle your project’s dependencies. Is there a reason you have to use a git submodule versus depending on the library directly via build.zig and build.zig.zon?

The docs for zig-gamedev specify adding it as a git submodule. From the docs:

"To use zig-gamedev in your project copy or download zig-gamedev as a submodule, for example:

git submodule add https://github.com/michal-z/zig-gamedev.git libs/zig-gamedev"

See GitHub - zig-gamedev/zig-gamedev: Main monorepo for @zig-gamedev libs and example applications

I don’t think this is a terribly uncommon approach for non-trivial libraries that you might want to include in your project, mainly because few projects have been packaged at this point. Maybe in the future, zig-gamedev will be packaged and this problem will go away, I don’t really know for sure.

I like to use a git submodule so I can directly view and edit the source code of my dependencies - it has come in handy quite often, and is something I miss dearly from languages like C# where dependencies are almost exclusively managed through a package manager.

For importing the dependencies of a local dependency, you can put a relative path in your build.zig.zon, so for example you can put .path = "llibs/zig-gamedev". (assuming you are using a recent enough version of Zig)
This PR is where it as added

Zig is still very young, and package management is still under heavy debate. Until the Zig developers come to a good solution that people are happy with, things will keep changing, so don’t worry too much about future-proofing.