-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.zig
47 lines (40 loc) · 1.71 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
const std = @import("std");
const builtin = @import("builtin");
const pkgs = @import("deps.zig").pkgs;
pub fn build(b: *std.build.Builder) !void {
const mode = b.standardReleaseOptions();
const lib = b.addStaticLibrary("wasmtime-zig", "src/main.zig");
lib.setBuildMode(mode);
lib.addPackage(pkgs.wasm);
lib.install();
var main_tests = b.addTest("src/main.zig");
main_tests.setBuildMode(mode);
main_tests.addPackage(pkgs.wasm);
main_tests.step.dependOn(b.getInstallStep());
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);
const example = b.option([]const u8, "example", "The example to run from the examples/ folder");
const example_path = example_path: {
const basename = example orelse "simple";
const with_ext = try std.fmt.allocPrint(b.allocator, "{s}.zig", .{basename});
const full_path = try std.fs.path.join(b.allocator, &[_][]const u8{ "examples", with_ext });
break :example_path full_path;
};
const simple_exe = b.addExecutable(example orelse "simple", example_path);
simple_exe.setBuildMode(mode);
simple_exe.addPackage(.{
.name = "wasmtime",
.path = "src/main.zig",
.dependencies = &.{pkgs.wasm},
});
if (builtin.os.tag == .windows) {
simple_exe.linkSystemLibrary("wasmtime.dll");
} else {
simple_exe.linkSystemLibrary("wasmtime");
}
simple_exe.linkLibC();
simple_exe.step.dependOn(b.getInstallStep());
const run_simple_cmd = simple_exe.run();
const run_simple_step = b.step("run", "Runs an example. If no -Dexample arg is provided, the simple example will be ran");
run_simple_step.dependOn(&run_simple_cmd.step);
}