Skip to content

Commit 158234c

Browse files
authored
Merge pull request #269 from graphprotocol/pcv/migrate-to-wasm-bindgen
feat: migrate json-encoder-web from wasm-pack to direct wasm-bindgen
2 parents d2e921c + 01a74dd commit 158234c

7 files changed

Lines changed: 80 additions & 1040 deletions

File tree

.github/workflows/web-encoder.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ jobs:
2020
node-version: latest
2121
cache: "npm"
2222
cache-dependency-path: packages/json-encoder-web/package-lock.json
23+
- name: Install Rust
24+
uses: actions-rs/toolchain@v1
25+
with:
26+
toolchain: stable
27+
target: wasm32-unknown-unknown
28+
override: true
29+
- name: Install wasm-bindgen-cli
30+
run: cargo install wasm-bindgen-cli --version "0.2.100"
2331
- run: npm install
2432
working-directory: packages/json-encoder-web
2533
- run: npm run build
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build outputs
5+
dist/
6+
pkg/
7+
target/
8+
9+
# Logs
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
14+
# Editor directories and files
15+
.idea
16+
.vscode
17+
*.swp
18+
*.swo
19+
*~
20+
21+
# OS files
22+
.DS_Store
23+
Thumbs.db
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env node
2+
const { execSync } = require('child_process');
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
function buildWasm() {
7+
console.log('🔨 Building WASM module...');
8+
9+
// Clean previous build
10+
if (fs.existsSync('pkg')) {
11+
fs.rmSync('pkg', { recursive: true, force: true });
12+
}
13+
fs.mkdirSync('pkg');
14+
15+
try {
16+
// Compile Rust to WASM
17+
console.log('📦 Compiling Rust to WASM...');
18+
execSync('cargo build --target wasm32-unknown-unknown --release', {
19+
stdio: 'inherit'
20+
});
21+
22+
// Generate bindings
23+
console.log('🔗 Generating bindings...');
24+
execSync(`wasm-bindgen \
25+
target/wasm32-unknown-unknown/release/json_encoder_web.wasm \
26+
--out-dir pkg \
27+
--target bundler \
28+
--no-typescript`, {
29+
stdio: 'inherit'
30+
});
31+
32+
console.log('✅ WASM build complete!');
33+
} catch (error) {
34+
console.error('❌ Build failed:', error.message);
35+
process.exit(1);
36+
}
37+
}
38+
39+
// Run if called directly
40+
if (require.main === module) {
41+
buildWasm();
42+
}
43+
44+
module.exports = { buildWasm };

packages/json-encoder-web/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as wasm from './pkg';
1+
import * as wasm from './pkg/json_encoder_web';
22
import * as copy from 'copy-to-clipboard';
33
import notie from 'notie';
44
import { editor as monacoEditor } from 'monaco-editor/esm/vs/editor/editor.api'

0 commit comments

Comments
 (0)