Skip to content

Commit fb7e1d1

Browse files
authored
Merge branch 'main' into 2025-10-pkg-pr-releases
2 parents 5853140 + 032a15a commit fb7e1d1

35 files changed

+653
-511
lines changed

.config/cspell.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,22 @@
44
// language - current active spelling language
55
"language": "en",
66
// words - list of words to be always considered correct
7-
"words": ["tarides", "nixbuild", "stefanzweifel", "ACMRT", "Oxlint"],
7+
"words": [
8+
"ACMRT",
9+
"Iseconds",
10+
"merkletree",
11+
"nixbuild",
12+
"Oxlint",
13+
"sideloaded",
14+
"sideloading",
15+
"stefanzweifel",
16+
"tarides",
17+
"rimraf",
18+
"jsoo",
19+
"Eeuo",
20+
"caml",
21+
"esbuild"
22+
],
823
// flagWords - list of words to be always considered incorrect
924
// This is useful for offensive words and common spelling errors.
1025
// For example "hte" should be "the"

flake.lock

Lines changed: 22 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@
237237
root = ./.;
238238
fileset = unions [
239239
./src/mina
240+
./scripts
240241
./src/bindings/scripts
241242
./src/bindings/js
242243
./src/bindings/crypto
@@ -281,6 +282,7 @@
281282
patchPhase = ''
282283
patchShebangs ./src/bindings/scripts/
283284
patchShebangs ./src/bindings/crypto/test-vectors/
285+
patchShebangs ./scripts/
284286
'';
285287
buildPhase =
286288
''

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
"build:web": "./scripts/build/build-web.sh",
5858
"build:examples": "./scripts/build/build-examples.sh",
5959
"check:bindings": "./scripts/build/check-for-bindings.sh",
60+
"build:wasm": "npm run build:wasm:web && npm run build:wasm:node",
61+
"build:wasm:web": "./scripts/build/wasm/build-web.sh",
62+
"build:wasm:node": "./scripts/build/wasm/build-node.sh",
63+
"build:jsoo": "npm run build:jsoo:web && npm run build:jsoo:node",
64+
"build:jsoo:web": "./scripts/build/jsoo/build-web.sh",
65+
"build:jsoo:node": "./scripts/build/jsoo/build-node.sh",
6066
"build:docs": "typedoc",
6167
"prepublish:web": "./scripts/prepublish/prepublish-web.sh",
6268
"prepublish:node": "./scripts/prepublish/prepublish-node.sh",
@@ -70,6 +76,7 @@
7076
"format:md": "prettier --config .prettierrc.md.cjs --write '**/*.md'",
7177
"format:md:check": "prettier --config .prettierrc.md.cjs --check '**/*.md'",
7278
"clean": "./scripts/clean/clean.sh",
79+
"clean:artifacts": "./scripts/clean/clean-artifacts.sh",
7380
"clean:all": "./scripts/clean/clean-all.sh",
7481
"lint": "oxlint",
7582
"lint:fix": "oxlint --fix --fix-suggestions",

scripts/build/build-dev.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ npx tsc -p tsconfig.test.json
1515
ok "TypeScript compilation complete"
1616

1717
info "Copying artifacts to dist..."
18-
node src/build/copy-to-dist.js
18+
mkdir -p dist/node/bindings/compiled/node_bindings/
19+
cp -r src/bindings/compiled/node_bindings/* dist/node/bindings/compiled/node_bindings/
20+
cp src/bindings.d.ts dist/node/
1921
ok "Artifacts copied"
2022

2123
success "Development build complete"

scripts/build/jsoo/build-node.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
3+
set -Eeuo pipefail
4+
5+
source ./scripts/lib/ux.sh
6+
7+
JSOO_PATH=./src/bindings/ocaml/jsoo_exports/
8+
BUILT_PATH=./_build/default/$JSOO_PATH
9+
BINDINGS_PATH=./src/bindings/compiled/node_bindings/
10+
11+
setup_script "jsoo-build-node" "JSOO build node"
12+
13+
mkdir -p $BINDINGS_PATH
14+
15+
info "building JSOO artifacts for node..."
16+
TARGETS=(\
17+
o1js_node.bc.js \
18+
)
19+
dune build ${TARGETS[@]/#/$JSOO_PATH/}
20+
ok "JSOO artifacts built successfully"
21+
22+
info "copying artifacts into the right place..."
23+
for target in ${TARGETS[@]}; do
24+
cp $BUILT_PATH/$target $BINDINGS_PATH/$target
25+
chmod 660 $BINDINGS_PATH/$target
26+
done
27+
28+
info "setting up TS declaration files..."
29+
echo '// this file intentionally left blank' > $BINDINGS_PATH/o1js_node.bc.d.cts
30+
ok "TS declaration created"
31+
32+
info "moving some files to CommonJS format..."
33+
run_cmd mv -f $BINDINGS_PATH/o1js_node.bc.js $BINDINGS_PATH/o1js_node.bc.cjs
34+
ok "Node.js bindings copied"
35+
36+
info "Updating WASM references in bindings..."
37+
run_cmd sed -i 's/plonk_wasm.js/plonk_wasm.cjs/' $BINDINGS_PATH/o1js_node.bc.cjs
38+
ok "WASM references updated"
39+
40+
info "fixing JS bindings for better error handling..."
41+
run_cmd sed -i 's/function failwith(s){throw \[0,Failure,s\]/function failwith(s){throw globalThis.Error(s.c)/' "${BINDINGS_PATH}"/o1js_node.bc.cjs
42+
run_cmd sed -i 's/function invalid_arg(s){throw \[0,Invalid_argument,s\]/function invalid_arg(s){throw globalThis.Error(s.c)/' "${BINDINGS_PATH}"/o1js_node.bc.cjs
43+
run_cmd sed -i 's/return \[0,Exn,t\]/return globalThis.Error(t.c)/' "${BINDINGS_PATH}"/o1js_node.bc.cjs
44+
run_cmd sed -i 's/function raise(t){throw caml_call1(to_exn$0,t)}/function raise(t){throw Error(t?.[1]?.c ?? "Unknown error thrown by raise")}/' "${BINDINGS_PATH}"/o1js_node.bc.cjs
45+
ok "JS bindings fixed"
46+
47+
success "JSOO node build complete!"

scripts/build/jsoo/build-web.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
4+
source ./scripts/lib/ux.sh
5+
6+
JSOO_PATH=./src/bindings/ocaml/jsoo_exports/
7+
BUILT_PATH=./_build/default/$JSOO_PATH
8+
BINDINGS_PATH=./src/bindings/compiled/web_bindings/
9+
10+
setup_script "jsoo-build-web" "JSOO build web"
11+
12+
mkdir -p $BINDINGS_PATH
13+
14+
info "building JSOO artifacts for web..."
15+
TARGETS=(\
16+
o1js_web.bc.js\
17+
)
18+
dune build ${TARGETS[@]/#/$JSOO_PATH/}
19+
ok "initial artifacts built successfully!"
20+
21+
info "copying artifacts into the right place..."
22+
for target in ${TARGETS[@]}; do
23+
cp $BUILT_PATH/$target $BINDINGS_PATH/$target
24+
chmod 660 $BINDINGS_PATH/$target
25+
done
26+
27+
info "improving error messages in web bindings..."
28+
# Transform OCaml-style exceptions to JavaScript Error objects
29+
run_cmd sed -i 's/function failwith(s){throw \[0,Failure,s\]/function failwith(s){throw globalThis.Error(s.c)/' $BINDINGS_PATH/o1js_web.bc.js
30+
run_cmd sed -i 's/function invalid_arg(s){throw \[0,Invalid_argument,s\]/function invalid_arg(s){throw globalThis.Error(s.c)/' $BINDINGS_PATH/o1js_web.bc.js
31+
run_cmd sed -i 's/return \[0,Exn,t\]/return globalThis.Error(t.c)/' $BINDINGS_PATH/o1js_web.bc.js
32+
run_cmd sed -i 's/function raise(t){throw caml_call1(to_exn$0,t)}/function raise(t){throw Error(t?.[1]?.c ?? "Unknown error thrown by raise")}/' $BINDINGS_PATH/o1js_web.bc.js
33+
ok "error messages improved"
34+
35+
info "minifying JS with esbuild..."
36+
run_cmd npx esbuild --minify --log-level=error $BINDINGS_PATH/o1js_web.bc.js > $BINDINGS_PATH/o1js_web.bc.min.js
37+
run_cmd mv $BINDINGS_PATH/o1js_web.bc.min.js $BINDINGS_PATH/o1js_web.bc.js
38+
ok "JS minified"
39+
40+
success "JSOO artifacts built for web"

scripts/build/wasm/build-node.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
set -Eeuo pipefail
4+
5+
source ./scripts/lib/ux.sh
6+
7+
setup_script "wasm-node-build" "wasm node build"
8+
9+
MINA_PATH=./src/mina
10+
KIMCHI_PATH=$MINA_PATH/src/lib/crypto/kimchi_bindings/js/node_js/
11+
BUILT_PATH=./_build/default/$KIMCHI_PATH
12+
BINDINGS_PATH=./src/bindings/compiled/node_bindings/
13+
14+
mkdir -p $BINDINGS_PATH
15+
16+
info "building Kimchi bindings for node..."
17+
18+
TARGETS=(\
19+
plonk_wasm_bg.wasm \
20+
plonk_wasm_bg.wasm.d.ts \
21+
plonk_wasm.js \
22+
plonk_wasm.d.ts \
23+
)
24+
dune build ${TARGETS[@]/#/$KIMCHI_PATH/}
25+
26+
info "copying artifacts into the right place..."
27+
28+
for target in "${TARGETS[@]}"; do
29+
cp $BUILT_PATH/$target $BINDINGS_PATH/$target
30+
chmod 660 $BINDINGS_PATH/$target
31+
done
32+
33+
info "moving some files to CommonJS format..."
34+
35+
mv $BINDINGS_PATH/plonk_wasm.js $BINDINGS_PATH/plonk_wasm.cjs
36+
mv $BINDINGS_PATH/plonk_wasm.d.ts $BINDINGS_PATH/plonk_wasm.d.cts
37+
38+
info "autofixing wasm bindings for Node.JS..."
39+
run_cmd node src/build/fix-wasm-bindings-node.js $BINDINGS_PATH/plonk_wasm.cjs
40+
41+
success "WASM node build success!"

scripts/build/wasm/build-web.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
3+
set -Eeuo pipefail
4+
5+
source ./scripts/lib/ux.sh
6+
7+
setup_script "wasm-web-build" "wasm web build"
8+
9+
if ! command -v wasm-opt >/dev/null 2>&1; then
10+
error "wasm-opt is required for web bindings optimization"
11+
exit 1
12+
fi
13+
14+
MINA_PATH=./src/mina
15+
KIMCHI_PATH=$MINA_PATH/src/lib/crypto/kimchi_bindings/js/web/
16+
BUILT_PATH=./_build/default/$KIMCHI_PATH
17+
BINDINGS_PATH=./src/bindings/compiled/web_bindings/
18+
19+
mkdir -p $BINDINGS_PATH
20+
21+
22+
info "building Kimchi bindings for web..."
23+
24+
TARGETS=(\
25+
plonk_wasm_bg.wasm \
26+
plonk_wasm_bg.wasm.d.ts \
27+
plonk_wasm.js \
28+
plonk_wasm.d.ts\
29+
)
30+
dune build ${TARGETS[@]/#/$KIMCHI_PATH/}
31+
32+
info "copying artifacts into the right place..."
33+
34+
for target in "${TARGETS[@]}"; do
35+
cp $BUILT_PATH/$target $BINDINGS_PATH/$target
36+
done
37+
38+
info "optimizing wasm with wasm-opt..."
39+
run_cmd wasm-opt \
40+
--detect-features \
41+
--enable-mutable-globals \
42+
-O4 \
43+
-o $BINDINGS_PATH/plonk_wasm_bg.wasm.opt \
44+
$BINDINGS_PATH/plonk_wasm_bg.wasm
45+
run_cmd mv $BINDINGS_PATH/plonk_wasm_bg.wasm.opt $BINDINGS_PATH/plonk_wasm_bg.wasm
46+
47+
ok "wasm optimized"
48+
49+
chmod 660 ${TARGETS[@]/#/$BINDINGS_PATH/}
50+
51+
success "WASM web build success!"

0 commit comments

Comments
 (0)