Skip to content

Commit

Permalink
Merge #1934
Browse files Browse the repository at this point in the history
1934: Update zksync-crypto build to match wasm-pack r=Deniallugo a=slumber



Co-authored-by: Chris Sosnin <[email protected]>
  • Loading branch information
bors-matterlabs-dev[bot] and slumber authored Sep 28, 2021
2 parents 67aad0e + 179a87c commit f4f378c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sdk/binaryen
Submodule binaryen updated 824 files
17 changes: 12 additions & 5 deletions sdk/zksync-crypto/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

set -e

ASM=dist/zksync-crypto-bundler_bg_asm.js
BG_ASM=dist/zksync-crypto-bundler_bg_asm.js
ASM=dist/zksync-crypto-bundler_asm.js

which wasm-pack || cargo install wasm-pack

Expand All @@ -21,14 +22,20 @@ fi

# convert the bundler build into JS in case the environment doesn't support WebAssembly
../build_binaryen.sh
../binaryen/bin/wasm2js ./dist/zksync-crypto-bundler_bg.wasm -o $ASM
../binaryen/bin/wasm2js ./dist/zksync-crypto-bundler_bg.wasm -o $BG_ASM

# save another copy for bg_asm import
cp ./dist/zksync-crypto-bundler.js ./dist/zksync-crypto-bundler_asm.js
# note that due to the behavior of wasm-pack we copy the different file:
# for a bundler build it extracts the content of .js file into _bg.js,
# we fix it ourselves
cp ./dist/zksync-crypto-bundler_bg.js $ASM

# fix imports for asm
sed -i.backup "s/^import.*/\
let wasm = require('.\/zksync-crypto-bundler_bg_asm.js');/" ./dist/zksync-crypto-bundler_asm.js
sed -i.backup "s/\.js/_asm\.js/g" $ASM
let wasm = require('.\/zksync-crypto-bundler_bg_asm.js');/" $ASM
sed -i.backup "s/\_bg.js/_asm\.js/g" $BG_ASM

rm dist/*.backup

# this is again related to how wasm-pack works
echo -e "\nwasm.__wbindgen_start();\n" >> $ASM
2 changes: 1 addition & 1 deletion sdk/zksync-crypto/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zksync-crypto",
"version": "0.6.1",
"version": "0.6.2",
"browser": "dist/zksync-crypto-web.js",
"main": "dist/zksync-crypto-node.js",
"files": [
Expand Down
3 changes: 2 additions & 1 deletion sdk/zksync-crypto/web-wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const brokenStrings = [
// This substring is unique, had to
// write only part of line to make the RegExp works.
// Probably will rewrite in the future
`input = import.meta.url.replace`
`input = import.meta.url.replace`,
`input = new URL`
];

let jsCode = fs.readFileSync(jsFile).toString();
Expand Down

0 comments on commit f4f378c

Please sign in to comment.