mirror of
https://github.com/pezkuwichain/pezkuwi-wasm.git
synced 2026-04-22 02:08:00 +00:00
feat: add all @pezkuwi/wasm-crypto packages with bizinikiwi context
This commit is contained in:
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2019-2025 @polkadot/wasm authors & contributors
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
set -e
|
||||
|
||||
yarn polkadot-dev-clean-build
|
||||
yarn polkadot-dev-build-ts
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2019-2025 @polkadot/wasm authors & contributors
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
set -e
|
||||
|
||||
source ../scripts/rust-version.sh
|
||||
|
||||
WSM=$PKG_NAME/build-wasm/wasm_bg.wasm
|
||||
OPT=$PKG_NAME/build-wasm/wasm_opt.wasm
|
||||
ASM=$PKG_NAME-asmjs/build/cjs/data.js
|
||||
DENO_DIR=$PKG_NAME-asmjs/build-deno/deno
|
||||
DENO_ASM=$DENO_DIR/data.js
|
||||
|
||||
# build new via wasm-pack
|
||||
echo "*** Building Rust sources"
|
||||
cd $PKG_NAME
|
||||
if [ "$RUST_VER" == "stable" ]; then
|
||||
RUSTC_BOOTSTRAP=1 cargo build --target wasm32-unknown-unknown --release -Z build-std=std,panic_abort
|
||||
else
|
||||
rustup run $RUST_VER xargo build --target wasm32-unknown-unknown --release --locked
|
||||
fi
|
||||
cd ..
|
||||
|
||||
echo "*** Converting to WASM"
|
||||
# Use system wasm-bindgen (installed via cargo)
|
||||
wasm-bindgen $PKG_NAME/target/wasm32-unknown-unknown/release/wasm.wasm --out-dir $PKG_NAME/build-wasm --target web
|
||||
|
||||
# optimise using system wasm-opt
|
||||
echo "*** Optimising WASM output"
|
||||
wasm-opt $WSM -Oz -o $OPT
|
||||
|
||||
# convert wasm to base64 structure
|
||||
echo "*** Packing WASM into baseX"
|
||||
node ../scripts/pack-wasm-base.mjs
|
||||
|
||||
# build asmjs version from the input (optimised) WASM
|
||||
echo "*** Building asm.js version"
|
||||
# Use system wasm2js
|
||||
wasm2js -Oz --output $ASM $OPT
|
||||
|
||||
# copy the deno version
|
||||
mkdir -p $DENO_DIR
|
||||
cp $ASM $DENO_ASM
|
||||
|
||||
# cleanup the generated asm, converting to cjs
|
||||
sed -i -e '/import {/d' $ASM
|
||||
sed -i -e '1,/var retasmFunc = /!d' $ASM
|
||||
sed -i -e 's/var retasmFunc = .*/exports.asmJsInit = (wbg) => asmFunc(wbg);/g' $ASM
|
||||
|
||||
# same as the cjs version, this time for deno
|
||||
sed -i -e '/import {/d' $DENO_ASM
|
||||
sed -i -e '1,/var retasmFunc = /!d' $DENO_ASM
|
||||
sed -i -e 's/var retasmFunc = .*/export const asmJsInit = (wbg) => asmFunc(wbg);/g' $DENO_ASM
|
||||
|
||||
# cleanups
|
||||
rm -rf $PKG_NAME-asmjs/build/cjs/*-e
|
||||
rm -rf $PKG_NAME-asmjs/build-deno/deno/*-e
|
||||
rm -rf $PKG_NAME-wasm/build/cjs/*-e
|
||||
rm -rf $PKG_NAME-wasm/build-deno/deno/*-e
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2019-2025 @polkadot/wasm authors & contributors
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
set -e
|
||||
|
||||
echo "*** Building JavaScript"
|
||||
./scripts/build-js.sh
|
||||
|
||||
echo "*** Building WASM"
|
||||
cd packages
|
||||
|
||||
unamestr=`uname`
|
||||
|
||||
# For Mac we set extra paths for clang
|
||||
if [[ "$unamestr" == "Darwin" ]]; then
|
||||
if [ ! -f "/opt/homebrew/opt/llvm/bin/clang" ]; then
|
||||
echo "FATAL: Ensure you have clang installed via homebrew"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PATH="/opt/homebrew/opt/llvm/bin:$PATH" CC=/opt/homebrew/opt/llvm/bin/clang AR=/opt/homebrew/opt/llvm/bin/llvm-ar PKG_NAME=wasm-crypto ../scripts/build-wasm.sh
|
||||
else
|
||||
PKG_NAME=wasm-crypto ../scripts/build-wasm.sh
|
||||
fi
|
||||
|
||||
if [ -z "$WITH_DENO" ]; then
|
||||
yarn test:wasm-crypto:js
|
||||
else
|
||||
yarn test:wasm-crypto:deno
|
||||
fi
|
||||
|
||||
# echo ""
|
||||
# echo "*** wasm-crypto"
|
||||
# ls -alR wasm-crypto/build
|
||||
# echo ""
|
||||
# echo "*** wasm-crypto-asmjs"
|
||||
# ls -alR wasm-crypto-asmjs/build
|
||||
# echo ""
|
||||
# echo "*** wasm-crypto-wasm"
|
||||
# ls -alR wasm-crypto-wasm/build
|
||||
|
||||
cd ..
|
||||
|
||||
if [ -z "$WITH_DENO" ]; then
|
||||
yarn build:rollup
|
||||
fi
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2019-2025 @polkadot/wasm authors & contributors
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
set -e
|
||||
|
||||
yarn polkadot-dev-clean-build
|
||||
|
||||
cd packages/wasm-crypto
|
||||
cargo clean
|
||||
cd ../..
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2019-2025 @polkadot/wasm authors & contributors
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
set -e
|
||||
|
||||
source ./scripts/rust-version.sh
|
||||
|
||||
# NOTE If this is bumped, bump the version in Cargo.toml as well
|
||||
BINDGEN_REPO=https://github.com/rustwasm/wasm-bindgen
|
||||
BINDGEN_VER=0.2.79
|
||||
BINDGEN_ZIP=
|
||||
|
||||
|
||||
|
||||
|
||||
BINARYEN_REPO=https://github.com/WebAssembly/binaryen
|
||||
BINARYEN_VER=version_105
|
||||
BINARYEN_ZIP=
|
||||
|
||||
WABT_REPO=https://github.com/WebAssembly/wabt
|
||||
WABT_VER=1.0.27
|
||||
WABT_ZIP=
|
||||
|
||||
unamestr=`uname`
|
||||
|
||||
# toolchain with rust-src (for panic overrdides) and the right wasm32 toolchain
|
||||
rustup toolchain install $RUST_VER -c rust-src -t wasm32-unknown-unknown
|
||||
rustup default $RUST_VER
|
||||
|
||||
if [ "$RUST_VER" != "stable" ]; then
|
||||
cargo install xargo
|
||||
fi
|
||||
|
||||
if [[ "$unamestr" == 'Linux' ]]; then
|
||||
echo "*** Detected Linux"
|
||||
BINARYEN_ZIP=binaryen-$BINARYEN_VER-x86_64-linux
|
||||
BINDGEN_ZIP=wasm-bindgen-$BINDGEN_VER-x86_64-unknown-linux-musl
|
||||
WABT_ZIP=wabt-$WABT_VER-ubuntu
|
||||
elif [[ "$unamestr" == "Darwin" ]]; then
|
||||
echo "*** Detected Mac"
|
||||
BINARYEN_ZIP=binaryen-$BINARYEN_VER-x86_64-macos
|
||||
BINDGEN_ZIP=wasm-bindgen-$BINDGEN_VER-x86_64-apple-darwin
|
||||
WABT_ZIP=wabt-$WABT_VER-macos
|
||||
else
|
||||
echo "*** Unknown platform $unamestr, unable to install wasm helper binaries"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -d "binaryen" ]; then
|
||||
echo "*** Downloading binaryen"
|
||||
curl -L $BINARYEN_REPO/releases/download/$BINARYEN_VER/$BINARYEN_ZIP.tar.gz | tar xz
|
||||
mv binaryen-$BINARYEN_VER binaryen
|
||||
# ls -alR binaryen
|
||||
fi
|
||||
|
||||
if [ ! -d "bindgen" ]; then
|
||||
echo "*** Downloading bindgen"
|
||||
curl -L $BINDGEN_REPO/releases/download/$BINDGEN_VER/$BINDGEN_ZIP.tar.gz | tar xz
|
||||
mv $BINDGEN_ZIP bindgen
|
||||
# ls -alR bindgen
|
||||
fi
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
// Copyright 2019-2025 @pezkuwi/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { zlibSync } from 'fflate/node';
|
||||
import fs from 'node:fs';
|
||||
|
||||
import { formatNumber } from '@pezkuwi/util';
|
||||
|
||||
const PKG_NAME = process.env['PKG_NAME'];
|
||||
const DIR_DENO = `./${PKG_NAME}-wasm/build-deno/deno`;
|
||||
const DIR_CJS = `./${PKG_NAME}-wasm/build/cjs`;
|
||||
const HDR = `// Copyright 2019-${new Date().getFullYear()} @polkadot/${PKG_NAME}-wasm authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\n// Generated as part of the build, do not edit\n`;
|
||||
|
||||
const data = fs.readFileSync(`./${PKG_NAME}/build-wasm/wasm_opt.wasm`);
|
||||
const compressed = Buffer.from(zlibSync(data, { level: 9 }));
|
||||
const base64 = compressed.toString('base64');
|
||||
|
||||
console.log(`*** Compressed WASM: in=${formatNumber(data.length)}, out=${formatNumber(compressed.length)}, opt=${(100 * compressed.length / data.length).toFixed(2)}%, base64=${formatNumber(base64.length)}`);
|
||||
|
||||
fs.mkdirSync(DIR_DENO, { recursive: true });
|
||||
|
||||
fs.writeFileSync(`${DIR_CJS}/bytes.js`, `${HDR}
|
||||
exports.lenIn = ${compressed.length};
|
||||
|
||||
exports.lenOut = ${data.length};
|
||||
|
||||
exports.bytes = '${base64}';
|
||||
`);
|
||||
|
||||
fs.writeFileSync(`${DIR_DENO}/bytes.js`, `${HDR}
|
||||
export const lenIn = ${compressed.length};
|
||||
|
||||
export const lenOut = ${data.length};
|
||||
|
||||
export const bytes = '${base64}';
|
||||
`);
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2019-2025 @polkadot/wasm authors & contributors
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
RUST_VER=nightly-2022-06-24
|
||||
Reference in New Issue
Block a user