zig/test/standalone/mix_c_files/build.zig
Andrew Kelley 08c768ad82 pre-merge cleanups
* Annotate workarounds with their corresponding GitHub issue links.
 * Enable test coverage for LTO on Windows with the added c_compiler test.
2021-11-15 16:32:15 -07:00

33 lines
961 B
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("test", "main.zig");
exe.addCSourceFile("test.c", &[_][]const u8{"-std=c11"});
exe.setBuildMode(mode);
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);
}
}