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 {
218218 const is_wine_enabled = b.option(bool, "enable-wine", "Use Wine to run cross compiled Windows tests") orelse false;
219219 const is_qemu_enabled = b.option(bool, "enable-qemu", "Use QEMU to run cross compiled foreign architecture tests") orelse false;
220220 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;
221222 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
223224 test_stage2.addBuildOption(bool, "skip_non_native", skip_non_native);
......@@ -227,6 +228,7 @@ pub fn build(b: *Builder) !void {
227228 test_stage2.addBuildOption(bool, "enable_qemu", is_qemu_enabled);
228229 test_stage2.addBuildOption(bool, "enable_wine", is_wine_enabled);
229230 test_stage2.addBuildOption(bool, "enable_wasmtime", is_wasmtime_enabled);
231 test_stage2.addBuildOption(bool, "enable_darling", is_darling_enabled);
230232 test_stage2.addBuildOption(?[]const u8, "glibc_multi_install_dir", glibc_multi_dir);
231233 test_stage2.addBuildOption([]const u8, "version", version);
232234
......@@ -261,11 +263,56 @@ pub fn build(b: *Builder) !void {
261263 const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works");
262264 fmt_step.dependOn(&fmt_build_zig.step);
263265
264 // TODO for the moment, skip wasm32-wasi until bugs are sorted out.
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));
266
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));
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));
266 toolchain_step.dependOn(tests.addPkgTests(
267 b,
268 test_filter,
269 "test/stage1/behavior.zig",
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
270317 toolchain_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
271318 toolchain_step.dependOn(tests.addStandaloneTests(b, test_filter, modes));
......@@ -283,7 +330,22 @@ pub fn build(b: *Builder) !void {
283330 toolchain_step.dependOn(tests.addCompileErrorTests(b, test_filter, modes));
284331 }
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
288350 const test_step = b.step("test", "Run all the tests");
289351 test_step.dependOn(toolchain_step);
lib/std/build.zig+8
......@@ -1398,6 +1398,9 @@ pub const LibExeObjStep = struct {
13981398 /// Uses system Wasmtime installation to run cross compiled wasm/wasi build artifacts.
13991399 enable_wasmtime: bool = false,
14001400
1401 /// Experimental. Uses system Darling installation to run cross compiled macOS build artifacts.
1402 enable_darling: bool = false,
1403
14011404 /// After following the steps in https://github.com/ziglang/zig/wiki/Updating-libc#glibc,
14021405 /// this will be the directory $glibc-build-dir/install/glibcs
14031406 /// Given the example of the aarch64 target, this is the directory
......@@ -2514,6 +2517,11 @@ pub const LibExeObjStep = struct {
25142517 try zig_args.append("--dir=.");
25152518 try zig_args.append("--test-cmd-bin");
25162519 },
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 },
25172525 }
25182526
25192527 for (self.packages.items) |pkg| {
lib/std/zig/cross_target.zig+10
......@@ -606,6 +606,7 @@ pub const CrossTarget = struct {
606606 qemu: []const u8,
607607 wine: []const u8,
608608 wasmtime: []const u8,
609 darling: []const u8,
609610 unavailable,
610611 };
611612
......@@ -667,6 +668,15 @@ pub const CrossTarget = struct {
667668 32 => return Executor{ .wasmtime = "wasmtime" },
668669 else => return .unavailable,
669670 },
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 },
670680 else => return .unavailable,
671681 }
672682 }
src/test.zig+11
......@@ -9,6 +9,7 @@ const build_options = @import("build_options");
99const enable_qemu: bool = build_options.enable_qemu;
1010const enable_wine: bool = build_options.enable_wine;
1111const enable_wasmtime: bool = build_options.enable_wasmtime;
12const enable_darling: bool = build_options.enable_darling;
1213const glibc_multi_install_dir: ?[]const u8 = build_options.glibc_multi_install_dir;
1314const ThreadPool = @import("ThreadPool.zig");
1415const CrossTarget = std.zig.CrossTarget;
......@@ -899,6 +900,16 @@ pub const TestContext = struct {
899900 } else {
900901 return; // wasmtime not available; pass test.
901902 },
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 },
902913 }
903914
904915 try comp.makeBinFileExecutable();
test/tests.zig+2
......@@ -503,6 +503,7 @@ pub fn addPkgTests(
503503 is_wine_enabled: bool,
504504 is_qemu_enabled: bool,
505505 is_wasmtime_enabled: bool,
506 is_darling_enabled: bool,
506507 glibc_dir: ?[]const u8,
507508) *build.Step {
508509 const step = b.step(b.fmt("test-{s}", .{name}), desc);
......@@ -564,6 +565,7 @@ pub fn addPkgTests(
564565 these_tests.enable_wine = is_wine_enabled;
565566 these_tests.enable_qemu = is_qemu_enabled;
566567 these_tests.enable_wasmtime = is_wasmtime_enabled;
568 these_tests.enable_darling = is_darling_enabled;
567569 these_tests.glibc_multi_install_dir = glibc_dir;
568570 these_tests.addIncludeDir("test");
569571