-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
118 lines (101 loc) · 3.87 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const core = ModuleInfo.init(b, "wasm-core", "src/core/mod.zig", &.{});
const decode = ModuleInfo.init(b, "wasm-decode", "src/decode/mod.zig", &.{core});
const validate = ModuleInfo.init(b, "wasm-validate", "src/validate/mod.zig", &.{core});
const runtime = ModuleInfo.init(b, "wasm-runtime", "src/runtime/mod.zig", &.{ core, decode, validate });
const spec = ModuleInfo.init(b, "wasm-spec-test", "src/spec_test/mod.zig", &.{ core, decode, validate, runtime });
const all_modules = .{ core, decode, validate, runtime, spec };
{
const modules = .{ core, decode, runtime };
const exe = b.addExecutable(.{
.name = "zig-wasm-interp",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
inline for (modules) |info| {
exe.root_module.addImport(info.name, info.module);
}
exe.linkLibC();
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
}
{
const spectest_modules = all_modules;
const exe = b.addExecutable(.{
.name = "spec_test",
.root_source_file = b.path("src/spec_test.zig"),
.target = target,
.optimize = optimize,
});
inline for (spectest_modules) |info| {
exe.root_module.addImport(info.name, info.module);
}
exe.linkLibC();
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("spectest", "Run the wasm spec tests");
run_step.dependOn(&run_cmd.step);
}
{
const unit_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const run_unit_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit tests");
inline for (all_modules) |info| {
const unit_test = b.addTest(.{
.root_source_file = b.path(info.path),
.target = target,
.optimize = optimize,
});
inline for (all_modules) |i| {
unit_test.root_module.addImport(i.name, i.module);
}
unit_test.linkLibC();
const run_unit_test = b.addRunArtifact(unit_test);
test_step.dependOn(&run_unit_test.step);
}
test_step.dependOn(&run_unit_tests.step);
}
}
const ModuleInfo = struct {
module: *std.Build.Module,
name: []const u8,
path: []const u8,
pub fn init(b: *std.Build, name: []const u8, path: []const u8, dependencies: []const ModuleInfo) ModuleInfo {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allcator = gpa.allocator();
defer _ = gpa.deinit();
const imports = allcator.alloc(std.Build.Module.Import, dependencies.len) catch {
std.debug.panic("allocation failed", .{});
};
defer _ = allcator.free(imports);
for (dependencies, 0..) |d, i| {
imports[i] = .{
.name = d.name,
.module = d.module,
};
}
const module = b.addModule(name, .{
.root_source_file = b.path(path),
.imports = imports,
});
return .{ .module = module, .name = name, .path = path };
}
};