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 {
608608 // If the OS and CPU arch match, the binary can be considered native.
609609 if (os_match and cpu_arch == Target.current.cpu.arch) {
610610 // 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.
612611 if (self.os_tag == null) {
613612 return .native;
614613 }
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 }
615620 }
616621
617622 // 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{
1414const macosx_x64 = std.zig.CrossTarget{
1515 .cpu_arch = .x86_64,
1616 .os_tag = .macos,
17 .dynamic_linker = std.zig.CrossTarget.DynamicLinker.init("/usr/lib/dyld"),
1718};
1819
1920const linux_riscv64 = std.zig.CrossTarget{
......@@ -145,7 +146,7 @@ pub fn addCases(ctx: *TestContext) !void {
145146 }
146147
147148 {
148 var case = ctx.exe("hello world", macosx_x64);
149 var case = ctx.exe("hello world with updates", macosx_x64);
149150 case.addError("", &[_][]const u8{":1:1: error: no entry point found"});
150151
151152 // Incorrect return type