authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-21 23:01:49+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-22 11:31:41+03:00
log8fa91939a880ac5394aaac457238251d2c937059
treec1c275ae097eb463a23e71fe40bfd7717c1e5f4a
parent12a2ccfb459e89f6a59c14de36bf80bf51a0a517

build.zig: separate C ABI tests from standalone tests


5 files changed, 80 insertions(+), 63 deletions(-)

build.zig+1
......@@ -508,6 +508,7 @@ pub fn build(b: *Builder) !void {
508508 b.enable_wasmtime,
509509 b.enable_wine,
510510 ));
511 test_step.dependOn(tests.addCAbiTests(b, skip_non_native));
511512 test_step.dependOn(tests.addLinkTests(b, test_filter, modes, enable_macos_sdk, skip_stage2_tests));
512513 test_step.dependOn(tests.addStackTraceTests(b, test_filter, modes));
513514 test_step.dependOn(tests.addCliTests(b, test_filter, modes));
test/c_abi/build.zig deleted-22
......@@ -1,22 +0,0 @@
1const Builder = @import("std").build.Builder;
2
3pub fn build(b: *Builder) void {
4 const rel_opts = b.standardReleaseOptions();
5 const target = b.standardTargetOptions(.{});
6
7 const c_obj = b.addObject("cfuncs", null);
8 c_obj.addCSourceFile("cfuncs.c", &[_][]const u8{"-std=c99"});
9 c_obj.setBuildMode(rel_opts);
10 c_obj.linkSystemLibrary("c");
11 c_obj.target = target;
12
13 const main = b.addTest("main.zig");
14 main.setBuildMode(rel_opts);
15 main.addObject(c_obj);
16 main.target = target;
17
18 const test_step = b.step("test", "Test the program");
19 test_step.dependOn(&main.step);
20
21 b.default_step.dependOn(test_step);
22}
test/c_abi/build_wasm.zig deleted-24
......@@ -1,24 +0,0 @@
1const std = @import("std");
2const Builder = std.build.Builder;
3
4pub fn build(b: *Builder) void {
5 const rel_opts = b.standardReleaseOptions();
6 const target: std.zig.CrossTarget = .{ .cpu_arch = .wasm32, .os_tag = .wasi };
7 b.use_stage1 = false;
8
9 const c_obj = b.addObject("cfuncs", null);
10 c_obj.addCSourceFile("cfuncs.c", &[_][]const u8{"-std=c99"});
11 c_obj.setBuildMode(rel_opts);
12 c_obj.linkSystemLibrary("c");
13 c_obj.setTarget(target);
14
15 const main = b.addTest("main.zig");
16 main.setBuildMode(rel_opts);
17 main.addObject(c_obj);
18 main.setTarget(target);
19
20 const test_step = b.step("test", "Test the program");
21 test_step.dependOn(&main.step);
22
23 b.default_step.dependOn(test_step);
24}
test/standalone.zig-17
......@@ -44,23 +44,6 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
4444 if (builtin.os.tag != .wasi) {
4545 cases.addBuildFile("test/standalone/load_dynamic_library/build.zig", .{});
4646 }
47 // C ABI compatibility issue: https://github.com/ziglang/zig/issues/1481
48 if (builtin.cpu.arch == .x86_64) {
49 if (builtin.zig_backend == .stage1 or builtin.zig_backend == .stage2_llvm) {
50 cases.addBuildFile("test/c_abi/build.zig", .{});
51 }
52 }
53 if (builtin.cpu.arch.isAARCH64() and builtin.zig_backend == .stage2_llvm) {
54 cases.addBuildFile("test/c_abi/build.zig", .{});
55 }
56 if (builtin.cpu.arch == .i386 and builtin.zig_backend == .stage2_llvm) {
57 cases.addBuildFile("test/c_abi/build.zig", .{});
58 }
59 // C ABI tests only pass for the Wasm target when using stage2
60 cases.addBuildFile("test/c_abi/build_wasm.zig", .{
61 .requires_stage2 = true,
62 .use_emulation = true,
63 });
6447
6548 cases.addBuildFile("test/standalone/c_compiler/build.zig", .{
6649 .build_modes = true,
test/tests.zig+79
......@@ -1268,3 +1268,82 @@ fn printInvocation(args: []const []const u8) void {
12681268 }
12691269 std.debug.print("\n", .{});
12701270}
1271
1272const c_abi_targets = [_]CrossTarget{
1273 .{},
1274 .{
1275 .cpu_arch = .x86_64,
1276 .os_tag = .linux,
1277 .abi = .musl,
1278 },
1279 .{
1280 .cpu_arch = .i386,
1281 .os_tag = .linux,
1282 .abi = .musl,
1283 },
1284 .{
1285 .cpu_arch = .aarch64,
1286 .os_tag = .linux,
1287 .abi = .musl,
1288 },
1289 .{
1290 .cpu_arch = .arm,
1291 .os_tag = .linux,
1292 .abi = .musleabihf,
1293 },
1294 .{
1295 .cpu_arch = .mips,
1296 .os_tag = .linux,
1297 .abi = .musl,
1298 },
1299 .{
1300 .cpu_arch = .riscv64,
1301 .os_tag = .linux,
1302 .abi = .musl,
1303 },
1304 .{
1305 .cpu_arch = .wasm32,
1306 .os_tag = .wasi,
1307 .abi = .musl,
1308 },
1309 .{
1310 .cpu_arch = .powerpc,
1311 .os_tag = .linux,
1312 .abi = .musl,
1313 },
1314 .{
1315 .cpu_arch = .powerpc64le,
1316 .os_tag = .linux,
1317 .abi = .none,
1318 },
1319};
1320
1321pub fn addCAbiTests(b: *build.Builder, skip_non_native: bool) *build.Step {
1322 const step = b.step("test-c-abi", "Run the C ABI tests");
1323
1324 for (c_abi_targets) |c_abi_target| {
1325 if (skip_non_native and !c_abi_target.isNative())
1326 continue;
1327
1328 const test_step = b.addTest("test/c_abi/main.zig");
1329 test_step.setTarget(c_abi_target);
1330 if (c_abi_target.abi != null and c_abi_target.abi.?.isMusl()) {
1331 // TODO NativeTargetInfo insists on dynamically linking musl
1332 // for some reason?
1333 test_step.target_info.dynamic_linker.max_byte = null;
1334 }
1335 test_step.linkLibC();
1336 test_step.addCSourceFile("test/c_abi/cfuncs.c", &.{"-std=c99"});
1337
1338 const triple_prefix = c_abi_target.zigTriple(b.allocator) catch unreachable;
1339 test_step.setNamePrefix(b.fmt("{s}-{s} ", .{
1340 "test-c-abi",
1341 triple_prefix,
1342 }));
1343
1344 test_step.use_stage1 = false;
1345
1346 step.dependOn(&test_step.step);
1347 }
1348 return step;
1349}