Andrew Kelley 36e2d992dd combine std.build and std.build.Builder into std.Build
I've been wanting to do this for along time.
2023-01-31 15:09:35 -07:00

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);
}
}