mirror of
https://github.com/ziglang/zig.git
synced 2026-01-09 08:55:36 +00:00
42 lines
1.0 KiB
Zig
42 lines
1.0 KiB
Zig
const std = @import("std");
|
|
const builtin = @import("builtin");
|
|
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: *std.Build) void {
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
const target = b.standardTargetOptions(.{});
|
|
|
|
const exe = b.addExecutable(.{
|
|
.name = "main",
|
|
.root_source_file = .{ .path = "main.zig" },
|
|
.optimize = optimize,
|
|
.target = target,
|
|
});
|
|
exe.install();
|
|
|
|
const c_sources = [_][]const u8{
|
|
"test.c",
|
|
};
|
|
|
|
exe.addCSourceFiles(&c_sources, &.{});
|
|
exe.linkLibC();
|
|
|
|
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);
|
|
}
|
|
}
|