authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-09-22 05:04:31+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-09-22 05:04:31+02:00
log26825e95066c104585d248787c0e56ce4e8413e0
treeca505fa2a5cc4a4eff3b66b8e35977bb12940ec9
parentf58200e3f2967a06f343c9fc9dcae9de18def92a
parent16c18b835e16bae7a0f85caa29457f4ae4b7b417
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #25324 from alexrp/freebsd

Some changes to prepare for FreeBSD CI

10 files changed, 165 insertions(+), 6 deletions(-)

ci/x86_64-freebsd-debug.sh created+71
......@@ -0,0 +1,71 @@
1#!/bin/sh
2
3# Requires cmake ninja-build
4
5set -x
6set -e
7
8ARCH="x86_64"
9TARGET="$ARCH-freebsd-none"
10MCPU="baseline"
11CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.312+164c598cd"
12PREFIX="$HOME/deps/$CACHE_BASENAME"
13ZIG="$PREFIX/bin/zig"
14
15# Make the `zig version` number consistent.
16# This will affect the cmake command below.
17git fetch --unshallow || true
18git fetch --tags
19
20# Override the cache directories because they won't actually help other CI runs
21# which will be testing alternate versions of zig, and ultimately would just
22# fill up space on the hard drive for no reason.
23export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
24export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
25
26mkdir build-debug
27cd build-debug
28
29export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
30export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
31
32cmake .. \
33 -DCMAKE_INSTALL_PREFIX="stage3-debug" \
34 -DCMAKE_PREFIX_PATH="$PREFIX" \
35 -DCMAKE_BUILD_TYPE=Debug \
36 -DZIG_TARGET_TRIPLE="$TARGET" \
37 -DZIG_TARGET_MCPU="$MCPU" \
38 -DZIG_STATIC=ON \
39 -DZIG_NO_LIB=ON \
40 -GNinja \
41 -DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
42 -DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
43# https://github.com/ziglang/zig/issues/22213
44
45# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
46# so that installation and testing do not get affected by them.
47unset CC
48unset CXX
49
50ninja install
51
52stage3-debug/bin/zig build test docs \
53 --maxrss 32212254720 \
54 -Dstatic-llvm \
55 -Dskip-linux \
56 -Dskip-netbsd \
57 -Dskip-windows \
58 -Dskip-macos \
59 -Dtarget=native-native-none \
60 --search-prefix "$PREFIX" \
61 --zig-lib-dir "$PWD/../lib"
62
63stage3-debug/bin/zig build \
64 --prefix stage4-debug \
65 -Denable-llvm \
66 -Dno-lib \
67 -Dtarget=$TARGET \
68 -Duse-zig-libcxx \
69 -Dversion-string="$(stage3-debug/bin/zig version)"
70
71stage4-debug/bin/zig test ../test/behavior.zig
ci/x86_64-freebsd-release.sh created+77
......@@ -0,0 +1,77 @@
1#!/bin/sh
2
3# Requires cmake ninja-build
4
5set -x
6set -e
7
8ARCH="x86_64"
9TARGET="$ARCH-freebsd-none"
10MCPU="baseline"
11CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.312+164c598cd"
12PREFIX="$HOME/deps/$CACHE_BASENAME"
13ZIG="$PREFIX/bin/zig"
14
15# Make the `zig version` number consistent.
16# This will affect the cmake command below.
17git fetch --unshallow || true
18git fetch --tags
19
20# Override the cache directories because they won't actually help other CI runs
21# which will be testing alternate versions of zig, and ultimately would just
22# fill up space on the hard drive for no reason.
23export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
24export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
25
26mkdir build-release
27cd build-release
28
29export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
30export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
31
32cmake .. \
33 -DCMAKE_INSTALL_PREFIX="stage3-release" \
34 -DCMAKE_PREFIX_PATH="$PREFIX" \
35 -DCMAKE_BUILD_TYPE=Release \
36 -DZIG_TARGET_TRIPLE="$TARGET" \
37 -DZIG_TARGET_MCPU="$MCPU" \
38 -DZIG_STATIC=ON \
39 -DZIG_NO_LIB=ON \
40 -GNinja \
41 -DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
42 -DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
43# https://github.com/ziglang/zig/issues/22213
44
45# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
46# so that installation and testing do not get affected by them.
47unset CC
48unset CXX
49
50ninja install
51
52stage3-release/bin/zig build test docs \
53 --maxrss 32212254720 \
54 -Dstatic-llvm \
55 -Dskip-linux \
56 -Dskip-netbsd \
57 -Dskip-windows \
58 -Dskip-macos \
59 -Dtarget=native-native-none \
60 --search-prefix "$PREFIX" \
61 --zig-lib-dir "$PWD/../lib"
62
63# Ensure that stage3 and stage4 are byte-for-byte identical.
64stage3-release/bin/zig build \
65 --prefix stage4-release \
66 -Denable-llvm \
67 -Dno-lib \
68 -Doptimize=ReleaseFast \
69 -Dstrip \
70 -Dtarget=$TARGET \
71 -Duse-zig-libcxx \
72 -Dversion-string="$(stage3-release/bin/zig version)"
73
74# diff returns an error code if the files differ.
75echo "If the following command fails, it means nondeterminism has been"
76echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
77diff stage3-release/bin/zig stage4-release/bin/zig
ci/x86_64-linux-release.sh+1
......@@ -65,6 +65,7 @@ stage3-release/bin/zig build test docs \
6565 -fqemu \
6666 -fwasmtime \
6767 -Dstatic-llvm \
68 -Dskip-freebsd \
6869 -Dtarget=native-native-musl \
6970 --search-prefix "$PREFIX" \
7071 --zig-lib-dir "$PWD/../lib" \
lib/std/posix/test.zig-1
......@@ -644,7 +644,6 @@ test "sigrtmin/max" {
644644 try std.testing.expect(posix.sigrtmin() >= 32);
645645 try std.testing.expect(posix.sigrtmin() >= posix.system.sigrtmin());
646646 try std.testing.expect(posix.sigrtmin() < posix.system.sigrtmax());
647 try std.testing.expect(posix.sigrtmax() < posix.NSIG);
648647}
649648
650649test "sigset empty/full" {
src/target.zig+1-1
......@@ -245,7 +245,7 @@ pub fn hasNewLinkerSupport(ofmt: std.Target.ObjectFormat) bool {
245245pub fn selfHostedBackendIsAsRobustAsLlvm(target: *const std.Target) bool {
246246 if (target.cpu.arch.isSpirV()) return true;
247247 if (target.cpu.arch == .x86_64 and target.ptrBitWidth() == 64) {
248 if (target.os.tag == .netbsd or target.os.tag == .openbsd) {
248 if (target.os.tag.isBSD()) {
249249 // Self-hosted linker needs work: https://github.com/ziglang/zig/issues/24341
250250 return false;
251251 }
test/link/elf.zig+4
......@@ -2,6 +2,9 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
22 _ = build_opts;
33 const elf_step = b.step("test-elf", "Run ELF tests");
44
5 // https://github.com/ziglang/zig/issues/25323
6 if (builtin.os.tag == .freebsd) return elf_step;
7
58 const default_target = b.resolveTargetQuery(.{
69 .cpu_arch = .x86_64, // TODO relax this once ELF linker is able to handle other archs
710 .os_tag = .linux,
......@@ -4285,6 +4288,7 @@ const addStaticLibrary = link.addStaticLibrary;
42854288const expectLinkErrors = link.expectLinkErrors;
42864289const link = @import("link.zig");
42874290const std = @import("std");
4291const builtin = @import("builtin");
42884292
42894293const Build = std.Build;
42904294const BuildOptions = link.BuildOptions;
test/src/StackTrace.zig+1-1
......@@ -45,7 +45,7 @@ fn addCaseInner(self: *StackTrace, config: Config, use_llvm: bool) void {
4545fn shouldTestNonLlvm(target: *const std.Target) bool {
4646 return switch (target.cpu.arch) {
4747 .x86_64 => switch (target.ofmt) {
48 .elf => true,
48 .elf => !target.os.tag.isBSD(),
4949 else => false,
5050 },
5151 else => false,
test/stack_traces.zig+2
......@@ -803,6 +803,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
803803 .s390x,
804804 },
805805 .exclude_os = &.{
806 .freebsd,
806807 .openbsd, // integer overflow
807808 .windows, // TODO intermittent failures
808809 },
......@@ -847,6 +848,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
847848 },
848849 .ReleaseSafe = .{
849850 .exclude_os = &.{
851 .freebsd,
850852 .windows, // TODO
851853 .linux, // defeated by aggressive inlining
852854 .macos, // Broken in LLVM 20.
test/standalone/stack_iterator/build.zig+6-2
......@@ -61,8 +61,12 @@ pub fn build(b: *std.Build) void {
6161 .use_llvm = true,
6262 });
6363
64 const run_cmd = b.addRunArtifact(exe);
65 test_step.dependOn(&run_cmd.step);
64 if (builtin.os.tag != .freebsd) {
65 const run_cmd = b.addRunArtifact(exe);
66 test_step.dependOn(&run_cmd.step);
67 } else {
68 test_step.dependOn(&exe.step);
69 }
6670 }
6771
6872 // https://github.com/ziglang/zig/issues/24522
test/tests.zig+2-1
......@@ -2451,8 +2451,9 @@ pub fn wouldUseLlvm(use_llvm: ?bool, query: std.Target.Query, optimize_mode: Opt
24512451 else => return true,
24522452 }
24532453 const cpu_arch = query.cpu_arch orelse builtin.cpu.arch;
2454 const os_tag = query.os_tag orelse builtin.os.tag;
24542455 switch (cpu_arch) {
2455 .x86_64 => if (std.Target.ptrBitWidth_arch_abi(cpu_arch, query.abi orelse .none) != 64) return true,
2456 .x86_64 => if (os_tag.isBSD() or std.Target.ptrBitWidth_arch_abi(cpu_arch, query.abi orelse .none) != 64) return true,
24562457 .spirv32, .spirv64 => return false,
24572458 else => return true,
24582459 }