mirror of
https://github.com/ziglang/zig.git
synced 2024-11-30 09:02:32 +00:00
2cd3989cb3
Closes #12706
40 lines
1.0 KiB
Zig
40 lines
1.0 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 exe = b.addExecutable("main", "main.zig");
|
|
exe.setBuildMode(mode);
|
|
exe.install();
|
|
|
|
const c_sources = [_][]const u8{
|
|
"test.c",
|
|
};
|
|
|
|
exe.addCSourceFiles(&c_sources, &.{});
|
|
exe.linkLibC();
|
|
|
|
exe.setTarget(target);
|
|
b.default_step.dependOn(&exe.step);
|
|
|
|
const test_step = b.step("test", "Test the program");
|
|
if (isRunnableTarget(target)) {
|
|
const run_cmd = exe.run();
|
|
test_step.dependOn(&run_cmd.step);
|
|
} else {
|
|
test_step.dependOn(&exe.step);
|
|
}
|
|
}
|