mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 07:32:44 +00:00
45415093c6
* back out the changes to RunStep * move the disabled test to the .cpp code and avoid a confusing name-collision with the _LIBCPP macro prefix * fix merge conflict with the edits to the same test that ensure global initializers are called. Now this branch is only concerned with single-threaded targets and passing the correct macro defines to libc++.
57 lines
1.7 KiB
Zig
57 lines
1.7 KiB
Zig
const std = @import("std");
|
|
const builtin = @import("builtin");
|
|
const Builder = std.build.Builder;
|
|
const CrossTarget = std.zig.CrossTarget;
|
|
|
|
// TODO integrate this with the std.build executor API
|
|
fn isRunnableTarget(t: CrossTarget) bool {
|
|
if (t.isNative()) return true;
|
|
|
|
return (t.getOsTag() == builtin.os.tag and
|
|
t.getCpuArch() == builtin.cpu.arch);
|
|
}
|
|
|
|
pub fn build(b: *Builder) void {
|
|
const mode = b.standardReleaseOptions();
|
|
const target = b.standardTargetOptions(.{});
|
|
|
|
const test_step = b.step("test", "Test the program");
|
|
|
|
const exe_c = b.addExecutable("test_c", null);
|
|
b.default_step.dependOn(&exe_c.step);
|
|
exe_c.addCSourceFile("test.c", &[0][]const u8{});
|
|
exe_c.setBuildMode(mode);
|
|
exe_c.setTarget(target);
|
|
exe_c.linkLibC();
|
|
|
|
const exe_cpp = b.addExecutable("test_cpp", null);
|
|
b.default_step.dependOn(&exe_cpp.step);
|
|
exe_cpp.addCSourceFile("test.cpp", &[0][]const u8{});
|
|
exe_cpp.setBuildMode(mode);
|
|
exe_cpp.setTarget(target);
|
|
exe_cpp.linkLibCpp();
|
|
|
|
switch (target.getOsTag()) {
|
|
.windows => {
|
|
// https://github.com/ziglang/zig/issues/8531
|
|
exe_cpp.want_lto = false;
|
|
},
|
|
.macos => {
|
|
// https://github.com/ziglang/zig/issues/8680
|
|
exe_cpp.want_lto = false;
|
|
exe_c.want_lto = false;
|
|
},
|
|
else => {},
|
|
}
|
|
|
|
if (isRunnableTarget(target)) {
|
|
const run_c_cmd = exe_c.run();
|
|
test_step.dependOn(&run_c_cmd.step);
|
|
const run_cpp_cmd = exe_cpp.run();
|
|
test_step.dependOn(&run_cpp_cmd.step);
|
|
} else {
|
|
test_step.dependOn(&exe_c.step);
|
|
test_step.dependOn(&exe_cpp.step);
|
|
}
|
|
}
|