zig: move ZIG_GLOBAL_CACHE_DIR setup to configurePhase

This allows users to put zig in their `mkShell` without ending up with a
ZIG_GLOBAL_CACHE_DIR value set that points back to a location that only
would exist in the sandbox.
This commit is contained in:
Jared Baur
2026-01-12 09:02:04 -08:00
parent 5bfbbc27f6
commit e20232eab6
3 changed files with 15 additions and 3 deletions

View File

@@ -32,6 +32,10 @@ stdenv.mkDerivation {
The variables below are exclusive to `zig`.
#### `dontUseZigConfigure` {#dont-use-zig-configure}
Disables using `zigConfigurePhase`.
#### `dontUseZigBuild` {#dont-use-zig-build}
Disables using `zigBuildPhase`.

View File

@@ -2762,6 +2762,9 @@
"index.html#zig-exclusive-variables",
"index.html#zig-hook-exclusive-variables"
],
"dont-use-zig-configure": [
"index.html#dont-use-zig-configure"
],
"dont-use-zig-build": [
"index.html#dont-use-zig-build"
],

View File

@@ -4,9 +4,13 @@
readonly zigDefaultCpuFlag=@zig_default_cpu_flag@
readonly zigDefaultOptimizeFlag=@zig_default_optimize_flag@
function zigSetGlobalCacheDir {
function zigConfigurePhase {
runHook preConfigure
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d)
export ZIG_GLOBAL_CACHE_DIR
runHook postConfigure
}
function zigBuildPhase {
@@ -97,8 +101,9 @@ function zigInstallPhase {
runHook postInstall
}
# shellcheck disable=SC2154
addEnvHooks "$hostOffset" zigSetGlobalCacheDir
if [ -z "${dontUseZigConfigure-}" ] && [ -z "${configurePhase-}" ]; then
configurePhase=zigConfigurePhase
fi
if [ -z "${dontUseZigBuild-}" ] && [ -z "${buildPhase-}" ]; then
buildPhase=zigBuildPhase