diff --git a/ci/x86_64-freebsd-debug.sh b/ci/x86_64-freebsd-debug.sh new file mode 100755 index 000000000000..9b0f6f5c2611 --- /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 000000000000..0c67189f5651 --- /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 diff --git a/ci/x86_64-linux-release.sh b/ci/x86_64-linux-release.sh index b86ce63619f0..08144ff3f076 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" \ diff --git a/lib/std/posix/test.zig b/lib/std/posix/test.zig index 85651c13a5f5..cd322945d36e 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" { diff --git a/src/target.zig b/src/target.zig index e999d2ae2266..6326f3c3a1ec 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/link/elf.zig b/test/link/elf.zig index 16ee824da720..161dcf2d3202 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; diff --git a/test/src/StackTrace.zig b/test/src/StackTrace.zig index ff3bbe708b5d..9b51f4e4b2c3 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/stack_traces.zig b/test/stack_traces.zig index 9e815e032fce..d2523daf52dd 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 8d2c448215ee..b6ac2a9aee5f 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 diff --git a/test/tests.zig b/test/tests.zig index a99b7c703b9f..5b0dfc40a7dc 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, }