Build via xargo (#136)
* Build via xargo * xargo as dev dep * Install xargo explicitly * Fix binaryen dep * Update deps * Remove unused wasm-pack section * Uname
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -7,6 +7,8 @@ node_modules/
|
||||
pkg/
|
||||
target/
|
||||
tmp/
|
||||
wabt/
|
||||
wasm-bindgen/
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
Changes:
|
||||
|
||||
- Move to building via stable Rust, not nightly
|
||||
- Rework generation of WASM interfaces (proper cross-platform support)
|
||||
- Remove application of `getRandomValues` polyfill. Generally these should be supplied by the user.
|
||||
- Build via xargo for panic abort (Pinned nightly)
|
||||
|
||||
|
||||
## 1.4.1 Aug 27, 2020
|
||||
|
||||
1
packages/wasm-crypto/Cargo.lock
generated
1
packages/wasm-crypto/Cargo.lock
generated
@@ -657,7 +657,6 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
|
||||
name = "wasm"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"blake2-rfc",
|
||||
"byteorder",
|
||||
"ed25519-dalek",
|
||||
|
||||
@@ -15,7 +15,6 @@ version = "0.0.0"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
backtrace = "0.3.38"
|
||||
blake2-rfc = "0.2.18"
|
||||
byteorder = "1.3.1"
|
||||
ed25519-dalek = { version = "1.0.0-pre.4", features = [] }
|
||||
@@ -37,6 +36,10 @@ rand = { version = "0.7.3", features = ["wasm-bindgen"] }
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
debug = false
|
||||
debug-assertions = false
|
||||
incremental = false
|
||||
lto = true
|
||||
opt-level = "z"
|
||||
panic = "abort"
|
||||
rpath = false
|
||||
|
||||
2
packages/wasm-crypto/Xargo.toml
Normal file
2
packages/wasm-crypto/Xargo.toml
Normal file
@@ -0,0 +1,2 @@
|
||||
[dependencies]
|
||||
std = { default-features = false, features = ["panic_immediate_abort"] }
|
||||
@@ -5,6 +5,9 @@
|
||||
|
||||
set -e
|
||||
|
||||
# also change in install-build-deps
|
||||
RUST_VER=nightly-2020-10-25
|
||||
|
||||
WSM=pkg/wasm_bg.wasm
|
||||
OPT=pkg/wasm_opt.wasm
|
||||
ASM=build/wasm/asm.js
|
||||
@@ -25,11 +28,14 @@ cp src/wasm/* build/wasm/
|
||||
|
||||
# build new via wasm-pack
|
||||
echo "*** Building WASM output"
|
||||
wasm-pack build --release --scope polkadot --target web
|
||||
rustup run $RUST_VER xargo build --target wasm32-unknown-unknown --release
|
||||
../../wasm-bindgen/wasm-bindgen target/wasm32-unknown-unknown/release/wasm.wasm --out-dir pkg --target web
|
||||
# wasm-pack build --release --scope polkadot --target web
|
||||
|
||||
# optimise
|
||||
echo "*** Optimising WASM output"
|
||||
../../binaryen/bin/wasm-opt $WSM -Os -o $OPT
|
||||
# ../../wabt/bin/wasm-strip $WSM
|
||||
../../binaryen/wasm-opt $WSM -Os -o $OPT
|
||||
|
||||
# convert wasm to base64 structure
|
||||
echo "*** Packing WASM into baseX"
|
||||
@@ -37,7 +43,7 @@ node ../../scripts/pack-wasm-base.js
|
||||
|
||||
# build asmjs version from the input (optimised) WASM
|
||||
echo "*** Building asm.js version"
|
||||
../../binaryen/bin/wasm2js --output $ASM $OPT
|
||||
../../binaryen/wasm2js --output $ASM $OPT
|
||||
|
||||
# cleanup the generated asm, converting to cjs
|
||||
sed -i -e '/import {/d' $ASM
|
||||
|
||||
@@ -5,45 +5,62 @@
|
||||
|
||||
set -e
|
||||
|
||||
# wasm2js for wasm -> asm.js
|
||||
BINARYEN=( "wasm-opt" "wasm2js" )
|
||||
# also change in build-package
|
||||
RUST_VER=nightly-2020-10-25
|
||||
|
||||
BINARYEN_REPO=https://github.com/WebAssembly/binaryen
|
||||
BINARYEN_VER=version_97
|
||||
BINARYEN_ZIP=
|
||||
|
||||
BINDGEN_REPO=https://github.com/rustwasm/wasm-bindgen
|
||||
BINDGEN_VER=0.2.65
|
||||
BINDGEN_ZIP=
|
||||
|
||||
WABT_REPO=https://github.com/WebAssembly/wabt
|
||||
WABT_VER=1.0.19
|
||||
WABT_ZIP=
|
||||
|
||||
unamestr=`uname`
|
||||
|
||||
rustup toolchain install stable
|
||||
# toolchain with rust-src (for panic overrdides) and the right wasm32 toolchain
|
||||
rustup toolchain install $RUST_VER -c rust-src -t wasm32-unknown-unknown
|
||||
cargo install xargo
|
||||
|
||||
# install wasm-pack as required
|
||||
if ! [ -x "$(command -v wasm-pack)" ]; then
|
||||
echo "*** Installing wasm-pack"
|
||||
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
||||
fi
|
||||
# if ! [ -x "$(command -v wasm-pack)" ]; then
|
||||
# echo "*** Installing wasm-pack"
|
||||
# curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
||||
# fi
|
||||
|
||||
# CI, Linux
|
||||
if [[ "$unamestr" == 'Linux' ]]; then
|
||||
if [ ! -d "binaryen" ]; then
|
||||
echo "*** Downloading binaryen"
|
||||
curl -L https://github.com/WebAssembly/binaryen/releases/download/version_91/binaryen-version_91-x86-linux.tar.gz | tar xz
|
||||
mkdir -p binaryen/bin
|
||||
|
||||
for BIN in "${BINARYEN[@]}"; do
|
||||
mv binaryen-version_91/$BIN binaryen/bin
|
||||
done
|
||||
fi
|
||||
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
|
||||
# install binaryen as required
|
||||
if [ ! -d "binaryen" ]; then
|
||||
echo "*** Cloning binaryen"
|
||||
git clone --recursive https://github.com/WebAssembly/binaryen.git
|
||||
rm -rf binaryen/test
|
||||
fi
|
||||
|
||||
for BIN in "${BINARYEN[@]}"; do
|
||||
if [ ! -f "binaryen/bin/$BIN" ]; then
|
||||
echo "*** Building $BIN"
|
||||
cd binaryen
|
||||
cmake . && make $BIN
|
||||
cd ..
|
||||
fi
|
||||
done
|
||||
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/bin binaryen
|
||||
rm -rf binaryen-$BINARYEN_VER
|
||||
fi
|
||||
|
||||
if [ ! -d "wasm-bindgen" ]; then
|
||||
echo "*** Downloading wasm-bindgen"
|
||||
curl -L $BINDGEN_REPO/releases/download/$BINDGEN_VER/$BINDGEN_ZIP.tar.gz | tar xz
|
||||
mv $BINDGEN_ZIP wasm-bindgen
|
||||
fi
|
||||
|
||||
# if [ ! -d "wabt" ]; then
|
||||
# echo "*** Downloading wabt"
|
||||
# curl -L $WABT_REPO/releases/download/$WABT_VER/$WABT_ZIP.tar.gz | tar xz
|
||||
# mv wabt-$WABT_VER wabt
|
||||
# fi
|
||||
|
||||
Reference in New Issue
Block a user