zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit cd5f69794d63ece18cd8f8aa0e2ce8bc16a31ab7 (tree)
parent 69a5f0d7973f2a3fefb69bc30c7dc1f0b430bba2
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sat, 16 May 2020 12:19:31 -0400

cross compile the stage2 tests for the target that they work for

Diffstat:
Msrc-self-hosted/test.zig | 6+++++-
Mtest/stage2/zir.zig | 14+++++++++++---
2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src-self-hosted/test.zig b/src-self-hosted/test.zig @@ -29,6 +29,7 @@ pub const TestContext = struct { name: []const u8, src: [:0]const u8, expected_zir: []const u8, + cross_target: std.zig.CrossTarget, }; pub fn addZIRCompareOutput( @@ -47,6 +48,7 @@ pub const TestContext = struct { pub fn addZIRTransform( ctx: *TestContext, name: []const u8, + cross_target: std.zig.CrossTarget, src: [:0]const u8, expected_zir: []const u8, ) void { @@ -54,6 +56,7 @@ pub const TestContext = struct { .name = name, .src = src, .expected_zir = expected_zir, + .cross_target = cross_target, }) catch unreachable; } @@ -85,7 +88,8 @@ pub const TestContext = struct { } for (self.zir_transform_cases.items) |case| { std.testing.base_allocator_instance.reset(); - try self.runOneZIRTransformCase(std.testing.allocator, root_node, case, native_info.target); + const info = try std.zig.system.NativeTargetInfo.detect(std.testing.allocator, case.cross_target); + try self.runOneZIRTransformCase(std.testing.allocator, root_node, case, info.target); try std.testing.allocator_instance.validate(); } } diff --git a/test/stage2/zir.zig b/test/stage2/zir.zig @@ -1,7 +1,15 @@ +const std = @import("std"); const TestContext = @import("../../src-self-hosted/test.zig").TestContext; +// self-hosted does not yet support PE executable files / COFF object files +// or mach-o files. So we do the ZIR transform test cases cross compiling for +// x86_64-linux. +const linux_x64 = std.zig.CrossTarget{ + .cpu_arch = .x86_64, + .os_tag = .linux, +}; pub fn addCases(ctx: *TestContext) void { - ctx.addZIRTransform("elemptr, add, cmp, condbr, return, breakpoint", + ctx.addZIRTransform("elemptr, add, cmp, condbr, return, breakpoint", linux_x64, \\@void = primitive(void) \\@usize = primitive(usize) \\@fnty = fntype([], @void, cc=C) @@ -49,8 +57,8 @@ pub fn addCases(ctx: *TestContext) void { \\ ); - if (@import("std").Target.current.os.tag != .linux or - @import("std").Target.current.cpu.arch != .x86_64) + if (std.Target.current.os.tag != .linux or + std.Target.current.cpu.arch != .x86_64) { // TODO implement self-hosted PE (.exe file) linking // TODO implement more ZIR so we don't depend on x86_64-linux