Changes
5 changed files (+50/-0)
-
-
@@ -16,3 +16,4 @@ # configure, and activate the toolings easily.zig 0.14.0 dprint 0.49.0 bun 1.2.4
-
-
-
@@ -40,6 +40,20 @@ // Install include/sood.hconst install_header = b.addInstallFileWithDir(b.path("src/c.h"), .header, "sood.h"); b.getInstallStep().dependOn(&install_header.step); // Install WASM build. const wasm_step = b.step("wasm", "Build WebAssembly module"); const wasm = b.addExecutable(.{ .name = "sood", .root_source_file = b.path("src/wasm.zig"), .target = b.resolveTargetQuery(.{ .os_tag = .freestanding, .cpu_arch = .wasm32 }), .optimize = optimize, }); // These two options are somehow needed. // <https://ziggit.dev/t/build-wasm-using-zig-build-system-when-ther-is-no-entry-point-but-function-to-export/4364/3> wasm.rdynamic = true; wasm.entry = .disabled; wasm_step.dependOn(&b.addInstallArtifact(wasm, .{}).step); // Example (Zig) const example_zig_step = b.step("example-zig", "Build Zig example"); const example_zig = b.addExecutable(.{
-
-
-
@@ -33,5 +33,6 @@ },"plugins": [ "https://plugins.dprint.dev/exec-0.5.1.json@492414e39dea4dccc07b4af796d2f4efdb89e84bae2bd4e1e924c0cc050855bf", "https://plugins.dprint.dev/json-0.20.0.wasm", "https://plugins.dprint.dev/typescript-0.94.0.wasm", ], }
-
-
examples/basic.js (new)
-
@@ -0,0 +1,15 @@// Copyright 2025 Shota FUJI // // Licensed under the Zero-Clause BSD License or the Apache License, Version 2.0, at your option. // You may not use, copy, modify, or distribute this file except according to those terms. You can // find a copy of the Zero-Clause BSD License at LICENSES/0BSD.txt, and a copy of the Apache License, // Version 2.0 at LICENSES/Apache-2.0.txt. You may also obtain a copy of the Apache License, Version // 2.0 at <https://www.apache.org/licenses/LICENSE-2.0> // // SPDX-License-Identifier: 0BSD OR Apache-2.0 const wasm = Bun.file(new URL("../zig-out/bin/sood.wasm", import.meta.url)); const { instance } = await WebAssembly.instantiate(await wasm.arrayBuffer()); console.log(instance.exports.sood_add(1, 2));
-
-
src/wasm.zig (new)
-
@@ -0,0 +1,19 @@// Copyright 2025 Shota FUJI // // Licensed under the Zero-Clause BSD License or the Apache License, Version 2.0, at your option. // You may not use, copy, modify, or distribute this file except according to those terms. You can // find a copy of the Zero-Clause BSD License at LICENSES/0BSD.txt, and a copy of the Apache License, // Version 2.0 at LICENSES/Apache-2.0.txt. You may also obtain a copy of the Apache License, Version // 2.0 at <https://www.apache.org/licenses/LICENSE-2.0> // // SPDX-License-Identifier: 0BSD OR Apache-2.0 // // === // // WebAssembly API. const sood = @import("lib.zig"); export fn sood_add(a: i32, b: i32) i32 { return sood.add(a, b); }
-