-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.zig
90 lines (72 loc) · 3.34 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
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const wasmer_dir_path = try std.process.getEnvVarOwned(b.allocator, "WASMER_DIR");
const wasmer_lib_dir_path = b.pathJoin(&.{ wasmer_dir_path, "lib" });
const build_examples_option = b.option(bool, "examples", "Build example files") orelse false;
const run_step = b.step("run", "Run the app");
const wasmer_module = b.addModule("wasmer", .{
.root_source_file = b.path("src/wasmer.zig"),
.target = target,
.optimize = optimize,
});
const wasmer_lib = b.addStaticLibrary(.{
.name = "wasmer",
.root_source_file = b.path("src/wasmer.zig"),
.target = target,
.optimize = optimize,
});
if (build_examples_option) {
var examples_dir = try std.fs.cwd().openDir("examples", .{ .iterate = true });
defer examples_dir.close();
var examples_dir_iter = examples_dir.iterate();
while (try examples_dir_iter.next()) |entry| {
if (entry.kind == .file and std.mem.endsWith(u8, entry.name, ".zig")) {
var buffer_exe_path = std.ArrayList(u8).init(b.allocator);
const exe_name = entry.name[0 .. entry.name.len - 4];
try buffer_exe_path.appendSlice("examples/");
try buffer_exe_path.appendSlice(entry.name);
const exe_path = try buffer_exe_path.toOwnedSlice();
const example_exe = b.addExecutable(.{
.name = exe_name,
.root_source_file = b.path(exe_path),
.target = target,
.optimize = optimize,
.link_libc = true,
});
example_exe.root_module.addImport("wasmer", wasmer_module);
example_exe.root_module.addLibraryPath(.{ .cwd_relative = wasmer_lib_dir_path });
example_exe.root_module.linkSystemLibrary("wasmer", .{});
b.installArtifact(example_exe);
const run_example_cmd = b.addRunArtifact(example_exe);
run_example_cmd.step.dependOn(b.getInstallStep());
run_step.dependOn(&run_example_cmd.step);
}
}
}
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const wasmer_unit_tests = b.addTest(.{
.root_source_file = b.path("src/wasmer.zig"),
.target = target,
.optimize = optimize,
});
wasmer_unit_tests.linkLibC();
wasmer_unit_tests.addLibraryPath(.{ .cwd_relative = wasmer_lib_dir_path });
wasmer_unit_tests.linkSystemLibrary("wasmer");
const run_wasmer_unit_tests = b.addRunArtifact(wasmer_unit_tests);
// Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_wasmer_unit_tests.step);
// Build docs
const docs_step = b.step("docs", "Emit docs");
const docs = b.addInstallDirectory(.{
.source_dir = wasmer_lib.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
docs_step.dependOn(&docs.step);
}