-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.zig
71 lines (58 loc) · 2.58 KB
/
build.zig
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
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Module
const web3_module = b.addModule("web3", .{
.root_source_file = .{
.cwd_relative = "src/web3.zig",
},
});
try b.modules.put(b.dupe("web3"), web3_module);
// Creates a step for unit testing
const unit_tests = b.addTest(.{
.root_source_file = .{
.cwd_relative = "src/web3.zig"
},
.target = target,
.optimize = optimize,
});
const run_unit_tests = b.addRunArtifact(unit_tests);
// Run tests step
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_unit_tests.step);
// Examples
const example_dir_path = try std.fs.path.join(b.allocator, &[_][]const u8{ "src", "examples" });
const examples_dir = std.fs.cwd().openDir(example_dir_path, .{ .iterate = true }) catch return;
var examples_dir_iter = examples_dir.iterate();
while (try examples_dir_iter.next()) |path| {
switch (path.kind) {
.file => {
if (std.mem.eql(u8, std.fs.path.extension(path.name), ".zig")) {
const example_path = std.fs.path.join(b.allocator, &[_][]const u8{ example_dir_path, path.name }) catch @panic("Out of memory");
const exe = b.addExecutable(.{
.name = std.fs.path.stem(path.name),
.root_source_file = .{
.cwd_relative = example_path
},
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("web3", web3_module);
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
// Pass args
if (b.args) |args| {
run_cmd.addArgs(args);
}
const step_name = std.mem.join(b.allocator, "_", &[_][]const u8{ "example", std.fs.path.stem(path.name) }) catch @panic("Out of memory");
const step_desc = std.mem.join(b.allocator, "", &[_][]const u8{ "Run example \"", example_path, "\"" }) catch @panic("Out of memory");
const run_step = b.step(step_name, step_desc);
run_step.dependOn(&run_cmd.step);
}
},
else => continue,
}
}
}