Skip to content

Commit c390671

Browse files
authored
Merge pull request #23810 from alexrp/more-test-targets
2 parents 837e0f9 + 23cb2b2 commit c390671

File tree

11 files changed

+378
-61
lines changed

11 files changed

+378
-61
lines changed

lib/compiler/build_runner.zig

+7-5
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,9 @@ pub fn main() !void {
241241
// but it is handled by the parent process. The build runner
242242
// only sees this flag.
243243
graph.system_package_mode = true;
244-
} else if (mem.eql(u8, arg, "--glibc-runtimes")) {
245-
builder.glibc_runtimes_dir = nextArgOrFatal(args, &arg_idx);
244+
} else if (mem.eql(u8, arg, "--libc-runtimes") or mem.eql(u8, arg, "--glibc-runtimes")) {
245+
// --glibc-runtimes was the old name of the flag; kept for compatibility for now.
246+
builder.libc_runtimes_dir = nextArgOrFatal(args, &arg_idx);
246247
} else if (mem.eql(u8, arg, "--verbose-link")) {
247248
builder.verbose_link = true;
248249
} else if (mem.eql(u8, arg, "--verbose-air")) {
@@ -1279,9 +1280,10 @@ fn usage(b: *std.Build, out_stream: anytype) !void {
12791280
\\ -fqemu, -fno-qemu Integration with system-installed QEMU to execute
12801281
\\ foreign-architecture programs on Linux hosts
12811282
\\ (default: no)
1282-
\\ --glibc-runtimes [path] Enhances QEMU integration by providing glibc built
1283-
\\ for multiple foreign architectures, allowing
1284-
\\ execution of non-native programs that link with glibc.
1283+
\\ --libc-runtimes [path] Enhances QEMU integration by providing dynamic libc
1284+
\\ (e.g. glibc or musl) built for multiple foreign
1285+
\\ architectures, allowing execution of non-native
1286+
\\ programs that link with libc.
12851287
\\ -frosetta, -fno-rosetta Rely on Rosetta to execute x86_64 programs on
12861288
\\ ARM64 macOS hosts. (default: no)
12871289
\\ -fwasmtime, -fno-wasmtime Integration with system-installed wasmtime to

lib/std/Build.zig

+3-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ enable_wine: bool = false,
7979
/// this will be the directory $glibc-build-dir/install/glibcs
8080
/// Given the example of the aarch64 target, this is the directory
8181
/// that contains the path `aarch64-linux-gnu/lib/ld-linux-aarch64.so.1`.
82-
glibc_runtimes_dir: ?[]const u8 = null,
82+
/// Also works for dynamic musl.
83+
libc_runtimes_dir: ?[]const u8 = null,
8384

8485
dep_prefix: []const u8 = "",
8586

@@ -390,7 +391,7 @@ fn createChildOnly(
390391
.enable_rosetta = parent.enable_rosetta,
391392
.enable_wasmtime = parent.enable_wasmtime,
392393
.enable_wine = parent.enable_wine,
393-
.glibc_runtimes_dir = parent.glibc_runtimes_dir,
394+
.libc_runtimes_dir = parent.libc_runtimes_dir,
394395
.dep_prefix = parent.fmt("{s}{s}.", .{ parent.dep_prefix, dep_name }),
395396
.modules = .init(allocator),
396397
.named_writefiles = .init(allocator),

lib/std/Build/Step/Run.zig

+21-23
Original file line numberDiff line numberDiff line change
@@ -1026,11 +1026,11 @@ fn runCommand(
10261026
}
10271027

10281028
const root_target = exe.rootModuleTarget();
1029-
const need_cross_glibc = root_target.isGnuLibC() and
1030-
exe.is_linking_libc;
1029+
const need_cross_libc = exe.is_linking_libc and
1030+
(root_target.isGnuLibC() or (root_target.isMuslLibC() and exe.linkage == .dynamic));
10311031
const other_target = exe.root_module.resolved_target.?.result;
10321032
switch (std.zig.system.getExternalExecutor(b.graph.host.result, &other_target, .{
1033-
.qemu_fixes_dl = need_cross_glibc and b.glibc_runtimes_dir != null,
1033+
.qemu_fixes_dl = need_cross_libc and b.libc_runtimes_dir != null,
10341034
.link_libc = exe.is_linking_libc,
10351035
})) {
10361036
.native, .rosetta => {
@@ -1047,31 +1047,29 @@ fn runCommand(
10471047
},
10481048
.qemu => |bin_name| {
10491049
if (b.enable_qemu) {
1050-
const glibc_dir_arg = if (need_cross_glibc)
1051-
b.glibc_runtimes_dir orelse
1052-
return failForeign(run, "--glibc-runtimes", argv[0], exe)
1053-
else
1054-
null;
1055-
10561050
try interp_argv.append(bin_name);
10571051

1058-
if (glibc_dir_arg) |dir| {
1059-
try interp_argv.append("-L");
1060-
try interp_argv.append(b.pathJoin(&.{
1061-
dir,
1062-
try std.zig.target.glibcRuntimeTriple(
1063-
b.allocator,
1064-
root_target.cpu.arch,
1065-
root_target.os.tag,
1066-
root_target.abi,
1067-
),
1068-
}));
1052+
if (need_cross_libc) {
1053+
if (b.libc_runtimes_dir) |dir| {
1054+
try interp_argv.append("-L");
1055+
try interp_argv.append(b.pathJoin(&.{
1056+
dir,
1057+
try if (root_target.isGnuLibC()) std.zig.target.glibcRuntimeTriple(
1058+
b.allocator,
1059+
root_target.cpu.arch,
1060+
root_target.os.tag,
1061+
root_target.abi,
1062+
) else if (root_target.isMuslLibC()) std.zig.target.muslRuntimeTriple(
1063+
b.allocator,
1064+
root_target.cpu.arch,
1065+
root_target.abi,
1066+
) else unreachable,
1067+
}));
1068+
} else return failForeign(run, "--libc-runtimes", argv[0], exe);
10691069
}
10701070

10711071
try interp_argv.appendSlice(argv);
1072-
} else {
1073-
return failForeign(run, "-fqemu", argv[0], exe);
1074-
}
1072+
} else return failForeign(run, "-fqemu", argv[0], exe);
10751073
},
10761074
.darling => |bin_name| {
10771075
if (b.enable_darling) {

lib/std/Target.zig

+10-28
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,6 @@ pub const Abi = enum {
838838
.aix => if (arch == .powerpc) .eabihf else .none,
839839
.haiku => switch (arch) {
840840
.arm,
841-
.thumb,
842841
.powerpc,
843842
=> .eabihf,
844843
else => .none,
@@ -877,22 +876,13 @@ pub const Abi = enum {
877876
},
878877
.freebsd => switch (arch) {
879878
.arm,
880-
.armeb,
881-
.thumb,
882-
.thumbeb,
883879
.powerpc,
884880
=> .eabihf,
885-
// Soft float tends to be more common for MIPS.
886-
.mips,
887-
.mipsel,
888-
=> .eabi,
889881
else => .none,
890882
},
891883
.netbsd => switch (arch) {
892884
.arm,
893885
.armeb,
894-
.thumb,
895-
.thumbeb,
896886
.powerpc,
897887
=> .eabihf,
898888
// Soft float tends to be more common for MIPS.
@@ -903,7 +893,6 @@ pub const Abi = enum {
903893
},
904894
.openbsd => switch (arch) {
905895
.arm,
906-
.thumb,
907896
=> .eabi,
908897
.powerpc,
909898
=> .eabihf,
@@ -2205,7 +2194,6 @@ pub const DynamicLinker = struct {
22052194

22062195
.haiku => switch (cpu.arch) {
22072196
.arm,
2208-
.thumb,
22092197
.aarch64,
22102198
.m68k,
22112199
.powerpc,
@@ -2234,9 +2222,7 @@ pub const DynamicLinker = struct {
22342222

22352223
.linux => if (abi.isAndroid())
22362224
switch (cpu.arch) {
2237-
.arm,
2238-
.thumb,
2239-
=> if (abi == .androideabi) init("/system/bin/linker") else none,
2225+
.arm => if (abi == .androideabi) init("/system/bin/linker") else none,
22402226

22412227
.aarch64,
22422228
.riscv64,
@@ -2454,19 +2440,11 @@ pub const DynamicLinker = struct {
24542440

24552441
.freebsd => switch (cpu.arch) {
24562442
.arm,
2457-
.armeb,
2458-
.thumb,
2459-
.thumbeb,
24602443
.aarch64,
2461-
.mips,
2462-
.mipsel,
2463-
.mips64,
2464-
.mips64el,
24652444
.powerpc,
24662445
.powerpc64,
24672446
.powerpc64le,
24682447
.riscv64,
2469-
.sparc64,
24702448
.x86,
24712449
.x86_64,
24722450
=> initFmt("{s}/libexec/ld-elf.so.1", .{
@@ -2481,8 +2459,6 @@ pub const DynamicLinker = struct {
24812459
.netbsd => switch (cpu.arch) {
24822460
.arm,
24832461
.armeb,
2484-
.thumb,
2485-
.thumbeb,
24862462
.aarch64,
24872463
.aarch64_be,
24882464
.m68k,
@@ -2491,6 +2467,8 @@ pub const DynamicLinker = struct {
24912467
.mips64,
24922468
.mips64el,
24932469
.powerpc,
2470+
.powerpc64,
2471+
.riscv32,
24942472
.riscv64,
24952473
.sparc,
24962474
.sparc64,
@@ -2502,7 +2480,6 @@ pub const DynamicLinker = struct {
25022480

25032481
.openbsd => switch (cpu.arch) {
25042482
.arm,
2505-
.thumb,
25062483
.aarch64,
25072484
.mips64,
25082485
.mips64el,
@@ -2530,11 +2507,16 @@ pub const DynamicLinker = struct {
25302507
},
25312508

25322509
.illumos,
2510+
=> switch (cpu.arch) {
2511+
.x86,
2512+
.x86_64,
2513+
=> initFmt("/lib/{s}ld.so.1", .{if (ptrBitWidth_cpu_abi(cpu, .none) == 64) "64/" else ""}),
2514+
else => none,
2515+
},
2516+
25332517
.solaris,
25342518
=> switch (cpu.arch) {
2535-
.sparc,
25362519
.sparc64,
2537-
.x86,
25382520
.x86_64,
25392521
=> initFmt("/lib/{s}ld.so.1", .{if (ptrBitWidth_cpu_abi(cpu, .none) == 64) "64/" else ""}),
25402522
else => none,

lib/std/fs/test.zig

+1
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,7 @@ test "pwritev, preadv" {
13941394
test "setEndPos" {
13951395
// https://github.com/ziglang/zig/issues/20747 (open fd does not have write permission)
13961396
if (native_os == .wasi and builtin.link_libc) return error.SkipZigTest;
1397+
if (builtin.cpu.arch.isMIPS64() and (builtin.abi == .gnuabin32 or builtin.abi == .muslabin32)) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/23806
13971398

13981399
var tmp = tmpDir(.{});
13991400
defer tmp.cleanup();

lib/std/hash/xxhash.zig

+3
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ fn testExpect(comptime H: type, seed: anytype, input: []const u8, expected: u64)
781781

782782
test "xxhash3" {
783783
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
784+
if (builtin.cpu.arch.isMIPS64() and (builtin.abi == .gnuabin32 or builtin.abi == .muslabin32)) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/23807
784785

785786
const H = XxHash3;
786787
// Non-Seeded Tests
@@ -814,6 +815,7 @@ test "xxhash3" {
814815

815816
test "xxhash3 smhasher" {
816817
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
818+
if (builtin.cpu.arch.isMIPS64() and (builtin.abi == .gnuabin32 or builtin.abi == .muslabin32)) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/23807
817819

818820
const Test = struct {
819821
fn do() !void {
@@ -827,6 +829,7 @@ test "xxhash3 smhasher" {
827829

828830
test "xxhash3 iterative api" {
829831
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
832+
if (builtin.cpu.arch.isMIPS64() and (builtin.abi == .gnuabin32 or builtin.abi == .muslabin32)) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/23807
830833

831834
const Test = struct {
832835
fn do() !void {

lib/std/os/linux/test.zig

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const expectEqual = std.testing.expectEqual;
88
const fs = std.fs;
99

1010
test "fallocate" {
11+
if (builtin.cpu.arch.isMIPS64() and (builtin.abi == .gnuabin32 or builtin.abi == .muslabin32)) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/23809
12+
1113
var tmp = std.testing.tmpDir(.{});
1214
defer tmp.cleanup();
1315

lib/std/posix/test.zig

+2
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,8 @@ fn expectMode(dir: posix.fd_t, file: []const u8, mode: posix.mode_t) !void {
13911391
}
13921392

13931393
test "fchmodat smoke test" {
1394+
if (builtin.cpu.arch.isMIPS64() and (builtin.abi == .gnuabin32 or builtin.abi == .muslabin32)) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/23808
1395+
13941396
if (!std.fs.has_executable_bit) return error.SkipZigTest;
13951397

13961398
var tmp = tmpDir(.{});

lib/std/zig/target.zig

+14
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ pub fn glibcRuntimeTriple(
131131
};
132132
}
133133

134+
/// Returns the subdirectory triple to be used to find the correct musl for the given `arch` and
135+
/// `abi` in an installation directory.
136+
///
137+
/// `abi` must be a musl ABI, i.e. `.isMusl()`.
138+
pub fn muslRuntimeTriple(
139+
allocator: Allocator,
140+
arch: std.Target.Cpu.Arch,
141+
abi: std.Target.Abi,
142+
) Allocator.Error![]const u8 {
143+
assert(abi.isMusl());
144+
145+
return std.Target.linuxTripleSimple(allocator, arch, .linux, abi);
146+
}
147+
134148
pub fn osArchName(target: std.Target) [:0]const u8 {
135149
return switch (target.os.tag) {
136150
.linux => switch (target.cpu.arch) {

test/behavior/basic.zig

+1
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,7 @@ test "arrays and vectors with big integers" {
12041204
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
12051205
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
12061206
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1207+
if (builtin.zig_backend == .stage2_llvm and (builtin.abi == .gnuabin32 or builtin.abi == .muslabin32)) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/23805
12071208

12081209
inline for (.{ u65528, u65529, u65535 }) |Int| {
12091210
var a: [1]Int = undefined;

0 commit comments

Comments
 (0)