Skip to content

Commit

Permalink
chore: speedup wasm dev build
Browse files Browse the repository at this point in the history
Here for wasm dev build I replace the `wasm-pack` which is nice, but behind its defaults it hides lots of useful stuff, and I call `cargo build`, `wasm-bindgen` and `wasm-opt` explicitly. Notably `wasm-pack` does not allow custom cargo profiles (rustwasm/wasm-pack#1111).

I also add the new "opt-dev" cargo profile, which is something in the middle between `release` and `dev` - a balance between rebuild speed and runtime performance. This should save lots of time during day-to-day work.

The production version still uses `wasm-pack` and a more tried solution.

The dev version now requires cargo wasm toolchain, `wasm-bindgen` and `wasm-opt` (from `binaryen` project) installed manually. Previously `wasm-pack` would handle that. The dev docker image was updated accordingly.
  • Loading branch information
ivan-aksamentov committed Oct 4, 2022
1 parent ade06e2 commit 1c3377b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,33 @@ opt-level = 3
[profile.dev.package.pretty_assertions]
opt-level = 3


[profile.opt-dev]
inherits = "dev"
codegen-units = 128
incremental = true
opt-level = 2
lto = "off"
panic = "abort"
strip = true

# Optimize dependencies even in debug mode
[profile.opt-dev.package."*"]
opt-level = 2
[profile.opt-dev.package.backtrace]
opt-level = 3
[profile.opt-dev.package.color-spantrace]
opt-level = 3
[profile.opt-dev.package.tracing]
opt-level = 3
[profile.opt-dev.package.tracing-error]
opt-level = 3
[profile.opt-dev.package.tracing-subscriber]
opt-level = 3
[profile.opt-dev.package.pretty_assertions]
opt-level = 3


[profile.release]
codegen-units = 1
incremental = false
Expand Down
5 changes: 5 additions & 0 deletions docker/docker-dev.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ RUN set -euxo pipefail >/dev/null \
&& curl -sSL "https://github.com/rustwasm/wasm-bindgen/releases/download/${WASM_BINDGEN_CLI_VERSION}/wasm-bindgen-${WASM_BINDGEN_CLI_VERSION}-x86_64-unknown-linux-musl.tar.gz" | tar -C "${CARGO_HOME}/bin" --strip-components=1 -xz "wasm-bindgen-${WASM_BINDGEN_CLI_VERSION}-x86_64-unknown-linux-musl/wasm-bindgen" \
&& chmod +x "${CARGO_HOME}/bin/wasm-bindgen"

RUN set -euxo pipefail >/dev/null \
&& export BINARYEN_VERSION="110" \
&& curl -sSL "https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz" | tar -C "${CARGO_HOME}/bin" --strip-components=2 -xz "binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt" \
&& chmod +x "${CARGO_HOME}/bin/wasm-opt"

# Install executable dependencies
RUN set -euxo pipefail >/dev/null \
&& cargo quickinstall cargo-audit \
Expand Down
2 changes: 1 addition & 1 deletion packages_rs/nextclade-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"monkey-patch": "bash tools/auspice-monkey-patch.sh && yarn run:node tools/monkeyPatch.ts",
"changelog": "yarn conventional-changelog -p angular -i CHANGELOG.md -s -r 1",
"serve-data": "babel-node --config-file \"./babel-node.config.js\" --extensions \".ts\" ./tools/server/dataServer.ts",
"wasm-dev": "wasm-pack --quiet --log-level=error build --dev --target=bundler --out-dir=.build/wasm-dev/ --out-name=nextclade-wasm -- --package=nextclade-web --locked && mkdir -p src/gen/ && cp .build/wasm-dev/* src/gen/",
"wasm-dev": "cargo build -q --profile=opt-dev --package=nextclade-web --lib --target=wasm32-unknown-unknown --target-dir=.build/docker/wasm-dev/ && wasm-bindgen .build/docker/wasm-dev/wasm32-unknown-unknown/opt-dev/nextclade_web.wasm --target=bundler --out-dir=.build/wasm-prod/ --out-name=nextclade-wasm && wasm-opt -O --optimize-level=1 --shrink-level=1 .build/docker/wasm-dev/wasm32-unknown-unknown/opt-dev/nextclade_web.wasm -o .build/wasm-prod/nextclade-wasm.wasm && mkdir -p src/gen/ && cp .build/wasm-prod/* src/gen/",
"wasm-prod": "wasm-pack --quiet --log-level=error build --release --target=bundler --out-dir=.build/wasm-prod/ --out-name=nextclade-wasm -- --package=nextclade-web --locked && mkdir -p src/gen/ && cp .build/wasm-prod/* src/gen/"
},
"dependencies": {
Expand Down

1 comment on commit 1c3377b

@vercel
Copy link

@vercel vercel bot commented on 1c3377b Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nextclade – ./

nextclade.vercel.app
nextclade-nextstrain.vercel.app
nextclade-git-master-nextstrain.vercel.app

Please sign in to comment.