Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
78 lines (63 loc) · 2.44 KB
/
Copy pathbuild.zig
File metadata and controls
78 lines (63 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const thc = b.addModule("tardy_http_client", .{
.root_source_file = b.path("src/Client.zig"),
.target = target,
.optimize = optimize,
});
const tardy = b.dependency("tardy", .{
.target = target,
.optimize = optimize,
}).module("tardy");
thc.addImport("tardy", tardy);
add_example(b, "basic", target, optimize, thc);
add_example(b, "multi_fetch", target, optimize, thc);
add_example(b, "url_scraper", target, optimize, thc);
const test_runner = std.Build.Step.Compile.TestRunner{ .path = b.path("test_runner.zig"), .mode = .simple };
const tests = b.addTest(.{
.name = "all_tests",
.root_source_file = b.path("./src/tests.zig"),
.optimize = optimize,
.test_runner = test_runner,
});
tests.root_module.addImport("tardy", tardy);
const test_artifact = b.addRunArtifact(tests);
test_artifact.step.dependOn(&tests.step);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&test_artifact.step);
}
fn add_example(
b: *std.Build,
name: []const u8,
target: std.Build.ResolvedTarget,
optimize: std.builtin.Mode,
thc_module: *std.Build.Module,
) void {
const example = b.addExecutable(.{
.name = name,
.root_source_file = b.path(b.fmt("./examples/{s}/main.zig", .{name})),
.target = target,
.optimize = optimize,
.strip = false,
});
const tardy = b.dependency("tardy", .{
.target = target,
.optimize = optimize,
}).module("tardy");
example.root_module.addImport("tardy_http_client", thc_module);
example.root_module.addImport("tardy", tardy);
const install_artifact = b.addInstallArtifact(example, .{});
b.getInstallStep().dependOn(&install_artifact.step);
const build_step = b.step(b.fmt("{s}", .{name}), b.fmt("Build thc example ({s})", .{name}));
build_step.dependOn(&install_artifact.step);
const run_artifact = b.addRunArtifact(example);
if (b.args) |args| {
run_artifact.addArgs(args);
}
run_artifact.step.dependOn(&install_artifact.step);
const run_step = b.step(b.fmt("run_{s}", .{name}), b.fmt("Run thc example ({s})", .{name}));
run_step.dependOn(&install_artifact.step);
run_step.dependOn(&run_artifact.step);
}