2018-11-14 21:06:20 +08:00
|
|
|
const std = @import("std");
|
|
|
|
|
|
|
|
const Builder = std.build.Builder;
|
|
|
|
|
|
|
|
pub fn build(b: *Builder) void {
|
|
|
|
const mode = b.standardReleaseOptions();
|
2020-08-15 21:23:46 +08:00
|
|
|
const target = b.standardTargetOptions(.{});
|
2018-11-14 21:06:20 +08:00
|
|
|
|
2022-11-15 18:17:21 +08:00
|
|
|
const test_step = b.step("test", "Run all tests in all modes.");
|
|
|
|
const tests = b.addTest("clap.zig");
|
|
|
|
tests.setBuildMode(mode);
|
|
|
|
tests.setTarget(target);
|
|
|
|
test_step.dependOn(&tests.step);
|
2019-08-18 00:48:06 +08:00
|
|
|
|
2018-11-14 21:06:20 +08:00
|
|
|
const example_step = b.step("examples", "Build examples");
|
2021-05-27 03:06:10 +08:00
|
|
|
inline for (.{
|
2019-11-27 22:13:31 +08:00
|
|
|
"simple",
|
2020-11-11 01:53:57 +08:00
|
|
|
"simple-ex",
|
2018-11-14 21:06:20 +08:00
|
|
|
"streaming-clap",
|
2019-06-22 01:15:32 +08:00
|
|
|
"help",
|
2020-03-06 06:24:36 +08:00
|
|
|
"usage",
|
2018-11-14 21:06:20 +08:00
|
|
|
}) |example_name| {
|
|
|
|
const example = b.addExecutable(example_name, "example/" ++ example_name ++ ".zig");
|
2019-06-12 21:30:30 +08:00
|
|
|
example.addPackagePath("clap", "clap.zig");
|
2018-11-14 21:06:20 +08:00
|
|
|
example.setBuildMode(mode);
|
2020-08-15 21:23:46 +08:00
|
|
|
example.setTarget(target);
|
2019-08-17 21:21:45 +08:00
|
|
|
example.install();
|
2018-11-14 21:06:20 +08:00
|
|
|
example_step.dependOn(&example.step);
|
|
|
|
}
|
|
|
|
|
2020-04-11 20:28:36 +08:00
|
|
|
const readme_step = b.step("readme", "Remake README.");
|
2019-06-22 01:15:32 +08:00
|
|
|
const readme = readMeStep(b);
|
|
|
|
readme.dependOn(example_step);
|
|
|
|
readme_step.dependOn(readme);
|
|
|
|
|
2018-11-14 21:06:20 +08:00
|
|
|
const all_step = b.step("all", "Build everything and runs all tests");
|
2022-11-15 18:17:21 +08:00
|
|
|
all_step.dependOn(test_step);
|
2018-11-14 21:06:20 +08:00
|
|
|
all_step.dependOn(example_step);
|
2019-06-22 01:15:32 +08:00
|
|
|
all_step.dependOn(readme_step);
|
2018-11-14 21:06:20 +08:00
|
|
|
|
|
|
|
b.default_step.dependOn(all_step);
|
|
|
|
}
|
|
|
|
|
2019-06-22 01:15:32 +08:00
|
|
|
fn readMeStep(b: *Builder) *std.build.Step {
|
|
|
|
const s = b.allocator.create(std.build.Step) catch unreachable;
|
2021-06-24 23:36:12 +08:00
|
|
|
s.* = std.build.Step.init(.custom, "ReadMeStep", b.allocator, struct {
|
2019-06-22 01:15:32 +08:00
|
|
|
fn make(step: *std.build.Step) anyerror!void {
|
|
|
|
@setEvalBranchQuota(10000);
|
2021-06-24 23:36:35 +08:00
|
|
|
_ = step;
|
2020-03-02 13:32:15 +08:00
|
|
|
const file = try std.fs.cwd().createFile("README.md", .{});
|
2021-05-09 00:08:52 +08:00
|
|
|
const stream = file.writer();
|
2019-12-10 12:03:39 +08:00
|
|
|
try stream.print(@embedFile("example/README.md.template"), .{
|
2019-11-27 22:13:31 +08:00
|
|
|
@embedFile("example/simple.zig"),
|
2022-02-26 02:40:00 +08:00
|
|
|
@embedFile("example/simple-ex.zig"),
|
2019-11-27 22:13:31 +08:00
|
|
|
@embedFile("example/streaming-clap.zig"),
|
2019-06-22 01:15:32 +08:00
|
|
|
@embedFile("example/help.zig"),
|
2020-03-06 06:24:36 +08:00
|
|
|
@embedFile("example/usage.zig"),
|
2019-12-10 12:03:39 +08:00
|
|
|
});
|
2019-06-22 01:15:32 +08:00
|
|
|
}
|
|
|
|
}.make);
|
|
|
|
return s;
|
|
|
|
}
|