-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
94 lines (85 loc) · 2.82 KB
/
build.zig
File metadata and controls
94 lines (85 loc) · 2.82 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
92
93
94
const std = @import("std");
pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const wasm_target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
.cpu_features_add = std.Target.wasm.featureSet(&.{.simd128}),
});
// --- zimdjson module (local patched copy) ---
const zimdjson = b.addModule("zimdjson", .{
.root_source_file = b.path("deps/zimdjson/src/zimdjson.zig"),
.target = wasm_target,
.optimize = optimize,
.strip = true,
.unwind_tables = .none,
});
// zimdjson needs build_options with enable_tracy and is_dev_mode
const build_options = b.addOptions();
build_options.addOption(bool, "enable_tracy", false);
build_options.addOption(bool, "is_dev_mode", false);
zimdjson.addImport("build_options", build_options.createModule());
// --- Main WASM engine library ---
const engine = b.addExecutable(.{
.name = "engine",
.root_module = b.createModule(.{
.root_source_file = b.path("src/zig/main.zig"),
.target = wasm_target,
.optimize = optimize,
.strip = true,
.unwind_tables = .none,
}),
});
engine.root_module.addImport("zimdjson", zimdjson);
// WASM-specific settings
engine.entry = .disabled;
engine.rdynamic = true;
engine.root_module.export_symbol_names = &.{
"alloc",
"dealloc",
// Document slot exports (tape-direct navigation)
"doc_parse",
"doc_free",
"doc_get_tag",
"doc_get_number",
"doc_read_string_raw",
"doc_get_count",
"doc_get_src_pos",
"doc_get_close_index",
"doc_find_field",
"doc_get_input_ptr",
"doc_batch_ptr",
"doc_array_elements",
"doc_object_keys",
// Streaming parser
"stream_create",
"stream_destroy",
"stream_feed",
"stream_get_status",
"stream_get_buffer_ptr",
"stream_get_value_len",
"stream_get_remaining_ptr",
"stream_get_remaining_len",
"stream_get_buffer_len",
"stream_reset_for_next",
// Tape export/import
"doc_export_tape_size",
"doc_export_tape",
"doc_import_tape",
// Deep comparison
"doc_deep_equal",
// Input classification & autocomplete
"classify_input",
"autocomplete_input",
"get_value_end",
// JSON5 support
"doc_parse_fmt",
// Error code
"get_error_code",
};
// Install to zig-out/bin/engine.wasm
b.installArtifact(engine);
// --- Copy to dist/ for convenience ---
const install_dist = b.addInstallFile(engine.getEmittedBin(), "../dist/engine.wasm");
b.getInstallStep().dependOn(&install_dist.step);
}