From 0700ec35bda705fccb61cb3f28734ce11166fda5 Mon Sep 17 00:00:00 2001 From: alexrp Date: Sun, 21 Sep 2025 08:47:21 +0200 Subject: [PATCH 1/6] compiler: don't use self-hosted backend on any BSD yet There are some blocking bugs in the self-hosted ELF linker. --- src/target.zig | 2 +- test/src/StackTrace.zig | 2 +- test/tests.zig | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/target.zig b/src/target.zig index e999d2ae22..6326f3c3a1 100644 --- a/src/target.zig +++ b/src/target.zig @@ -238,7 +238,7 @@ pub fn hasLldSupport(ofmt: std.Target.ObjectFormat) bool { pub fn selfHostedBackendIsAsRobustAsLlvm(target: *const std.Target) bool { if (target.cpu.arch.isSpirV()) return true; if (target.cpu.arch == .x86_64 and target.ptrBitWidth() == 64) { - if (target.os.tag == .netbsd or target.os.tag == .openbsd) { + if (target.os.tag.isBSD()) { // Self-hosted linker needs work: https://github.com/ziglang/zig/issues/24341 return false; } diff --git a/test/src/StackTrace.zig b/test/src/StackTrace.zig index ff3bbe708b..9b51f4e4b2 100644 --- a/test/src/StackTrace.zig +++ b/test/src/StackTrace.zig @@ -45,7 +45,7 @@ fn addCaseInner(self: *StackTrace, config: Config, use_llvm: bool) void { fn shouldTestNonLlvm(target: *const std.Target) bool { return switch (target.cpu.arch) { .x86_64 => switch (target.ofmt) { - .elf => true, + .elf => !target.os.tag.isBSD(), else => false, }, else => false, diff --git a/test/tests.zig b/test/tests.zig index a99b7c703b..5b0dfc40a7 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -2451,8 +2451,9 @@ pub fn wouldUseLlvm(use_llvm: ?bool, query: std.Target.Query, optimize_mode: Opt else => return true, } const cpu_arch = query.cpu_arch orelse builtin.cpu.arch; + const os_tag = query.os_tag orelse builtin.os.tag; switch (cpu_arch) { - .x86_64 => if (std.Target.ptrBitWidth_arch_abi(cpu_arch, query.abi orelse .none) != 64) return true, + .x86_64 => if (os_tag.isBSD() or std.Target.ptrBitWidth_arch_abi(cpu_arch, query.abi orelse .none) != 64) return true, .spirv32, .spirv64 => return false, else => return true, } From f7d62009ff756a3c9cc79dbad88f51e44d1b4352 Mon Sep 17 00:00:00 2001 From: alexrp Date: Sun, 21 Sep 2025 08:46:37 +0200 Subject: [PATCH 2/6] std.posix: remove bogus assert that SIGRTMAX < NSIG --- lib/std/posix/test.zig | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/std/posix/test.zig b/lib/std/posix/test.zig index 85651c13a5..cd322945d3 100644 --- a/lib/std/posix/test.zig +++ b/lib/std/posix/test.zig @@ -644,7 +644,6 @@ test "sigrtmin/max" { try std.testing.expect(posix.sigrtmin() >= 32); try std.testing.expect(posix.sigrtmin() >= posix.system.sigrtmin()); try std.testing.expect(posix.sigrtmin() < posix.system.sigrtmax()); - try std.testing.expect(posix.sigrtmax() < posix.NSIG); } test "sigset empty/full" { From b2d2b441b2cbf15a01ca386b0df5c2103c1be24b Mon Sep 17 00:00:00 2001 From: alexrp Date: Mon, 22 Sep 2025 01:33:21 +0200 Subject: [PATCH 3/6] test: disable test-link on FreeBSD https://github.com/ziglang/zig/issues/25323 --- test/link/elf.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/link/elf.zig b/test/link/elf.zig index 16ee824da7..161dcf2d32 100644 --- a/test/link/elf.zig +++ b/test/link/elf.zig @@ -2,6 +2,9 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { _ = build_opts; const elf_step = b.step("test-elf", "Run ELF tests"); + // https://github.com/ziglang/zig/issues/25323 + if (builtin.os.tag == .freebsd) return elf_step; + const default_target = b.resolveTargetQuery(.{ .cpu_arch = .x86_64, // TODO relax this once ELF linker is able to handle other archs .os_tag = .linux, @@ -4285,6 +4288,7 @@ const addStaticLibrary = link.addStaticLibrary; const expectLinkErrors = link.expectLinkErrors; const link = @import("link.zig"); const std = @import("std"); +const builtin = @import("builtin"); const Build = std.Build; const BuildOptions = link.BuildOptions; From b3432c2796979c4a0e137153414df61282b5626a Mon Sep 17 00:00:00 2001 From: alexrp Date: Mon, 22 Sep 2025 01:34:53 +0200 Subject: [PATCH 4/6] test: disable some stack trace tests on FreeBSD --- test/stack_traces.zig | 2 ++ test/standalone/stack_iterator/build.zig | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/stack_traces.zig b/test/stack_traces.zig index 9e815e032f..d2523daf52 100644 --- a/test/stack_traces.zig +++ b/test/stack_traces.zig @@ -803,6 +803,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void { .s390x, }, .exclude_os = &.{ + .freebsd, .openbsd, // integer overflow .windows, // TODO intermittent failures }, @@ -847,6 +848,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void { }, .ReleaseSafe = .{ .exclude_os = &.{ + .freebsd, .windows, // TODO .linux, // defeated by aggressive inlining .macos, // Broken in LLVM 20. diff --git a/test/standalone/stack_iterator/build.zig b/test/standalone/stack_iterator/build.zig index 8d2c448215..b6ac2a9aee 100644 --- a/test/standalone/stack_iterator/build.zig +++ b/test/standalone/stack_iterator/build.zig @@ -61,8 +61,12 @@ pub fn build(b: *std.Build) void { .use_llvm = true, }); - const run_cmd = b.addRunArtifact(exe); - test_step.dependOn(&run_cmd.step); + if (builtin.os.tag != .freebsd) { + const run_cmd = b.addRunArtifact(exe); + test_step.dependOn(&run_cmd.step); + } else { + test_step.dependOn(&exe.step); + } } // https://github.com/ziglang/zig/issues/24522 From 3675074c7c2fe45f312e3246efda2632315eb9c3 Mon Sep 17 00:00:00 2001 From: alexrp Date: Sun, 21 Sep 2025 07:43:18 +0200 Subject: [PATCH 5/6] ci: add x86_64-freebsd scripts --- ci/x86_64-freebsd-debug.sh | 71 +++++++++++++++++++++++++++++++++ ci/x86_64-freebsd-release.sh | 77 ++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100755 ci/x86_64-freebsd-debug.sh create mode 100755 ci/x86_64-freebsd-release.sh diff --git a/ci/x86_64-freebsd-debug.sh b/ci/x86_64-freebsd-debug.sh new file mode 100755 index 0000000000..9b0f6f5c26 --- /dev/null +++ b/ci/x86_64-freebsd-debug.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +# Requires cmake ninja-build + +set -x +set -e + +ARCH="x86_64" +TARGET="$ARCH-freebsd-none" +MCPU="baseline" +CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.312+164c598cd" +PREFIX="$HOME/deps/$CACHE_BASENAME" +ZIG="$PREFIX/bin/zig" + +# Make the `zig version` number consistent. +# This will affect the cmake command below. +git fetch --unshallow || true +git fetch --tags + +# Override the cache directories because they won't actually help other CI runs +# which will be testing alternate versions of zig, and ultimately would just +# fill up space on the hard drive for no reason. +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" + +mkdir build-debug +cd build-debug + +export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" +export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" + +cmake .. \ + -DCMAKE_INSTALL_PREFIX="stage3-debug" \ + -DCMAKE_PREFIX_PATH="$PREFIX" \ + -DCMAKE_BUILD_TYPE=Debug \ + -DZIG_TARGET_TRIPLE="$TARGET" \ + -DZIG_TARGET_MCPU="$MCPU" \ + -DZIG_STATIC=ON \ + -DZIG_NO_LIB=ON \ + -GNinja \ + -DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \ + -DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE +# https://github.com/ziglang/zig/issues/22213 + +# Now cmake will use zig as the C/C++ compiler. We reset the environment variables +# so that installation and testing do not get affected by them. +unset CC +unset CXX + +ninja install + +stage3-debug/bin/zig build test docs \ + --maxrss 32212254720 \ + -Dstatic-llvm \ + -Dskip-linux \ + -Dskip-netbsd \ + -Dskip-windows \ + -Dskip-macos \ + -Dtarget=native-native-none \ + --search-prefix "$PREFIX" \ + --zig-lib-dir "$PWD/../lib" + +stage3-debug/bin/zig build \ + --prefix stage4-debug \ + -Denable-llvm \ + -Dno-lib \ + -Dtarget=$TARGET \ + -Duse-zig-libcxx \ + -Dversion-string="$(stage3-debug/bin/zig version)" + +stage4-debug/bin/zig test ../test/behavior.zig diff --git a/ci/x86_64-freebsd-release.sh b/ci/x86_64-freebsd-release.sh new file mode 100755 index 0000000000..0c67189f56 --- /dev/null +++ b/ci/x86_64-freebsd-release.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +# Requires cmake ninja-build + +set -x +set -e + +ARCH="x86_64" +TARGET="$ARCH-freebsd-none" +MCPU="baseline" +CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.312+164c598cd" +PREFIX="$HOME/deps/$CACHE_BASENAME" +ZIG="$PREFIX/bin/zig" + +# Make the `zig version` number consistent. +# This will affect the cmake command below. +git fetch --unshallow || true +git fetch --tags + +# Override the cache directories because they won't actually help other CI runs +# which will be testing alternate versions of zig, and ultimately would just +# fill up space on the hard drive for no reason. +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" + +mkdir build-release +cd build-release + +export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" +export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" + +cmake .. \ + -DCMAKE_INSTALL_PREFIX="stage3-release" \ + -DCMAKE_PREFIX_PATH="$PREFIX" \ + -DCMAKE_BUILD_TYPE=Release \ + -DZIG_TARGET_TRIPLE="$TARGET" \ + -DZIG_TARGET_MCPU="$MCPU" \ + -DZIG_STATIC=ON \ + -DZIG_NO_LIB=ON \ + -GNinja \ + -DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \ + -DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE +# https://github.com/ziglang/zig/issues/22213 + +# Now cmake will use zig as the C/C++ compiler. We reset the environment variables +# so that installation and testing do not get affected by them. +unset CC +unset CXX + +ninja install + +stage3-release/bin/zig build test docs \ + --maxrss 32212254720 \ + -Dstatic-llvm \ + -Dskip-linux \ + -Dskip-netbsd \ + -Dskip-windows \ + -Dskip-macos \ + -Dtarget=native-native-none \ + --search-prefix "$PREFIX" \ + --zig-lib-dir "$PWD/../lib" + +# Ensure that stage3 and stage4 are byte-for-byte identical. +stage3-release/bin/zig build \ + --prefix stage4-release \ + -Denable-llvm \ + -Dno-lib \ + -Doptimize=ReleaseFast \ + -Dstrip \ + -Dtarget=$TARGET \ + -Duse-zig-libcxx \ + -Dversion-string="$(stage3-release/bin/zig version)" + +# diff returns an error code if the files differ. +echo "If the following command fails, it means nondeterminism has been" +echo "introduced, making stage3 and stage4 no longer byte-for-byte identical." +diff stage3-release/bin/zig stage4-release/bin/zig From 16c18b835e16bae7a0f85caa29457f4ae4b7b417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 22 Sep 2025 01:39:29 +0200 Subject: [PATCH 6/6] ci: stop building FreeBSD module tests on x86_64-linux They're now built on the x86_64-freebsd machine. --- ci/x86_64-linux-release.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/x86_64-linux-release.sh b/ci/x86_64-linux-release.sh index b86ce63619..08144ff3f0 100755 --- a/ci/x86_64-linux-release.sh +++ b/ci/x86_64-linux-release.sh @@ -65,6 +65,7 @@ stage3-release/bin/zig build test docs \ -fqemu \ -fwasmtime \ -Dstatic-llvm \ + -Dskip-freebsd \ -Dtarget=native-native-musl \ --search-prefix "$PREFIX" \ --zig-lib-dir "$PWD/../lib" \