authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-10-12 17:28:02+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-10-15 15:59:16-07:00
log0e1afee732c1007280b8afdab51aef3ceb860432
treec46ab1a0cc68388cb5c5e58343837d20689a6d6a
parentf3667e8a8056765c460aa3da1fd3ea655b54bf25

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 <kubkon@jakubkonka.com>

2 files changed, 8 insertions(+), 2 deletions(-)

lib/std/zig/cross_target.zig+6-1
...@@ -608,10 +608,15 @@ pub const CrossTarget = struct {...@@ -608,10 +608,15 @@ pub const CrossTarget = struct {
608 // If the OS and CPU arch match, the binary can be considered native.608 // If the OS and CPU arch match, the binary can be considered native.
609 if (os_match and cpu_arch == Target.current.cpu.arch) {609 if (os_match and cpu_arch == Target.current.cpu.arch) {
610 // However, we also need to verify that the dynamic linker path is valid.610 // However, we also need to verify that the dynamic linker path is valid.
611 // TODO Until that is implemented, we prevent returning `.native` when the OS is non-native.
612 if (self.os_tag == null) {611 if (self.os_tag == null) {
613 return .native;612 return .native;
614 }613 }
614 if (self.dynamic_linker.max_byte) |len| blk: {
615 std.fs.cwd().access(self.dynamic_linker.buffer[0..len + 1], .{}) catch {
616 break :blk;
617 };
618 return .native;
619 }
615 }620 }
616621
617 // If the OS matches, we can use QEMU to emulate a foreign architecture.622 // If the OS matches, we can use QEMU to emulate a foreign architecture.
test/stage2/test.zig+2-1
...@@ -14,6 +14,7 @@ const linux_x64 = std.zig.CrossTarget{...@@ -14,6 +14,7 @@ const linux_x64 = std.zig.CrossTarget{
14const macosx_x64 = std.zig.CrossTarget{14const macosx_x64 = std.zig.CrossTarget{
15 .cpu_arch = .x86_64,15 .cpu_arch = .x86_64,
16 .os_tag = .macos,16 .os_tag = .macos,
17 .dynamic_linker = std.zig.CrossTarget.DynamicLinker.init("/usr/lib/dyld"),
17};18};
1819
19const linux_riscv64 = std.zig.CrossTarget{20const linux_riscv64 = std.zig.CrossTarget{
...@@ -145,7 +146,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -145,7 +146,7 @@ pub fn addCases(ctx: *TestContext) !void {
145 }146 }
146147
147 {148 {
148 var case = ctx.exe("hello world", macosx_x64);149 var case = ctx.exe("hello world with updates", macosx_x64);
149 case.addError("", &[_][]const u8{":1:1: error: no entry point found"});150 case.addError("", &[_][]const u8{":1:1: error: no entry point found"});
150151
151 // Incorrect return type152 // Incorrect return type