cmake: remove --zig-lib-dir arg from zig build

This demonstrates one of the downsides of the approach in this branch:
since `zig build` CLI is intentionally unaware of the command line
parsing that will be done by the child process, it cannot obtain zig lib
dir override from the command line even as it needs that information in
order to build the subcommand.

Consequently, zig lib dir has to be passed via env var. CMake does not
provide a way to do this. So instead we rely on Zig's automatic lookup
functionality.

This could be mitigated by adding CLI arg parsing that happens *before*
the subcommand. I find this kind of special case to be awkward and
unpleasant however. I think it's better to simply remove the ability to
pass `--zig-lib-dir` to `zig build`.
This commit is contained in:
Andrew Kelley committed 2026-06-29 23:50:19 -07:00
1 parent a802ec7b3e
commit d4b7050555
29 files changed
+85 -39

No files matched your search

-2
View File
@@ -729,8 +729,6 @@ endif()
set(ZIG_BUILD_ARGS
--zig-lib-dir "${PROJECT_SOURCE_DIR}/lib"
"-Dversion-string=${RESOLVED_ZIG_VERSION}"
"-Dtarget=${ZIG_TARGET_TRIPLE}"
"-Dcpu=${ZIG_TARGET_MCPU}"
+3 -1
View File
@@ -40,12 +40,14 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
stage3-debug/bin/zig build \
+3 -1
View File
@@ -40,12 +40,14 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
# Ensure that stage3 and stage4 are byte-for-byte identical.
+3 -1
View File
@@ -42,6 +42,9 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
@@ -49,7 +52,6 @@ stage3-debug/bin/zig build test docs \
-Dskip-non-native \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml \
--test-timeout 3m
+3 -1
View File
@@ -42,6 +42,9 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
@@ -49,7 +52,6 @@ stage3-release/bin/zig build test docs \
-Dskip-non-native \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml \
--test-timeout 3m
+3 -1
View File
@@ -43,9 +43,11 @@ cmake .. \
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
--zig-lib-dir "$PWD/../lib" \
-Denable-macos-sdk \
-Dstatic-llvm \
-Dskip-spirv \
+3 -1
View File
@@ -43,8 +43,10 @@ cmake .. \
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
stage3-release/bin/zig build test docs \
--zig-lib-dir "$PWD/../lib" \
-Denable-macos-sdk \
-Dstatic-llvm \
-Dskip-spirv \
+3 -1
View File
@@ -40,12 +40,14 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
stage3-debug/bin/zig build \
+3 -1
View File
@@ -40,12 +40,14 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
# Ensure that stage3 and stage4 are byte-for-byte identical.
+3 -2
View File
@@ -4,7 +4,6 @@ $MCPU = "baseline"
$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip"
$PREFIX_PATH = "$(Get-Location)\..\$ZIG_LLVM_CLANG_LLD_NAME"
$ZIG = "$PREFIX_PATH\bin\zig.exe"
$ZIG_LIB_DIR = "$(Get-Location)\lib"
$ZSF_MAX_RSS = if ($Env:ZSF_MAX_RSS) { $Env:ZSF_MAX_RSS } else { 0 }
if (!(Test-Path "..\$ZIG_LLVM_CLANG_LLD_NAME.zip")) {
@@ -53,10 +52,12 @@ CheckLastExitCode
ninja install
CheckLastExitCode
# Must be done after zig cc is finished.
$Env:ZIG_LIB_DIR="$(Get-Location)\..\lib"
Write-Output "Main test suite..."
& "stage3-release\bin\zig.exe" build test docs `
--maxrss $ZSF_MAX_RSS `
--zig-lib-dir "$ZIG_LIB_DIR" `
--search-prefix "$PREFIX_PATH" `
-Dstatic-llvm `
-Dskip-non-native `
+3 -1
View File
@@ -40,6 +40,9 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
@@ -47,7 +50,6 @@ stage3-debug/bin/zig build test docs \
-Dskip-non-native \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
stage3-debug/bin/zig build \
+3 -1
View File
@@ -40,6 +40,9 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
@@ -47,7 +50,6 @@ stage3-release/bin/zig build test docs \
-Dskip-non-native \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
# Ensure that stage3 and stage4 are byte-for-byte identical.
+3 -1
View File
@@ -40,6 +40,9 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
@@ -48,7 +51,6 @@ stage3-debug/bin/zig build test docs \
-Dtarget=native-native-musl \
-Dcpu=native+longcall \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
stage3-debug/bin/zig build \
+3 -1
View File
@@ -40,6 +40,9 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
@@ -48,7 +51,6 @@ stage3-release/bin/zig build test docs \
-Dtarget=native-native-musl \
-Dcpu=native+longcall \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
# Ensure that stage3 and stage4 are byte-for-byte identical.
+3 -1
View File
@@ -42,6 +42,9 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-debug/bin/zig build test-modules test-c-abi \
--maxrss ${ZSF_MAX_RSS:-0} \
@@ -50,5 +53,4 @@ stage3-debug/bin/zig build test-modules test-c-abi \
-Dskip-single-threaded \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
+3 -1
View File
@@ -42,6 +42,9 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-release/bin/zig build test-modules test-c-abi \
--maxrss ${ZSF_MAX_RSS:-0} \
@@ -50,5 +53,4 @@ stage3-release/bin/zig build test-modules test-c-abi \
-Dskip-single-threaded \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
+3 -1
View File
@@ -40,6 +40,9 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
@@ -47,7 +50,6 @@ stage3-debug/bin/zig build test docs \
-Dskip-non-native \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
stage3-debug/bin/zig build \
+3 -1
View File
@@ -40,6 +40,9 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
@@ -47,7 +50,6 @@ stage3-release/bin/zig build test docs \
-Dskip-non-native \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 4m
# Ensure that stage3 and stage4 are byte-for-byte identical.
+3 -1
View File
@@ -40,6 +40,9 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
@@ -51,7 +54,6 @@ stage3-debug/bin/zig build test docs \
-Dskip-windows \
-Dskip-darwin \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 2m
stage3-debug/bin/zig build \
+3 -1
View File
@@ -40,6 +40,9 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
@@ -51,7 +54,6 @@ stage3-release/bin/zig build test docs \
-Dskip-windows \
-Dskip-darwin \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 2m
# Ensure that the fuzzer at least compiles.
+3 -1
View File
@@ -43,6 +43,9 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
# simultaneously test building self-hosted without LLVM and with 32-bit arm
stage3-debug/bin/zig build \
-Dtarget=arm-linux-musleabihf \
@@ -63,7 +66,6 @@ stage3-debug/bin/zig build test docs \
-Dskip-darwin \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml \
--test-timeout 12m
+3 -1
View File
@@ -42,6 +42,9 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
# simultaneously test building self-hosted without LLVM and with 32-bit arm
stage3-debug/bin/zig build \
-Dtarget=arm-linux-musleabihf \
@@ -63,7 +66,6 @@ stage3-debug/bin/zig build test docs \
-Dskip-llvm \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml \
--test-timeout 10m
+4 -3
View File
@@ -48,6 +48,9 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
# Covers several things:
# 1. building the compiler without LLVM
# 2. 32-bit
@@ -66,7 +69,6 @@ stage3-release/bin/zig build test docs \
-Dstatic-llvm \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml \
--test-timeout 12m
@@ -120,6 +122,5 @@ stage3/bin/zig build -p stage4 \
-Dstatic-llvm \
-Dtarget=native-native-musl \
-Dno-lib \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib"
--search-prefix "$PREFIX"
stage4/bin/zig test ../test/behavior.zig
+3 -1
View File
@@ -40,12 +40,14 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 2m
stage3-debug/bin/zig build \
+3 -1
View File
@@ -40,12 +40,14 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 2m
# Ensure that the fuzzer at least compiles.
+3 -1
View File
@@ -40,12 +40,14 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
stage3-debug/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 2m
stage3-debug/bin/zig build \
+3 -1
View File
@@ -40,12 +40,14 @@ unset CXX
ninja install
# Must be done after zig cc is finished.
export ZIG_LIB_DIR="$PWD/../lib"
stage3-release/bin/zig build test docs \
--maxrss ${ZSF_MAX_RSS:-0} \
-Dstatic-llvm \
-Dskip-non-native \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
--test-timeout 2m
# Ensure that the fuzzer at least compiles.
+3 -4
View File
@@ -2,7 +2,6 @@ $TARGET = "x86_64-windows-gnu"
$MCPU = "baseline"
$PREFIX_PATH = "$($Env:USERPROFILE)\deps\zig+llvm+lld+clang-$TARGET-0.17.0-dev.203+073889523"
$ZIG = "$PREFIX_PATH\bin\zig.exe"
$ZIG_LIB_DIR = "$(Get-Location)\lib"
$ZSF_MAX_RSS = if ($Env:ZSF_MAX_RSS) { $Env:ZSF_MAX_RSS } else { 0 }
function CheckLastExitCode {
@@ -42,10 +41,12 @@ CheckLastExitCode
ninja install
CheckLastExitCode
# Must be done after zig cc is finished.
$Env:ZIG_LIB_DIR="$(Get-Location)\..\lib"
Write-Output "Main test suite..."
stage3-debug\bin\zig build test docs `
--maxrss $ZSF_MAX_RSS `
--zig-lib-dir "$ZIG_LIB_DIR" `
--search-prefix "$PREFIX_PATH" `
-Dstatic-llvm `
-Dskip-non-native `
@@ -56,7 +57,6 @@ CheckLastExitCode
Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..."
stage3-debug\bin\zig build-obj `
--zig-lib-dir "$ZIG_LIB_DIR" `
-ofmt=c `
-OReleaseSmall `
--name compiler_rt `
@@ -67,7 +67,6 @@ stage3-debug\bin\zig build-obj `
CheckLastExitCode
stage3-debug\bin\zig test `
--zig-lib-dir "$ZIG_LIB_DIR" `
-ofmt=c `
-femit-bin="behavior-x86_64-windows-msvc.c" `
--test-no-exec `
+3 -4
View File
@@ -2,7 +2,6 @@ $TARGET = "x86_64-windows-gnu"
$MCPU = "baseline"
$PREFIX_PATH = "$($Env:USERPROFILE)\deps\zig+llvm+lld+clang-$TARGET-0.17.0-dev.203+073889523"
$ZIG = "$PREFIX_PATH\bin\zig.exe"
$ZIG_LIB_DIR = "$(Get-Location)\lib"
$ZSF_MAX_RSS = if ($Env:ZSF_MAX_RSS) { $Env:ZSF_MAX_RSS } else { 0 }
function CheckLastExitCode {
@@ -42,10 +41,12 @@ CheckLastExitCode
ninja install
CheckLastExitCode
# Must be done after zig cc is finished.
$Env:ZIG_LIB_DIR="$(Get-Location)\..\lib"
Write-Output "Main test suite..."
stage3-release\bin\zig.exe build test docs `
--maxrss $ZSF_MAX_RSS `
--zig-lib-dir "$ZIG_LIB_DIR" `
--search-prefix "$PREFIX_PATH" `
-Dstatic-llvm `
-Dskip-non-native `
@@ -82,7 +83,6 @@ CheckLastExitCode
Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..."
stage3-release\bin\zig.exe build-obj `
--zig-lib-dir "$ZIG_LIB_DIR" `
-ofmt=c `
-OReleaseSmall `
--name compiler_rt `
@@ -93,7 +93,6 @@ stage3-release\bin\zig.exe build-obj `
CheckLastExitCode
stage3-release\bin\zig.exe test `
--zig-lib-dir "$ZIG_LIB_DIR" `
-ofmt=c `
-femit-bin="behavior-x86_64-windows-msvc.c" `
--test-no-exec `