Skip to content

Commit 26825e9

Browse files
authored
Merge pull request #25324 from alexrp/freebsd
Some changes to prepare for FreeBSD CI
2 parents f58200e + 16c18b8 commit 26825e9

File tree

10 files changed

+165
-6
lines changed

10 files changed

+165
-6
lines changed

ci/x86_64-freebsd-debug.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/sh
2+
3+
# Requires cmake ninja-build
4+
5+
set -x
6+
set -e
7+
8+
ARCH="x86_64"
9+
TARGET="$ARCH-freebsd-none"
10+
MCPU="baseline"
11+
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.312+164c598cd"
12+
PREFIX="$HOME/deps/$CACHE_BASENAME"
13+
ZIG="$PREFIX/bin/zig"
14+
15+
# Make the `zig version` number consistent.
16+
# This will affect the cmake command below.
17+
git fetch --unshallow || true
18+
git 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.
23+
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
24+
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
25+
26+
mkdir build-debug
27+
cd build-debug
28+
29+
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
30+
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
31+
32+
cmake .. \
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.
47+
unset CC
48+
unset CXX
49+
50+
ninja install
51+
52+
stage3-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+
63+
stage3-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+
71+
stage4-debug/bin/zig test ../test/behavior.zig

ci/x86_64-freebsd-release.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/sh
2+
3+
# Requires cmake ninja-build
4+
5+
set -x
6+
set -e
7+
8+
ARCH="x86_64"
9+
TARGET="$ARCH-freebsd-none"
10+
MCPU="baseline"
11+
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.312+164c598cd"
12+
PREFIX="$HOME/deps/$CACHE_BASENAME"
13+
ZIG="$PREFIX/bin/zig"
14+
15+
# Make the `zig version` number consistent.
16+
# This will affect the cmake command below.
17+
git fetch --unshallow || true
18+
git 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.
23+
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
24+
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
25+
26+
mkdir build-release
27+
cd build-release
28+
29+
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
30+
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
31+
32+
cmake .. \
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.
47+
unset CC
48+
unset CXX
49+
50+
ninja install
51+
52+
stage3-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.
64+
stage3-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.
75+
echo "If the following command fails, it means nondeterminism has been"
76+
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
77+
diff stage3-release/bin/zig stage4-release/bin/zig

ci/x86_64-linux-release.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

650649
test "sigset empty/full" {

src/target.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ pub fn hasNewLinkerSupport(ofmt: std.Target.ObjectFormat) bool {
245245
pub 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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
42854288
const expectLinkErrors = link.expectLinkErrors;
42864289
const link = @import("link.zig");
42874290
const std = @import("std");
4291+
const builtin = @import("builtin");
42884292

42894293
const Build = std.Build;
42904294
const BuildOptions = link.BuildOptions;

test/src/StackTrace.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn addCaseInner(self: *StackTrace, config: Config, use_llvm: bool) void {
4545
fn 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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
}

0 commit comments

Comments
 (0)