Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
77 lines (70 loc) · 3.06 KB
/
Copy pathbuild.zig
File metadata and controls
77 lines (70 loc) · 3.06 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// The manifest is the one place the version lives; the library reads it
// back through this so its user agent cannot drift from what was released.
const build_options = b.addOptions();
build_options.addOption([]const u8, "version", @import("build.zig.zon").version);
const internetdata = b.addModule("internetdata", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.imports = &.{.{ .name = "build_options", .module = build_options.createModule() }},
});
const test_step = b.step("test", "Run the unit and conformance tests");
const unit_tests = b.addTest(.{ .root_module = internetdata });
test_step.dependOn(&b.addRunArtifact(unit_tests).step);
const suites = [_][]const u8{
"test/conformance.zig",
"test/client.zig",
"test/sharing.zig",
"test/oauth.zig",
"test/timeout.zig",
"test/readme.zig",
};
for (suites) |path| {
test_step.dependOn(&b.addRunArtifact(suite(b, internetdata, target, optimize, path)).step);
}
// Built by CI so the programs the README points at cannot go stale.
const example_step = b.step("example", "Build the example programs into zig-out/bin");
for ([_][]const u8{ "lookup", "catalog" }) |name| {
const example = b.addExecutable(.{
.name = name,
.root_module = b.createModule(.{
.root_source_file = b.path(b.fmt("example/{s}.zig", .{name})),
.target = target,
.optimize = optimize,
.imports = &.{.{ .name = "internetdata", .module = internetdata }},
}),
});
example_step.dependOn(&b.addInstallArtifact(example, .{}).step);
}
// Kept out of `test` so a plain build stays offline and needs no credential.
const live_step = b.step("live", "Query the real API (needs network and an API key)");
const live_tests = suite(b, internetdata, target, optimize, "test/live.zig");
const run_live = b.addRunArtifact(live_tests);
run_live.has_side_effects = true;
live_step.dependOn(&run_live.step);
}
/// A test binary that consumes the library the way a dependent package does,
/// through its published module name, with the shared conformance corpus
/// embedded so a missing or malformed one is a build failure.
fn suite(
b: *std.Build,
internetdata: *std.Build.Module,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
path: []const u8,
) *std.Build.Step.Compile {
const tests = b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path(path),
.target = target,
.optimize = optimize,
.imports = &.{.{ .name = "internetdata", .module = internetdata }},
}) });
tests.root_module.addAnonymousImport("corpus", .{
.root_source_file = b.path("testdata/testdata.json"),
});
return tests;
}