From 8b871ae27584c2433683ca064dbd3e7127d2a184 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 6 Mar 2023 22:57:53 -0700 Subject: [PATCH] re-enable C ABI tests These were mostly already using the correct build API. I cleaned up the code a bit and unconditionally disabled LTO for these tests since that actually tests the intended behavior better. --- build.zig | 2 +- test/tests.zig | 56 +++++++++++++++++++++++++------------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/build.zig b/build.zig index 7c22016bb7..b97ea3c24c 100644 --- a/build.zig +++ b/build.zig @@ -460,7 +460,7 @@ pub fn build(b: *std.Build) !void { // b.enable_wine, // enable_symlinks_windows, //)); - //test_step.dependOn(tests.addCAbiTests(b, skip_non_native, skip_release)); + test_step.dependOn(tests.addCAbiTests(b, skip_non_native, skip_release)); //test_step.dependOn(tests.addLinkTests(b, test_filter, optimization_modes, enable_macos_sdk, skip_stage2_tests, enable_symlinks_windows)); test_step.dependOn(tests.addStackTraceTests(b, test_filter, optimization_modes)); test_step.dependOn(tests.addCliTests(b, test_filter, optimization_modes)); diff --git a/test/tests.zig b/test/tests.zig index 665ad023fd..1e99e5c2a8 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -985,37 +985,37 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S const optimize_modes: [2]OptimizeMode = .{ .Debug, .ReleaseFast }; - for (optimize_modes[0 .. @as(u8, 1) + @boolToInt(!skip_release)]) |optimize_mode| for (c_abi_targets) |c_abi_target| { - if (skip_non_native and !c_abi_target.isNative()) - continue; + for (optimize_modes) |optimize_mode| { + if (optimize_mode != .Debug and skip_release) continue; - const test_step = b.addTest(.{ - .root_source_file = .{ .path = "test/c_abi/main.zig" }, - .optimize = optimize_mode, - .target = c_abi_target, - }); - if (c_abi_target.abi != null and c_abi_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("test/c_abi/cfuncs.c", &.{"-std=c99"}); + for (c_abi_targets) |c_abi_target| { + if (skip_non_native and !c_abi_target.isNative()) continue; - if (c_abi_target.isWindows() and (c_abi_target.getCpuArch() == .x86 or builtin.target.os.tag == .linux)) { - // LTO currently incorrectly strips stdcall name-mangled functions - // LLD crashes in LTO here when cross compiling for windows on linux + const test_step = b.addTest(.{ + .root_source_file = .{ .path = "test/c_abi/main.zig" }, + .optimize = optimize_mode, + .target = c_abi_target, + }); + if (c_abi_target.abi != null and c_abi_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("test/c_abi/cfuncs.c", &.{"-std=c99"}); + // This test is intentionally trying to check if the external ABI is + // done properly. LTO would be a hindrance to this. test_step.want_lto = false; + + const triple_prefix = c_abi_target.zigTriple(b.allocator) catch @panic("OOM"); + test_step.setNamePrefix(b.fmt("{s}-{s}-{s} ", .{ + "test-c-abi", + triple_prefix, + @tagName(optimize_mode), + })); + + step.dependOn(&test_step.step); } - - const triple_prefix = c_abi_target.zigTriple(b.allocator) catch @panic("OOM"); - test_step.setNamePrefix(b.fmt("{s}-{s}-{s} ", .{ - "test-c-abi", - triple_prefix, - @tagName(optimize_mode), - })); - - step.dependOn(&test_step.step); - }; + } return step; }