From 0e1afee732c1007280b8afdab51aef3ceb860432 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Mon, 12 Oct 2020 17:28:02 +0200 Subject: [PATCH] Enable stage2 end-to-end tests on macOS run natively This commit enables stage2 end-to-end tests to run natively on macOS (where and when applicable). Since QEMU on macOS doesn't support the same type of architecture emulation as it does on linux (i.e., there is no `qemu-x86_64` for instance), this commit ensures that we specify a path to dynamic linker on macOS (`/usr/lib/dyld`) which is then checked for existence in `std.CrossTarget.getExternalExecutor()` function, and if exists, we can run the test natively. Signed-off-by: Jakub Konka --- lib/std/zig/cross_target.zig | 7 ++++++- test/stage2/test.zig | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/std/zig/cross_target.zig b/lib/std/zig/cross_target.zig index 3d39c8338b72217c6e65adc2af3f5e304ce1784b..77c7f12728bfe293ab09cd6f5ae7d01ab6f2c393 100644 --- a/lib/std/zig/cross_target.zig +++ b/lib/std/zig/cross_target.zig @@ -608,10 +608,15 @@ pub const CrossTarget = struct { // If the OS and CPU arch match, the binary can be considered native. if (os_match and cpu_arch == Target.current.cpu.arch) { // However, we also need to verify that the dynamic linker path is valid. - // TODO Until that is implemented, we prevent returning `.native` when the OS is non-native. if (self.os_tag == null) { return .native; } + if (self.dynamic_linker.max_byte) |len| blk: { + std.fs.cwd().access(self.dynamic_linker.buffer[0..len + 1], .{}) catch { + break :blk; + }; + return .native; + } } // If the OS matches, we can use QEMU to emulate a foreign architecture. diff --git a/test/stage2/test.zig b/test/stage2/test.zig index 183555e3310740f6e9240387a5fb3a699c821913..2090c9493e7f99e745e1d3579f048c4e3b3f6660 100644 --- a/test/stage2/test.zig +++ b/test/stage2/test.zig @@ -14,6 +14,7 @@ const linux_x64 = std.zig.CrossTarget{ const macosx_x64 = std.zig.CrossTarget{ .cpu_arch = .x86_64, .os_tag = .macos, + .dynamic_linker = std.zig.CrossTarget.DynamicLinker.init("/usr/lib/dyld"), }; const linux_riscv64 = std.zig.CrossTarget{ @@ -145,7 +146,7 @@ pub fn addCases(ctx: *TestContext) !void { } { - var case = ctx.exe("hello world", macosx_x64); + var case = ctx.exe("hello world with updates", macosx_x64); case.addError("", &[_][]const u8{":1:1: error: no entry point found"}); // Incorrect return type -- 2.54.0