|
1 | | -const builtin = @import("builtin"); |
2 | 1 | const std = @import("std"); |
3 | | -const Builder = std.build.Builder; |
4 | | -const LibExeObjStep = std.build.LibExeObjStep; |
5 | | - |
6 | | -fn linkWasmtime(step: *LibExeObjStep, search_path: ?[]const u8) void { |
7 | | - if (builtin.os.tag == .windows) { |
8 | | - // On Windows, link dynamic library as otherwise lld will have a |
9 | | - // hard time satisfying `libwasmtime` deps |
10 | | - step.linkSystemLibrary("wasmtime.dll"); |
11 | | - } else { |
12 | | - step.linkSystemLibrary("wasmtime"); |
13 | | - } |
14 | | - if (search_path) |path| { |
15 | | - step.addLibPath(path); |
16 | | - } |
17 | | -} |
| 2 | +const builtin = @import("builtin"); |
| 3 | +const pkgs = @import("deps.zig").pkgs; |
18 | 4 |
|
19 | | -pub fn build(b: *Builder) !void { |
| 5 | +pub fn build(b: *std.build.Builder) !void { |
20 | 6 | const mode = b.standardReleaseOptions(); |
21 | 7 |
|
22 | | - const lib_path = b.option([]const u8, "library-search-path", "Add additional system library search path."); |
23 | | - |
24 | 8 | const lib = b.addStaticLibrary("wasmtime-zig", "src/main.zig"); |
25 | 9 | lib.setBuildMode(mode); |
| 10 | + lib.addPackage(pkgs.wasm); |
26 | 11 | lib.install(); |
27 | 12 |
|
28 | 13 | var main_tests = b.addTest("src/main.zig"); |
29 | 14 | main_tests.setBuildMode(mode); |
30 | | - linkWasmtime(main_tests, lib_path); |
| 15 | + main_tests.addPackage(pkgs.wasm); |
31 | 16 | main_tests.step.dependOn(b.getInstallStep()); |
32 | 17 |
|
33 | 18 | const test_step = b.step("test", "Run library tests"); |
34 | 19 | test_step.dependOn(&main_tests.step); |
35 | 20 |
|
36 | | - const example = b.option([]const u8, "example", "The example to run from the /example folder"); |
37 | | - const example_path = blk: { |
38 | | - const ex = example orelse "simple"; |
39 | | - |
40 | | - const path = try std.fs.path.join(b.allocator, &[_][]const u8{ "example", ex }); |
41 | | - break :blk try std.mem.concat(b.allocator, u8, &[_][]const u8{ path, ".zig" }); |
| 21 | + const example = b.option([]const u8, "example", "The example to run from the examples/ folder"); |
| 22 | + const example_path = example_path: { |
| 23 | + const basename = example orelse "simple"; |
| 24 | + const with_ext = try std.fmt.allocPrint(b.allocator, "{s}.zig", .{basename}); |
| 25 | + const full_path = try std.fs.path.join(b.allocator, &[_][]const u8{ "examples", with_ext }); |
| 26 | + break :example_path full_path; |
42 | 27 | }; |
43 | 28 |
|
44 | 29 | const simple_exe = b.addExecutable(example orelse "simple", example_path); |
45 | 30 | simple_exe.setBuildMode(mode); |
46 | | - simple_exe.addPackagePath("wasmtime", "src/main.zig"); |
| 31 | + simple_exe.addPackage(.{ |
| 32 | + .name = "wasmtime", |
| 33 | + .path = "src/main.zig", |
| 34 | + .dependencies = &.{pkgs.wasm}, |
| 35 | + }); |
| 36 | + if (builtin.os.tag == .windows) { |
| 37 | + simple_exe.linkSystemLibrary("wasmtime.dll"); |
| 38 | + } else { |
| 39 | + simple_exe.linkSystemLibrary("wasmtime"); |
| 40 | + } |
47 | 41 | simple_exe.linkLibC(); |
48 | | - linkWasmtime(simple_exe, lib_path); |
49 | 42 | simple_exe.step.dependOn(b.getInstallStep()); |
50 | 43 |
|
51 | 44 | const run_simple_cmd = simple_exe.run(); |
|
0 commit comments