Skip to content

Commit

Permalink
fix: patch memory issues with wasm bundle and nodejs target. (zkondui…
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-crypto authored Aug 21, 2023
1 parent a8dae9a commit 0fcbca7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .cargo/config
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[target.wasm32-unknown-unknown]
runner = 'wasm-bindgen-test-runner'
rustflags = ["-C", "target-feature=+atomics,+bulk-memory,+mutable-globals"]
rustflags = ["-C", "target-feature=+atomics,+bulk-memory,+mutable-globals","-C",
"link-arg=--max-memory=4294967296"]
34 changes: 28 additions & 6 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ jobs:

- name: Build wasm files for both web and nodejs compilation targets
run: |
wasm-pack build --target web . -- -Z build-std="panic_abort,std" --features web
wasm-pack build --target nodejs --out-dir ./pkg/nodejs . -- -Z build-std="panic_abort,std"
wasm-pack build --target web --out-dir ./pkg/web . -- -Z build-std="panic_abort,std" --features web
- name: Create package.json in pkg folder
shell: bash
env:
Expand All @@ -42,24 +43,45 @@ jobs:
"name": "@ezkljs/engine",
"version": "${{ github.ref_name }}",
"files": [
"ezkl_bg.wasm",
"nodejs/ezkl_bg.wasm",
"nodejs/ezkl.js",
"nodejs/ezkl.d.ts",
"web/ezkl_bg.wasm",
"web/ezkl.js",
"web/ezkl.d.ts",
"web/snippets/wasm-bindgen-rayon-7afa899f36665473/src/workerHelpers.js",
"ezkl.js",
"ezkl.d.ts",
"snippets/wasm-bindgen-rayon-7afa899f36665473/src/workerHelpers.js"
"ezkl.d.ts"
],
"main": "ezkl.js",
"types": "ezkl.d.ts",
"sideEffects": [
"./snippets/*"
"web/snippets/*"
]
}' > pkg/package.json
- name: Create ezkl.js in pkg folder
run: |
echo "import * as nodejsFunctions from './nodejs/ezkl.js';" >> pkg/ezkl.js
echo "import * as webFunctions from './web/ezkl.js';" >> pkg/ezkl.js
echo "export const nodejs = nodejsFunctions;" >> pkg/ezkl.js
echo "export const web = webFunctions;" >> pkg/ezkl.js
- name: Create ezkl.d.ts in pkg folder
run: |
echo "export const nodejs: typeof import('./nodejs/ezkl');" >> pkg/ezkl.d.ts
echo "export const web: typeof import('./web/ezkl');" >> pkg/ezkl.d.ts
- name: Replace memory definition in nodejs with definition in web
run: |
PATTERN=$(grep -o 'new WebAssembly.Memory({initial:[0-9]*,maximum:[0-9]*,shared:true})' pkg/web/ezkl.js)
sed -i "3s|imports\['env'\] = {memory:.*|imports\['env'\] = {memory: $PATTERN}|" pkg/nodejs/ezkl.js
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18.12.1'
registry-url: 'https://registry.npmjs.org'

- name: Publish to npm
run: |
cd pkg
Expand Down

0 comments on commit 0fcbca7

Please sign in to comment.