Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
60 lines (52 loc) · 2.71 KB
/
Copy pathbuild.zig
File metadata and controls
60 lines (52 loc) · 2.71 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
const std = @import("std");
pub const napi_build = @import("src/build/napi-build.zig");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const napi_sys = b.addModule("napi_sys", .{
.root_source_file = b.path("src/sys/api.zig"),
});
const napi = b.addModule("napi", .{
.root_source_file = b.path("src/napi.zig"),
});
const build_options = b.addModule("build_options", .{
.root_source_file = b.path("src/build/options.zig"),
});
napi.addImport("napi-sys", napi_sys);
napi.addImport("build_options", build_options);
napi_sys.addImport("build_options", build_options);
napi_sys.addImport("ohos", napi_build.createOhosBindings(b, b.path("src/sys/ohos/native_api.h"), target, optimize, .{}));
napi.addIncludePath(b.path("src/sys/ohos"));
napi_sys.addIncludePath(b.path("src/sys/ohos"));
// Importing a Zig module does not instantiate its generic entrypoints.
// Keep an explicit host-addon check and a runnable test target for maintainers.
const check = b.step("check", "Compile the host Node addons and public API regression fixtures");
const compile_check = b.addSystemCommand(&.{ b.graph.zig_exe, "build", b.fmt("-Doptimize={s}", .{@tagName(optimize)}), "--summary", "failures" });
compile_check.setCwd(b.path("node-test"));
check.dependOn(&compile_check.step);
b.default_step.dependOn(&compile_check.step);
const test_step = b.step("test", "Run Zig unit tests and the host Node regression suite");
const node_tests = b.addSystemCommand(&.{ "npm", "run", "test:run" });
node_tests.setCwd(b.path("node-test"));
node_tests.step.dependOn(&compile_check.step);
test_step.dependOn(&node_tests.step);
const test_options = b.addOptions();
test_options.addOption(bool, "node_addon", true);
test_options.addOption(bool, "napi_tsgen", false);
test_options.addOption(i32, "napi_version", 8);
test_options.addOption(bool, "napi_experimental", false);
const unit_options = test_options.createModule();
const unit_sys = b.createModule(.{ .root_source_file = b.path("src/sys/api.zig") });
unit_sys.addImport("build_options", unit_options);
const unit_root = b.createModule(.{
.root_source_file = b.path("src/unit_tests.zig"),
.target = b.graph.host,
.optimize = optimize,
});
unit_root.addImport("napi-sys", unit_sys);
unit_root.addImport("build_options", unit_options);
const unit_tests = b.addTest(.{ .root_module = unit_root });
const run_units = b.addRunArtifact(unit_tests);
test_step.dependOn(&run_units.step);
b.step("test-unit", "Run the Zig unit tests").dependOn(&run_units.step);
}