2021-05-24 23:11:00 +01:00
|
|
|
const std = @import("std");
|
2022-05-11 00:38:37 +01:00
|
|
|
const builtin = @import("builtin");
|
2021-05-24 23:11:00 +01:00
|
|
|
|
2023-03-08 07:16:16 +00:00
|
|
|
pub fn build(b: *std.Build) void {
|
|
|
|
const test_step = b.step("test", "Test it");
|
|
|
|
b.default_step = test_step;
|
2022-05-11 00:38:37 +01:00
|
|
|
|
2023-03-08 07:16:16 +00:00
|
|
|
add(b, test_step, .Debug);
|
|
|
|
add(b, test_step, .ReleaseFast);
|
|
|
|
add(b, test_step, .ReleaseSmall);
|
|
|
|
add(b, test_step, .ReleaseSafe);
|
2022-05-11 00:38:37 +01:00
|
|
|
}
|
|
|
|
|
2023-03-08 07:16:16 +00:00
|
|
|
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
|
|
|
|
const target: std.zig.CrossTarget = .{};
|
2021-05-24 23:11:00 +01:00
|
|
|
|
2023-01-31 04:39:43 +00:00
|
|
|
const exe_c = b.addExecutable(.{
|
|
|
|
.name = "test_c",
|
|
|
|
.optimize = optimize,
|
|
|
|
.target = target,
|
|
|
|
});
|
2021-05-24 23:11:00 +01:00
|
|
|
exe_c.addCSourceFile("test.c", &[0][]const u8{});
|
|
|
|
exe_c.linkLibC();
|
|
|
|
|
2023-01-31 04:39:43 +00:00
|
|
|
const exe_cpp = b.addExecutable(.{
|
|
|
|
.name = "test_cpp",
|
|
|
|
.optimize = optimize,
|
|
|
|
.target = target,
|
|
|
|
});
|
2021-05-24 23:11:00 +01:00
|
|
|
b.default_step.dependOn(&exe_cpp.step);
|
|
|
|
exe_cpp.addCSourceFile("test.cpp", &[0][]const u8{});
|
2021-11-01 04:36:30 +00:00
|
|
|
exe_cpp.linkLibCpp();
|
2021-05-24 23:11:00 +01:00
|
|
|
|
2022-05-11 00:38:37 +01:00
|
|
|
switch (target.getOsTag()) {
|
2021-11-16 19:44:44 +00:00
|
|
|
.windows => {
|
|
|
|
// https://github.com/ziglang/zig/issues/8531
|
|
|
|
exe_cpp.want_lto = false;
|
|
|
|
},
|
2021-05-24 23:11:00 +01:00
|
|
|
.macos => {
|
2021-11-15 23:32:15 +00:00
|
|
|
// https://github.com/ziglang/zig/issues/8680
|
2021-05-24 23:11:00 +01:00
|
|
|
exe_cpp.want_lto = false;
|
|
|
|
exe_c.want_lto = false;
|
|
|
|
},
|
|
|
|
else => {},
|
|
|
|
}
|
|
|
|
|
2023-03-08 07:16:16 +00:00
|
|
|
const run_c_cmd = b.addRunArtifact(exe_c);
|
|
|
|
run_c_cmd.expectExitCode(0);
|
|
|
|
run_c_cmd.skip_foreign_checks = true;
|
|
|
|
test_step.dependOn(&run_c_cmd.step);
|
|
|
|
|
|
|
|
const run_cpp_cmd = b.addRunArtifact(exe_cpp);
|
|
|
|
run_cpp_cmd.expectExitCode(0);
|
|
|
|
run_cpp_cmd.skip_foreign_checks = true;
|
|
|
|
test_step.dependOn(&run_cpp_cmd.step);
|
2021-05-24 23:11:00 +01:00
|
|
|
}
|