Skip to content

Commit

Permalink
refactor: use wasm-pack for builds
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszjasiuk committed Jul 7, 2023
1 parent d0a9da8 commit de7c15a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 19 deletions.
22 changes: 16 additions & 6 deletions packages/crypto/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,25 @@ zeroize = "1.6.0"
[dev-dependencies]
wasm-bindgen-test = "0.3.13"

# https://doc.rust-lang.org/cargo/reference/profiles.html
[profile.release]
lto = true
opt-level = "s"

[profile.dev]
# We do not wan't to make any optimizations for dev
opt-level = 0

# wasm-pack sepcific configuration
[package.metadata.wasm-pack.profile.release]
wasm-opt = true
# https://docs.rs/wasm-opt/latest/wasm_opt/
wasm-opt = ['-O4']

[package.metadata.wasm-pack.profile.dev]
wasm-opt = false

[profile.release]
lto = true
opt-level = "s"
[package.metadata.wasm-pack.profile.dev.wasm-bindgen]
omit-default-module-path = true

[profile.dev]
opt-level = "s"
[package.metadata.wasm-pack.profile.release.wasm-bindgen]
omit-default-module-path = true
2 changes: 1 addition & 1 deletion packages/crypto/scripts/build-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd -P)

wasm-pack build $SCRIPT_DIR/../lib --target nodejs --out-dir $SCRIPT_DIR/../src/crypto
wasm-pack build $SCRIPT_DIR/../lib --dev --target nodejs --out-dir $SCRIPT_DIR/../src/crypto
6 changes: 4 additions & 2 deletions packages/crypto/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd -P)

path=""
profile=""

if [ "$1" = "" ]
then
echo "Building \"crypto\" in dev mode."
profile="--dev"
path="debug"
elif [ "$1" = "--release" ]
then
echo "Building \"crypto\" in release mode."
profile="--release"
path="release"
else
echo "Unsupported build mode \"$1\""
exit 1
fi

cd $SCRIPT_DIR/../lib; cargo build --target wasm32-unknown-unknown ${1} $features
wasm-bindgen --out-dir=$SCRIPT_DIR/../src/crypto --target=web --omit-default-module-path target/wasm32-unknown-unknown/$path/crypto.wasm
wasm-pack build $SCRIPT_DIR/../lib $profile --target web --out-dir $SCRIPT_DIR/../src/crypto
23 changes: 16 additions & 7 deletions packages/shared/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,25 @@ borsh-derive = {git = "https://github.com/heliaxdev/borsh-rs.git", rev = "cd5223
borsh-derive-internal = {git = "https://github.com/heliaxdev/borsh-rs.git", rev = "cd5223e5103c4f139e0c54cf8259b7ec5ec4073a"}
borsh-schema-derive-internal = {git = "https://github.com/heliaxdev/borsh-rs.git", rev = "cd5223e5103c4f139e0c54cf8259b7ec5ec4073a"}

# https://doc.rust-lang.org/cargo/reference/profiles.html
[profile.release]
lto = true
opt-level = "s"

[profile.dev]
# We do not wan't to make any optimizations for dev
opt-level = 0

# wasm-pack sepcific configuration
[package.metadata.wasm-pack.profile.release]
wasm-opt = true
# https://docs.rs/wasm-opt/latest/wasm_opt/
wasm-opt = ['-O4']

[package.metadata.wasm-pack.profile.dev]
wasm-opt = false

[profile.release]
lto = true
opt-level = "s"
[package.metadata.wasm-pack.profile.dev.wasm-bindgen]
omit-default-module-path = true

[profile.dev]
# TODO: we can experiment with optimization levels
opt-level = "s"
[package.metadata.wasm-pack.profile.release.wasm-bindgen]
omit-default-module-path = true
2 changes: 1 addition & 1 deletion packages/shared/scripts/build-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd -P)

wasm-pack build $SCRIPT_DIR/../lib --target nodejs --out-dir $SCRIPT_DIR/../src/shared
wasm-pack build $SCRIPT_DIR/../lib --dev --target nodejs --out-dir $SCRIPT_DIR/../src/shared
6 changes: 4 additions & 2 deletions packages/shared/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd -P)

features=""
path=""
profile=""

if [ "$1" = "" ]
then
echo "Building \"shared\" in dev mode."
profile="--dev"
features="--features dev"
path="debug"
elif [ "$1" = "--release" ]
then
echo "Building \"shared\" in release mode."
profile="--release"
path="release"
else
echo "Unsupported build mode \"$1\""
exit 1
fi

cd $SCRIPT_DIR/../lib; cargo build --target wasm32-unknown-unknown ${1} $features
wasm-bindgen --out-dir=$SCRIPT_DIR/../src/shared --target=web --omit-default-module-path target/wasm32-unknown-unknown/$path/shared.wasm
wasm-pack build $SCRIPT_DIR/../lib $profile --target web --out-dir $SCRIPT_DIR/../src/shared -- $features

0 comments on commit de7c15a

Please sign in to comment.