adds package path override
--pkg-path CLI arg and ZIG_LOCAL_PKG_DIR env var are now observed for both fetch and build commands.
subsumes #31950
global vs local
Makes zig fetch only fetch globally, just like it used to. However, if --save (or any variant) is used, then it also fetches locally. When fetching globally, does not require build.zig to be present. zig build always fetches locally (in addition to globally).
Notably, this fixes the use case: zig fetch .
When fetching by path, the hash is always computed, recompressed tarball is always created, always overwrites any existing global cache entry.
closes #31866
bug fix: reject path deps that escape the parent package root
closes #31818
Testing Strategy
Since #31848 is not implemented yet:
- Tested
zig fetch . with and without global cache already populated.
- Tested
zig build --fetch in awebo and ghostty.
- Tested
zig build --fetch in a project that has ghostty as a dependency (allowing the relative paths since they don't escape ghostty root)
Followup issue: I noticed there are memory leaks when running zig build --fetch (not usually noticed due to not using DebugAllocator). Issue filed: #31995
### adds package path override
`--pkg-path` CLI arg and `ZIG_LOCAL_PKG_DIR` env var are now observed for both `fetch` and `build` commands.
subsumes #31950
### global vs local
Makes `zig fetch` only fetch globally, just like it used to. However, if `--save` (or any variant) is used, then it also fetches locally. When fetching globally, does not require `build.zig` to be present. `zig build` always fetches locally (in addition to globally).
Notably, this fixes the use case: `zig fetch .`
When fetching by path, the hash is always computed, recompressed tarball is always created, always overwrites any existing global cache entry.
closes #31866
### bug fix: reject path deps that escape the parent package root
closes #31818
### Testing Strategy
Since https://codeberg.org/ziglang/zig/issues/31848 is not implemented yet:
* Tested `zig fetch .` with and without global cache already populated.
* Tested `zig build --fetch` in awebo and ghostty.
* Tested `zig build --fetch` in a project that has ghostty as a dependency (allowing the relative paths since they don't escape ghostty root)
Followup issue: I noticed there are memory leaks when running `zig build --fetch` (not usually noticed due to not using DebugAllocator). Issue filed: https://codeberg.org/ziglang/zig/issues/31995