From 48526c0eb6c394b778cba11559a66daf8d5ec3c7 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Thu, 26 Oct 2023 05:30:41 -0400 Subject: [PATCH] test: enable `c-abi-tests` for the x86_64 backend Add testing for `x86_64_v2` and `x86_64_v3` with the x86_64 backend. --- test/behavior/maximum_minimum.zig | 2 +- test/c_abi/cfuncs.c | 10 +- test/c_abi/main.zig | 86 ++++++++++++++ test/tests.zig | 190 +++++++++++++++++++++++------- 4 files changed, 239 insertions(+), 49 deletions(-) diff --git a/test/behavior/maximum_minimum.zig b/test/behavior/maximum_minimum.zig index 3fabe1aa59..7d19f1dcdc 100644 --- a/test/behavior/maximum_minimum.zig +++ b/test/behavior/maximum_minimum.zig @@ -282,7 +282,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_x86_64 and - !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sse4_1)) return error.SkipZigTest; + !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .avx)) return error.SkipZigTest; var x: @Vector(2, u32) = .{ 1_000_000, 12345 }; const y: @Vector(2, u16) = .{ 10, undefined }; diff --git a/test/c_abi/cfuncs.c b/test/c_abi/cfuncs.c index 34aab7f934..010dae791e 100644 --- a/test/c_abi/cfuncs.c +++ b/test/c_abi/cfuncs.c @@ -73,6 +73,10 @@ static void assert_or_panic(bool ok) { #define ZIG_NO_RAW_F16 #endif +#ifdef ZIG_BACKEND_STAGE2_X86_64 +#define ZIG_NO_COMPLEX +#endif + #ifdef __i386__ #define ZIG_NO_RAW_F16 #endif @@ -274,7 +278,7 @@ void run_c_tests(void) { zig_u32(0xfffffffd); zig_u64(0xfffffffffffffffc); -#ifndef ZIG_NO_I128 +#if !defined ZIG_NO_I128 && !defined ZIG_BACKEND_STAGE2_X86_64 { struct u128 s = {0xfffffffffffffffc}; zig_struct_u128(s); @@ -288,7 +292,7 @@ void run_c_tests(void) { zig_i32(-3); zig_i64(-4); -#ifndef ZIG_NO_I128 +#if !defined ZIG_NO_I128 && !defined ZIG_BACKEND_STAGE2_X86_64 { struct i128 s = {-6}; zig_struct_i128(s); @@ -429,7 +433,7 @@ void run_c_tests(void) { } #endif -#if !defined __mips__ && !defined ZIG_PPC32 +#if !defined __mips__ && !defined ZIG_PPC32 && !defined ZIG_BACKEND_STAGE2_X86_64 { struct FloatRect r1 = {1, 21, 16, 4}; struct FloatRect r2 = {178, 189, 21, 15}; diff --git a/test/c_abi/main.zig b/test/c_abi/main.zig index 1aa306ab14..a92ccc8e2e 100644 --- a/test/c_abi/main.zig +++ b/test/c_abi/main.zig @@ -49,6 +49,8 @@ export fn zig_five_integers(a: i32, b: i32, c: i32, d: i32, e: i32) void { } test "C ABI integers" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + c_u8(0xff); c_u16(0xfffe); c_u32(0xfffffffd); @@ -185,6 +187,8 @@ const complex_abi_compatible = builtin.cpu.arch != .x86 and !builtin.cpu.arch.is !builtin.cpu.arch.isARM() and !builtin.cpu.arch.isPPC() and !builtin.cpu.arch.isRISCV(); test "C ABI complex float" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (!complex_abi_compatible) return error.SkipZigTest; if (builtin.cpu.arch == .x86_64) return error.SkipZigTest; // See https://github.com/ziglang/zig/issues/8465 @@ -197,6 +201,8 @@ test "C ABI complex float" { } test "C ABI complex float by component" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (!complex_abi_compatible) return error.SkipZigTest; const a = ComplexFloat{ .real = 1.25, .imag = 2.6 }; @@ -208,6 +214,8 @@ test "C ABI complex float by component" { } test "C ABI complex double" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (!complex_abi_compatible) return error.SkipZigTest; const a = ComplexDouble{ .real = 1.25, .imag = 2.6 }; @@ -219,6 +227,8 @@ test "C ABI complex double" { } test "C ABI complex double by component" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (!complex_abi_compatible) return error.SkipZigTest; const a = ComplexDouble{ .real = 1.25, .imag = 2.6 }; @@ -230,6 +240,8 @@ test "C ABI complex double by component" { } export fn zig_cmultf(a: ComplexFloat, b: ComplexFloat) ComplexFloat { + if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest"); + expect(a.real == 1.25) catch @panic("test failure: zig_cmultf 1"); expect(a.imag == 2.6) catch @panic("test failure: zig_cmultf 2"); expect(b.real == 11.3) catch @panic("test failure: zig_cmultf 3"); @@ -239,6 +251,8 @@ export fn zig_cmultf(a: ComplexFloat, b: ComplexFloat) ComplexFloat { } export fn zig_cmultd(a: ComplexDouble, b: ComplexDouble) ComplexDouble { + if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest"); + expect(a.real == 1.25) catch @panic("test failure: zig_cmultd 1"); expect(a.imag == 2.6) catch @panic("test failure: zig_cmultd 2"); expect(b.real == 11.3) catch @panic("test failure: zig_cmultd 3"); @@ -248,6 +262,8 @@ export fn zig_cmultd(a: ComplexDouble, b: ComplexDouble) ComplexDouble { } export fn zig_cmultf_comp(a_r: f32, a_i: f32, b_r: f32, b_i: f32) ComplexFloat { + if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest"); + expect(a_r == 1.25) catch @panic("test failure: zig_cmultf_comp 1"); expect(a_i == 2.6) catch @panic("test failure: zig_cmultf_comp 2"); expect(b_r == 11.3) catch @panic("test failure: zig_cmultf_comp 3"); @@ -257,6 +273,8 @@ export fn zig_cmultf_comp(a_r: f32, a_i: f32, b_r: f32, b_i: f32) ComplexFloat { } export fn zig_cmultd_comp(a_r: f64, a_i: f64, b_r: f64, b_i: f64) ComplexDouble { + if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest"); + expect(a_r == 1.25) catch @panic("test failure: zig_cmultd_comp 1"); expect(a_i == 2.6) catch @panic("test failure: zig_cmultd_comp 2"); expect(b_r == 11.3) catch @panic("test failure: zig_cmultd_comp 3"); @@ -334,6 +352,8 @@ extern fn c_med_struct_mixed(MedStructMixed) void; extern fn c_ret_med_struct_mixed() MedStructMixed; test "C ABI medium struct of ints and floats" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.cpu.arch == .x86) return error.SkipZigTest; if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; @@ -402,6 +422,8 @@ extern fn c_med_struct_ints(MedStructInts) void; extern fn c_ret_med_struct_ints() MedStructInts; test "C ABI medium struct of ints" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.cpu.arch == .x86) return error.SkipZigTest; if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; @@ -509,6 +531,8 @@ extern fn c_split_struct_mixed(SplitStructMixed) void; extern fn c_ret_split_struct_mixed() SplitStructMixed; test "C ABI split struct of ints and floats" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.cpu.arch == .x86) return error.SkipZigTest; if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; @@ -590,6 +614,8 @@ const Vector5 = extern struct { extern fn c_big_struct_floats(Vector5) void; test "C ABI structs of floats as parameter" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; @@ -657,6 +683,8 @@ const FloatRect = extern struct { }; export fn zig_multiple_struct_floats(x: FloatRect, y: FloatRect) void { + if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest"); + expect(x.left == 1) catch @panic("test failure"); expect(x.right == 21) catch @panic("test failure"); expect(x.top == 16) catch @panic("test failure"); @@ -668,6 +696,8 @@ export fn zig_multiple_struct_floats(x: FloatRect, y: FloatRect) void { } test "C ABI structs of floats as multiple parameters" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; @@ -724,6 +754,8 @@ export fn zig_ret_small_struct_ints() SmallStructInts { } export fn zig_ret_med_struct_ints() MedStructInts { + if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest"); + return .{ .x = 1, .y = 2, @@ -732,6 +764,8 @@ export fn zig_ret_med_struct_ints() MedStructInts { } export fn zig_ret_med_struct_mixed() MedStructMixed { + if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest"); + return .{ .a = 1234, .b = 100.0, @@ -740,6 +774,8 @@ export fn zig_ret_med_struct_mixed() MedStructMixed { } export fn zig_ret_split_struct_mixed() SplitStructMixed { + if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest"); + return .{ .a = 1234, .b = 100, @@ -780,6 +816,8 @@ extern fn c_struct_with_array(StructWithArray) void; extern fn c_ret_struct_with_array() StructWithArray; test "Struct with array as padding." { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.cpu.arch == .x86) return error.SkipZigTest; if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; @@ -851,6 +889,8 @@ extern fn c_medium_vec(MediumVec) void; extern fn c_ret_medium_vec() MediumVec; test "medium simd vector" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; c_medium_vec(.{ 1, 2, 3, 4 }); @@ -868,6 +908,8 @@ extern fn c_big_vec(BigVec) void; extern fn c_ret_big_vec() BigVec; test "big simd vector" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (comptime builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; if (builtin.cpu.arch == .x86_64 and builtin.os.tag == .macos and builtin.mode != .Debug) return error.SkipZigTest; @@ -891,6 +933,8 @@ extern fn c_ptr_size_float_struct(Vector2) void; extern fn c_ret_ptr_size_float_struct() Vector2; test "C ABI pointer sized float struct" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.cpu.arch == .x86) return error.SkipZigTest; if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest; @@ -914,6 +958,8 @@ pub inline fn expectOk(c_err: c_int) !void { /// Tests for Double + Char struct const DC = extern struct { v1: f64, v2: u8 }; test "DC: Zig passes to C" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; @@ -921,6 +967,8 @@ test "DC: Zig passes to C" { try expectOk(c_assert_DC(.{ .v1 = -0.25, .v2 = 15 })); } test "DC: Zig returns to C" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest; if (comptime builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest; if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest; @@ -929,6 +977,8 @@ test "DC: Zig returns to C" { try expectOk(c_assert_ret_DC()); } test "DC: C passes to Zig" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; @@ -936,6 +986,8 @@ test "DC: C passes to Zig" { try expectOk(c_send_DC()); } test "DC: C returns to Zig" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest; if (comptime builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest; if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest; @@ -949,6 +1001,8 @@ pub extern fn c_assert_ret_DC() c_int; pub extern fn c_send_DC() c_int; pub extern fn c_ret_DC() DC; pub export fn zig_assert_DC(lv: DC) c_int { + if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest"); + var err: c_int = 0; if (lv.v1 != -0.25) err = 1; if (lv.v2 != 15) err = 2; @@ -956,6 +1010,8 @@ pub export fn zig_assert_DC(lv: DC) c_int { return err; } pub export fn zig_ret_DC() DC { + if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest"); + return .{ .v1 = -0.25, .v2 = 15 }; } @@ -963,6 +1019,8 @@ pub export fn zig_ret_DC() DC { const CFF = extern struct { v1: u8, v2: f32, v3: f32 }; test "CFF: Zig passes to C" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.target.cpu.arch == .x86) return error.SkipZigTest; if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; @@ -970,6 +1028,8 @@ test "CFF: Zig passes to C" { try expectOk(c_assert_CFF(.{ .v1 = 39, .v2 = 0.875, .v3 = 1.0 })); } test "CFF: Zig returns to C" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest; if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; @@ -977,6 +1037,8 @@ test "CFF: Zig returns to C" { try expectOk(c_assert_ret_CFF()); } test "CFF: C passes to Zig" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.target.cpu.arch == .x86) return error.SkipZigTest; if (comptime builtin.cpu.arch.isRISCV() and builtin.mode != .Debug) return error.SkipZigTest; if (builtin.cpu.arch == .aarch64 and builtin.mode != .Debug) return error.SkipZigTest; @@ -987,6 +1049,8 @@ test "CFF: C passes to Zig" { try expectOk(c_send_CFF()); } test "CFF: C returns to Zig" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest; if (builtin.cpu.arch == .aarch64 and builtin.mode != .Debug) return error.SkipZigTest; if (comptime builtin.cpu.arch.isRISCV() and builtin.mode != .Debug) return error.SkipZigTest; @@ -1000,6 +1064,8 @@ pub extern fn c_assert_ret_CFF() c_int; pub extern fn c_send_CFF() c_int; pub extern fn c_ret_CFF() CFF; pub export fn zig_assert_CFF(lv: CFF) c_int { + if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest"); + var err: c_int = 0; if (lv.v1 != 39) err = 1; if (lv.v2 != 0.875) err = 2; @@ -1008,6 +1074,8 @@ pub export fn zig_assert_CFF(lv: CFF) c_int { return err; } pub export fn zig_ret_CFF() CFF { + if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest"); + return .{ .v1 = 39, .v2 = 0.875, .v3 = 1.0 }; } @@ -1015,6 +1083,8 @@ pub export fn zig_ret_CFF() CFF { const PD = extern struct { v1: ?*anyopaque, v2: f64 }; test "PD: Zig passes to C" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.target.cpu.arch == .x86) return error.SkipZigTest; if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; @@ -1022,6 +1092,8 @@ test "PD: Zig passes to C" { try expectOk(c_assert_PD(.{ .v1 = null, .v2 = 0.5 })); } test "PD: Zig returns to C" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.target.cpu.arch == .x86) return error.SkipZigTest; if (comptime builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; @@ -1029,6 +1101,8 @@ test "PD: Zig returns to C" { try expectOk(c_assert_ret_PD()); } test "PD: C passes to Zig" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.target.cpu.arch == .x86) return error.SkipZigTest; if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; @@ -1036,6 +1110,8 @@ test "PD: C passes to Zig" { try expectOk(c_send_PD()); } test "PD: C returns to Zig" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.target.cpu.arch == .x86) return error.SkipZigTest; if (comptime builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest; if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; @@ -1047,6 +1123,8 @@ pub extern fn c_assert_ret_PD() c_int; pub extern fn c_send_PD() c_int; pub extern fn c_ret_PD() PD; pub export fn zig_c_assert_PD(lv: PD) c_int { + if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest"); + var err: c_int = 0; if (lv.v1 != null) err = 1; if (lv.v2 != 0.5) err = 2; @@ -1054,9 +1132,13 @@ pub export fn zig_c_assert_PD(lv: PD) c_int { return err; } pub export fn zig_ret_PD() PD { + if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest"); + return .{ .v1 = null, .v2 = 0.5 }; } pub export fn zig_assert_PD(lv: PD) c_int { + if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest"); + var err: c_int = 0; if (lv.v1 != null) err = 1; if (lv.v2 != 0.5) err = 2; @@ -1146,6 +1228,8 @@ const f80_struct = extern struct { }; extern fn c_f80_struct(f80_struct) f80_struct; test "f80 struct" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (!has_f80) return error.SkipZigTest; if (builtin.target.cpu.arch == .x86) return error.SkipZigTest; if (builtin.mode != .Debug) return error.SkipZigTest; @@ -1233,6 +1317,8 @@ test "Stdcall ABI big union" { extern fn c_explict_win64(ByRef) callconv(.Win64) ByRef; test "explicit SysV calling convention" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.cpu.arch != .x86_64) return error.SkipZigTest; const res = c_explict_win64(.{ .val = 1, .arr = undefined }); diff --git a/test/tests.zig b/test/tests.zig index 050faa1ffa..7d6160084b 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -94,6 +94,26 @@ const test_targets = blk: { .use_llvm = false, .use_lld = false, }, + .{ + .target = .{ + .cpu_arch = .x86_64, + .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v2 }, + .os_tag = .linux, + .abi = .none, + }, + .use_llvm = false, + .use_lld = false, + }, + .{ + .target = .{ + .cpu_arch = .x86_64, + .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v3 }, + .os_tag = .linux, + .abi = .none, + }, + .use_llvm = false, + .use_lld = false, + }, // Doesn't support new liveness //.{ // .target = .{ @@ -470,62 +490,123 @@ const test_targets = blk: { }; }; -const c_abi_targets = [_]CrossTarget{ +const CAbiTarget = struct { + target: CrossTarget = .{}, + use_llvm: ?bool = null, + use_lld: ?bool = null, + c_defines: []const []const u8 = &.{}, +}; + +const c_abi_targets = [_]CAbiTarget{ .{}, .{ - .cpu_arch = .x86_64, - .os_tag = .linux, - .abi = .musl, + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + .abi = .musl, + }, }, .{ - .cpu_arch = .x86, - .os_tag = .linux, - .abi = .musl, + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + .abi = .musl, + }, + .use_llvm = false, + .use_lld = false, + .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"}, }, .{ - .cpu_arch = .aarch64, - .os_tag = .linux, - .abi = .musl, + .target = .{ + .cpu_arch = .x86_64, + .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v2 }, + .os_tag = .linux, + .abi = .musl, + }, + .use_llvm = false, + .use_lld = false, + .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"}, }, .{ - .cpu_arch = .arm, - .os_tag = .linux, - .abi = .musleabihf, + .target = .{ + .cpu_arch = .x86_64, + .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v3 }, + .os_tag = .linux, + .abi = .musl, + }, + .use_llvm = false, + .use_lld = false, + .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"}, }, .{ - .cpu_arch = .mips, - .os_tag = .linux, - .abi = .musl, + .target = .{ + .cpu_arch = .x86, + .os_tag = .linux, + .abi = .musl, + }, }, .{ - .cpu_arch = .riscv64, - .os_tag = .linux, - .abi = .musl, + .target = .{ + .cpu_arch = .aarch64, + .os_tag = .linux, + .abi = .musl, + }, }, .{ - .cpu_arch = .wasm32, - .os_tag = .wasi, - .abi = .musl, + .target = .{ + .cpu_arch = .arm, + .os_tag = .linux, + .abi = .musleabihf, + }, }, .{ - .cpu_arch = .powerpc, - .os_tag = .linux, - .abi = .musl, + .target = .{ + .cpu_arch = .mips, + .os_tag = .linux, + .abi = .musl, + }, }, .{ - .cpu_arch = .powerpc64le, - .os_tag = .linux, - .abi = .musl, + .target = .{ + .cpu_arch = .riscv64, + .os_tag = .linux, + .abi = .musl, + }, }, .{ - .cpu_arch = .x86, - .os_tag = .windows, - .abi = .gnu, + .target = .{ + .cpu_arch = .wasm32, + .os_tag = .wasi, + .abi = .musl, + }, }, .{ - .cpu_arch = .x86_64, - .os_tag = .windows, - .abi = .gnu, + .target = .{ + .cpu_arch = .powerpc, + .os_tag = .linux, + .abi = .musl, + }, + }, + .{ + .target = .{ + .cpu_arch = .powerpc64le, + .os_tag = .linux, + .abi = .musl, + }, + }, + .{ + .target = .{ + .cpu_arch = .x86, + .os_tag = .windows, + .abi = .gnu, + }, + }, + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .windows, + .abi = .gnu, + }, }, }; @@ -1017,6 +1098,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { const libc_suffix = if (test_target.link_libc == true) "-libc" else ""; const triple_txt = test_target.target.zigTriple(b.allocator) catch @panic("OOM"); + const model_txt = test_target.target.getCpuModel().name; // wasm32-wasi builds need more RAM, idk why const max_rss = if (test_target.target.getOs().tag == .wasi) @@ -1054,9 +1136,10 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { these_tests.stack_size = 2 * 1024 * 1024; } - const qualified_name = b.fmt("{s}-{s}-{s}{s}{s}{s}{s}", .{ + const qualified_name = b.fmt("{s}-{s}-{s}-{s}{s}{s}{s}{s}", .{ options.name, triple_txt, + model_txt, @tagName(test_target.optimize_mode), libc_suffix, single_threaded_suffix, @@ -1144,33 +1227,50 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S if (optimize_mode != .Debug and skip_release) continue; for (c_abi_targets) |c_abi_target| { - if (skip_non_native and !c_abi_target.isNative()) continue; + if (skip_non_native and !c_abi_target.target.isNative()) continue; - if (c_abi_target.isWindows() and c_abi_target.getCpuArch() == .aarch64) { + if (c_abi_target.target.isWindows() and c_abi_target.target.getCpuArch() == .aarch64) { // https://github.com/ziglang/zig/issues/14908 continue; } - const triple_prefix = c_abi_target.zigTriple(b.allocator) catch @panic("OOM"); + if (c_abi_target.use_llvm == false and optimize_mode == .ReleaseFast) { + // panic: unrecognized command line argument + continue; + } const test_step = b.addTest(.{ - .root_source_file = .{ .path = "test/c_abi/main.zig" }, - .optimize = optimize_mode, - .target = c_abi_target, - .name = b.fmt("test-c-abi-{s}-{s}", .{ - triple_prefix, @tagName(optimize_mode), + .name = b.fmt("test-c-abi-{s}-{s}-{s}{s}{s}", .{ + c_abi_target.target.zigTriple(b.allocator) catch @panic("OOM"), + c_abi_target.target.getCpuModel().name, + @tagName(optimize_mode), + if (c_abi_target.use_llvm == true) + "-llvm" + else if (c_abi_target.target.ofmt == std.Target.ObjectFormat.c) + "-cbe" + else if (c_abi_target.use_llvm == false) + "-selfhosted" + else + "", + if (c_abi_target.use_lld == false) "-no-lld" else "", }), + .root_source_file = .{ .path = "test/c_abi/main.zig" }, + .target = c_abi_target.target, + .optimize = optimize_mode, + .link_libc = true, + .use_llvm = c_abi_target.use_llvm, + .use_lld = c_abi_target.use_lld, }); - if (c_abi_target.abi != null and c_abi_target.abi.?.isMusl()) { + if (c_abi_target.target.abi != null and c_abi_target.target.abi.?.isMusl()) { // TODO NativeTargetInfo insists on dynamically linking musl // for some reason? test_step.target_info.dynamic_linker.max_byte = null; } - test_step.linkLibC(); test_step.addCSourceFile(.{ .file = .{ .path = "test/c_abi/cfuncs.c" }, .flags = &.{"-std=c99"}, }); + for (c_abi_target.c_defines) |define| test_step.defineCMacro(define, null); // This test is intentionally trying to check if the external ABI is // done properly. LTO would be a hindrance to this.