Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,39 @@ pub fn build(b: *std.Build) void {
}
```

Zemscripten `build.zig` example:
```zig
pub fn build(b: *std.Build) void {
const target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
.os_tag = .emscripten,
});

const wasm = b.addLibrary(.{ .name = "zemscripten-build", .linkage = .static, .root_module = b.createModule(.{
.root_source_file = b.path("main.zig"),
.target = target,
.optimize = optimize,
}) });

// Add Emscripten include paths for @cImport
const emsdk_path = b.dependency("emsdk", .{}).path("").getPath(b);
const emscripten_include_path = b.pathJoin(&.{ emsdk_path, "upstream", "emscripten", "cache", "sysroot", "include" });
wasm.root_module.addSystemIncludePath(.{ .cwd_relative = emscripten_include_path });

const zemscripten = b.dependency("zemscripten", .{});
const zmesh = b.dependency("zmesh", .{
.target = target,
.optimize = optimize,
.emscripten_include_path = emscripten_include_path,
});

wasm.root_module.addImport("zmesh", zmesh.module("root"));
wasm.linkLibrary(zmesh.artifact("zmesh"));

...
}
```

Now in your code you may import and use `zmesh`:

```zig
Expand Down
14 changes: 14 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ pub fn build(b: *std.Build) void {
"shared",
"Build as shared library",
) orelse false,
.emscripten_include_path = b.option(
[]const u8,
"emscripten_include_path",
"Path to emscripten include directory for Emscripten builds",
),
};

const options_step = b.addOptions();
Expand Down Expand Up @@ -54,6 +59,15 @@ pub fn build(b: *std.Build) void {
if (target.result.abi != .msvc)
zmesh_lib.linkLibCpp();

// Add Emscripten sysroot include paths when building for emscripten target
if (target.result.os.tag == .emscripten) {
if (options.emscripten_include_path) |emscripten_include_path| {
zmesh_lib.addSystemIncludePath(.{ .cwd_relative = emscripten_include_path });
} else {
std.debug.panic("emscripten_include_path option must be provided when building for emscripten target\n", .{});
}
}

const par_shapes_t = if (options.shape_use_32bit_indices)
"-DPAR_SHAPES_T=uint32_t"
else
Expand Down