2022-05-06 18:14:31 +01:00
|
|
|
const std = @import("std");
|
|
|
|
const builtin = @import("builtin");
|
|
|
|
const CrossTarget = std.zig.CrossTarget;
|
|
|
|
|
2023-01-31 07:19:51 +00:00
|
|
|
// TODO integrate this with the std.Build executor API
|
2022-05-06 18:14:31 +01:00
|
|
|
fn isRunnableTarget(t: CrossTarget) bool {
|
|
|
|
if (t.isNative()) return true;
|
|
|
|
|
|
|
|
return (t.getOsTag() == builtin.os.tag and
|
|
|
|
t.getCpuArch() == builtin.cpu.arch);
|
|
|
|
}
|
|
|
|
|
2023-01-31 07:19:51 +00:00
|
|
|
pub fn build(b: *std.Build) void {
|
2023-01-31 04:39:43 +00:00
|
|
|
const optimize = b.standardOptimizeOption(.{});
|
2022-05-06 18:14:31 +01:00
|
|
|
const target = b.standardTargetOptions(.{});
|
|
|
|
|
2023-01-31 04:39:43 +00:00
|
|
|
const exe = b.addExecutable(.{
|
|
|
|
.name = "zigtest",
|
|
|
|
.root_source_file = .{ .path = "main.zig" },
|
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
2022-05-06 18:14:31 +01:00
|
|
|
exe.install();
|
|
|
|
|
|
|
|
const c_sources = [_][]const u8{
|
|
|
|
"test.c",
|
|
|
|
};
|
|
|
|
|
|
|
|
exe.addCSourceFiles(&c_sources, &.{});
|
|
|
|
exe.linkLibC();
|
|
|
|
|
|
|
|
var i: i32 = 0;
|
|
|
|
while (i < 1000) : (i += 1) {
|
|
|
|
exe.defineCMacro("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
|
|
|
|
}
|
|
|
|
|
|
|
|
exe.defineCMacro("FOO", "42");
|
|
|
|
exe.defineCMacro("BAR", "\"BAR\"");
|
|
|
|
exe.defineCMacro("BAZ",
|
|
|
|
\\"\"BAZ\""
|
|
|
|
);
|
|
|
|
exe.defineCMacro("QUX", "\"Q\" \"UX\"");
|
|
|
|
exe.defineCMacro("QUUX", "\"QU\\\"UX\"");
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|