Skip to content

Commit 7dfa940

Browse files
committed
wasm: support shared memory
1 parent b0bcd4d commit 7dfa940

4 files changed

Lines changed: 8 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- wasm32-freestanding
1919
runs-on: ubuntu-latest
2020
env:
21-
build: zig build -Dtarget=${{ matrix.target }} ${{ matrix.target == 'native' && '-fsys=wio' || '' }}
21+
build: zig build -Dtarget=${{ matrix.target }} ${{ matrix.target == 'wasm32-freestanding' && '-Dcpu=bleeding_edge' || '' }} ${{ matrix.target == 'native' && '-fsys=wio' || '' }}
2222
steps:
2323
- name: Checkout
2424
uses: actions/checkout@v6

demo/build.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ pub fn build(b: *std.Build) void {
4747
});
4848
b.installArtifact(exe);
4949

50+
if (target.result.cpu.arch.isWasm()) {
51+
exe.max_memory = 2 * 1024 * 1024;
52+
exe.shared_memory = true;
53+
}
54+
5055
const run_cmd = b.addRunArtifact(exe);
5156
run_cmd.step.dependOn(b.getInstallStep());
5257

demo/wasm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class GL {
1313
const array = new Uint8Array(wio.instance.exports.memory.buffer, ptr);
1414
let len = 0;
1515
while (array[len]) len++;
16-
return new TextDecoder().decode(array.subarray(0, len));
16+
return new TextDecoder().decode(array.slice(0, len));
1717
};
1818

1919
this.setStringZ = (ptr, max, length, string) => {

src/wasm/Wio.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Wio {
4242
}
4343

4444
getString(ptr, len) {
45-
return new TextDecoder().decode(new Uint8Array(this.instance.exports.memory.buffer, ptr, len));
45+
return new TextDecoder().decode(new Uint8Array(this.instance.exports.memory.buffer, ptr, len).slice());
4646
}
4747

4848
updateModifiers(data, event) {

0 commit comments

Comments
 (0)