-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.zig
More file actions
91 lines (75 loc) · 3.41 KB
/
build.zig
File metadata and controls
91 lines (75 loc) · 3.41 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
79
80
81
82
83
84
85
86
87
88
89
90
91
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,
});
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")) {
const exe_name = entry.name[0 .. entry.name.len - 4];
const exe_path = try std.fmt.allocPrint(b.allocator, "examples/{s}", .{entry.name});
const example_exe = b.addExecutable(.{
.name = exe_name,
.root_module = b.createModule(.{
.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_module = b.createModule(.{
.root_source_file = b.path("src/wasmer.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
wasmer_unit_tests.root_module.addLibraryPath(.{ .cwd_relative = wasmer_lib_dir_path });
wasmer_unit_tests.root_module.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_obj = b.addObject(.{
.name = "wasmer",
.root_module = b.createModule(.{
.root_source_file = b.path("src/wasmer.zig"),
.target = target,
.optimize = optimize,
}),
});
const docs = b.addInstallDirectory(.{
.source_dir = docs_obj.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
docs_step.dependOn(&docs.step);
}