Description
#20178 is not technically a prerequisite for this, but the two proposals would work well together.
It would be nice if you could do something like this:
$ cd my-zig-project
$ git clone git://example.com/zlib/ .zig-cache/p/$(zig pkg-hash zlib)
or
$ cd my-zig-project
$ ln -s $HOME/path-to-local-zlib-checkout/ .zig-cache/p/$(zig pkg-hash zlib)
then you could make edits to .zig-cache/p/<pkg hash>
that would override the global packages, as well as make it easy to interact with the upstream source control of the dependency.
Crucially, these directories are typically not tracked by source control, making the workflow convenient to test a patch to a dependency.
When building with local overrides, a warning should be issued:
$ zig build
warning: overriding 'zlib' dependency with './zig-cache/p/zlib-1.3.1-3-IQwAAPXlgi9M'
When building in --system
mode, it ignores local overrides with a warning:
$ zig build --system /usr/lib/zig/p
warning: ignoring local override './zig-cache/p/zlib-1.3.1-3-IQwAAPXlgi9M' in system mode
zig pkg-hash --list
would list all the immediate dependency packages and their hashes:
$ zig pkg-hash --list
libz zlib-1.3.1-3-IQwAAPXlgi9M
libvorbis libvorbis-1.3.8-3-NQ8kAD5eWxrE
Then you could drill down into the sub-dependencies:
$ zig pkg-hash --list libvorbis
libvorbis.libz zlib-1.3.1-3-IQwAAPXlgi9M
Or maybe --list
would just print the whole tree.
Perhaps another subcommand could do the path calculation, so even if you're in a subdirectory, it would give you the local override path:
andy@ark:~/my-project/build$ zig lop libvorbis.libz
../.zig-cache/p/zlib-1.3.1-3-IQwAAPXlgi9M
andy@ark:~/my-project/build$ zig lop libvorbis.libztypo
error: no dependency package named 'libvorbis.libztypo'
info: use `zig pkg-hash --list` to browse dependency tree
This would be a way to quickly find out the command line to pass to e.g. git clone
.
Another part of this workflow would be finding out the list of overrides that have mismatching hashes. Perhaps:
zig lop --clean
- delete all local overrides with mismatching hasheszig lop --clear
- delete all local overrideszig lop --status
- list all local overrides, their expected hashes, and actual hashes (when mismatching)
Related:
- add tooling to deal with build.zig dependency trees #14288, which introduces the concept of a "project ID".