authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-05-13 11:03:44+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-05-13 20:31:33+02:00
log402264ab0e16dfdc98e861a440df9ef5db35c402
tree6abe6a4502e56cef173f48c8a75a09f3a83d37cb
parente902c19c0e2bf7f0e9bc83b2c58d19ec024d56db

Add experimental Darling support for cross testing macOS

* for cross testing stage2 tests, we use `darling shell` command since the path to the tested binary is relative to cwd * for the `zig test` command, we simply use `darling` since the path to the binary is absolute

5 files changed, 99 insertions(+), 6 deletions(-)

build.zig+68-6
...@@ -218,6 +218,7 @@ pub fn build(b: *Builder) !void {...@@ -218,6 +218,7 @@ pub fn build(b: *Builder) !void {
218 const is_wine_enabled = b.option(bool, "enable-wine", "Use Wine to run cross compiled Windows tests") orelse false;218 const is_wine_enabled = b.option(bool, "enable-wine", "Use Wine to run cross compiled Windows tests") orelse false;
219 const is_qemu_enabled = b.option(bool, "enable-qemu", "Use QEMU to run cross compiled foreign architecture tests") orelse false;219 const is_qemu_enabled = b.option(bool, "enable-qemu", "Use QEMU to run cross compiled foreign architecture tests") orelse false;
220 const is_wasmtime_enabled = b.option(bool, "enable-wasmtime", "Use Wasmtime to enable and run WASI libstd tests") orelse false;220 const is_wasmtime_enabled = b.option(bool, "enable-wasmtime", "Use Wasmtime to enable and run WASI libstd tests") orelse false;
221 const is_darling_enabled = b.option(bool, "enable-darling", "[Experimental] Use Darling to run cross compiled macOS tests") orelse false;
221 const glibc_multi_dir = b.option([]const u8, "enable-foreign-glibc", "Provide directory with glibc installations to run cross compiled tests that link glibc");222 const glibc_multi_dir = b.option([]const u8, "enable-foreign-glibc", "Provide directory with glibc installations to run cross compiled tests that link glibc");
222223
223 test_stage2.addBuildOption(bool, "skip_non_native", skip_non_native);224 test_stage2.addBuildOption(bool, "skip_non_native", skip_non_native);
...@@ -227,6 +228,7 @@ pub fn build(b: *Builder) !void {...@@ -227,6 +228,7 @@ pub fn build(b: *Builder) !void {
227 test_stage2.addBuildOption(bool, "enable_qemu", is_qemu_enabled);228 test_stage2.addBuildOption(bool, "enable_qemu", is_qemu_enabled);
228 test_stage2.addBuildOption(bool, "enable_wine", is_wine_enabled);229 test_stage2.addBuildOption(bool, "enable_wine", is_wine_enabled);
229 test_stage2.addBuildOption(bool, "enable_wasmtime", is_wasmtime_enabled);230 test_stage2.addBuildOption(bool, "enable_wasmtime", is_wasmtime_enabled);
231 test_stage2.addBuildOption(bool, "enable_darling", is_darling_enabled);
230 test_stage2.addBuildOption(?[]const u8, "glibc_multi_install_dir", glibc_multi_dir);232 test_stage2.addBuildOption(?[]const u8, "glibc_multi_install_dir", glibc_multi_dir);
231 test_stage2.addBuildOption([]const u8, "version", version);233 test_stage2.addBuildOption([]const u8, "version", version);
232234
...@@ -261,11 +263,56 @@ pub fn build(b: *Builder) !void {...@@ -261,11 +263,56 @@ pub fn build(b: *Builder) !void {
261 const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works");263 const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works");
262 fmt_step.dependOn(&fmt_build_zig.step);264 fmt_step.dependOn(&fmt_build_zig.step);
263265
264 // TODO for the moment, skip wasm32-wasi until bugs are sorted out.266 toolchain_step.dependOn(tests.addPkgTests(
265 toolchain_step.dependOn(tests.addPkgTests(b, test_filter, "test/stage1/behavior.zig", "behavior", "Run the behavior tests", modes, false, skip_non_native, skip_libc, is_wine_enabled, is_qemu_enabled, is_wasmtime_enabled, glibc_multi_dir));267 b,
266268 test_filter,
267 toolchain_step.dependOn(tests.addPkgTests(b, test_filter, "lib/std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes, true, skip_non_native, true, is_wine_enabled, is_qemu_enabled, is_wasmtime_enabled, glibc_multi_dir));269 "test/stage1/behavior.zig",
268 toolchain_step.dependOn(tests.addPkgTests(b, test_filter, "lib/std/special/c.zig", "minilibc", "Run the mini libc tests", modes, true, skip_non_native, true, is_wine_enabled, is_qemu_enabled, is_wasmtime_enabled, glibc_multi_dir));270 "behavior",
271 "Run the behavior tests",
272 modes,
273 false,
274 skip_non_native,
275 skip_libc,
276 is_wine_enabled,
277 is_qemu_enabled,
278 is_wasmtime_enabled,
279 is_darling_enabled,
280 glibc_multi_dir,
281 ));
282
283 toolchain_step.dependOn(tests.addPkgTests(
284 b,
285 test_filter,
286 "lib/std/special/compiler_rt.zig",
287 "compiler-rt",
288 "Run the compiler_rt tests",
289 modes,
290 true,
291 skip_non_native,
292 true,
293 is_wine_enabled,
294 is_qemu_enabled,
295 is_wasmtime_enabled,
296 is_darling_enabled,
297 glibc_multi_dir,
298 ));
299
300 toolchain_step.dependOn(tests.addPkgTests(
301 b,
302 test_filter,
303 "lib/std/special/c.zig",
304 "minilibc",
305 "Run the mini libc tests",
306 modes,
307 true,
308 skip_non_native,
309 true,
310 is_wine_enabled,
311 is_qemu_enabled,
312 is_wasmtime_enabled,
313 is_darling_enabled,
314 glibc_multi_dir,
315 ));
269316
270 toolchain_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));317 toolchain_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
271 toolchain_step.dependOn(tests.addStandaloneTests(b, test_filter, modes));318 toolchain_step.dependOn(tests.addStandaloneTests(b, test_filter, modes));
...@@ -283,7 +330,22 @@ pub fn build(b: *Builder) !void {...@@ -283,7 +330,22 @@ pub fn build(b: *Builder) !void {
283 toolchain_step.dependOn(tests.addCompileErrorTests(b, test_filter, modes));330 toolchain_step.dependOn(tests.addCompileErrorTests(b, test_filter, modes));
284 }331 }
285332
286 const std_step = tests.addPkgTests(b, test_filter, "lib/std/std.zig", "std", "Run the standard library tests", modes, false, skip_non_native, skip_libc, is_wine_enabled, is_qemu_enabled, is_wasmtime_enabled, glibc_multi_dir);333 const std_step = tests.addPkgTests(
334 b,
335 test_filter,
336 "lib/std/std.zig",
337 "std",
338 "Run the standard library tests",
339 modes,
340 false,
341 skip_non_native,
342 skip_libc,
343 is_wine_enabled,
344 is_qemu_enabled,
345 is_wasmtime_enabled,
346 is_darling_enabled,
347 glibc_multi_dir,
348 );
287349
288 const test_step = b.step("test", "Run all the tests");350 const test_step = b.step("test", "Run all the tests");
289 test_step.dependOn(toolchain_step);351 test_step.dependOn(toolchain_step);
lib/std/build.zig+8
...@@ -1398,6 +1398,9 @@ pub const LibExeObjStep = struct {...@@ -1398,6 +1398,9 @@ pub const LibExeObjStep = struct {
1398 /// Uses system Wasmtime installation to run cross compiled wasm/wasi build artifacts.1398 /// Uses system Wasmtime installation to run cross compiled wasm/wasi build artifacts.
1399 enable_wasmtime: bool = false,1399 enable_wasmtime: bool = false,
14001400
1401 /// Experimental. Uses system Darling installation to run cross compiled macOS build artifacts.
1402 enable_darling: bool = false,
1403
1401 /// After following the steps in https://github.com/ziglang/zig/wiki/Updating-libc#glibc,1404 /// After following the steps in https://github.com/ziglang/zig/wiki/Updating-libc#glibc,
1402 /// this will be the directory $glibc-build-dir/install/glibcs1405 /// this will be the directory $glibc-build-dir/install/glibcs
1403 /// Given the example of the aarch64 target, this is the directory1406 /// Given the example of the aarch64 target, this is the directory
...@@ -2514,6 +2517,11 @@ pub const LibExeObjStep = struct {...@@ -2514,6 +2517,11 @@ pub const LibExeObjStep = struct {
2514 try zig_args.append("--dir=.");2517 try zig_args.append("--dir=.");
2515 try zig_args.append("--test-cmd-bin");2518 try zig_args.append("--test-cmd-bin");
2516 },2519 },
2520 .darling => |bin_name| if (self.enable_darling) {
2521 try zig_args.append("--test-cmd");
2522 try zig_args.append(bin_name);
2523 try zig_args.append("--test-cmd-bin");
2524 },
2517 }2525 }
25182526
2519 for (self.packages.items) |pkg| {2527 for (self.packages.items) |pkg| {
lib/std/zig/cross_target.zig+10
...@@ -606,6 +606,7 @@ pub const CrossTarget = struct {...@@ -606,6 +606,7 @@ pub const CrossTarget = struct {
606 qemu: []const u8,606 qemu: []const u8,
607 wine: []const u8,607 wine: []const u8,
608 wasmtime: []const u8,608 wasmtime: []const u8,
609 darling: []const u8,
609 unavailable,610 unavailable,
610 };611 };
611612
...@@ -667,6 +668,15 @@ pub const CrossTarget = struct {...@@ -667,6 +668,15 @@ pub const CrossTarget = struct {
667 32 => return Executor{ .wasmtime = "wasmtime" },668 32 => return Executor{ .wasmtime = "wasmtime" },
668 else => return .unavailable,669 else => return .unavailable,
669 },670 },
671 .macos => {
672 // TODO loosen this check once upstream adds QEMU-based emulation
673 // layer for non-host architectures:
674 // https://github.com/darlinghq/darling/issues/863
675 if (cpu_arch != Target.current.cpu.arch) {
676 return .unavailable;
677 }
678 return Executor{ .darling = "darling" };
679 },
670 else => return .unavailable,680 else => return .unavailable,
671 }681 }
672 }682 }
src/test.zig+11
...@@ -9,6 +9,7 @@ const build_options = @import("build_options");...@@ -9,6 +9,7 @@ const build_options = @import("build_options");
9const enable_qemu: bool = build_options.enable_qemu;9const enable_qemu: bool = build_options.enable_qemu;
10const enable_wine: bool = build_options.enable_wine;10const enable_wine: bool = build_options.enable_wine;
11const enable_wasmtime: bool = build_options.enable_wasmtime;11const enable_wasmtime: bool = build_options.enable_wasmtime;
12const enable_darling: bool = build_options.enable_darling;
12const glibc_multi_install_dir: ?[]const u8 = build_options.glibc_multi_install_dir;13const glibc_multi_install_dir: ?[]const u8 = build_options.glibc_multi_install_dir;
13const ThreadPool = @import("ThreadPool.zig");14const ThreadPool = @import("ThreadPool.zig");
14const CrossTarget = std.zig.CrossTarget;15const CrossTarget = std.zig.CrossTarget;
...@@ -899,6 +900,16 @@ pub const TestContext = struct {...@@ -899,6 +900,16 @@ pub const TestContext = struct {
899 } else {900 } else {
900 return; // wasmtime not available; pass test.901 return; // wasmtime not available; pass test.
901 },902 },
903
904 .darling => |darling_bin_name| if (enable_darling) {
905 try argv.append(darling_bin_name);
906 // Since we use relative to cwd here, we invoke darling with
907 // "shell" subcommand.
908 try argv.append("shell");
909 try argv.append(exe_path);
910 } else {
911 return; // Darling not available; pass test.
912 },
902 }913 }
903914
904 try comp.makeBinFileExecutable();915 try comp.makeBinFileExecutable();
test/tests.zig+2
...@@ -503,6 +503,7 @@ pub fn addPkgTests(...@@ -503,6 +503,7 @@ pub fn addPkgTests(
503 is_wine_enabled: bool,503 is_wine_enabled: bool,
504 is_qemu_enabled: bool,504 is_qemu_enabled: bool,
505 is_wasmtime_enabled: bool,505 is_wasmtime_enabled: bool,
506 is_darling_enabled: bool,
506 glibc_dir: ?[]const u8,507 glibc_dir: ?[]const u8,
507) *build.Step {508) *build.Step {
508 const step = b.step(b.fmt("test-{s}", .{name}), desc);509 const step = b.step(b.fmt("test-{s}", .{name}), desc);
...@@ -564,6 +565,7 @@ pub fn addPkgTests(...@@ -564,6 +565,7 @@ pub fn addPkgTests(
564 these_tests.enable_wine = is_wine_enabled;565 these_tests.enable_wine = is_wine_enabled;
565 these_tests.enable_qemu = is_qemu_enabled;566 these_tests.enable_qemu = is_qemu_enabled;
566 these_tests.enable_wasmtime = is_wasmtime_enabled;567 these_tests.enable_wasmtime = is_wasmtime_enabled;
568 these_tests.enable_darling = is_darling_enabled;
567 these_tests.glibc_multi_install_dir = glibc_dir;569 these_tests.glibc_multi_install_dir = glibc_dir;
568 these_tests.addIncludeDir("test");570 these_tests.addIncludeDir("test");
569571