Skip to content

Commit

Permalink
chore: Optimize wasm build with wasm-opt and in Cargo.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
PraxTube committed Jan 19, 2024
1 parent b2805ac commit 8bcf5af
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,23 @@ jobs:
- name: Build
run: |
cargo build --release --target wasm32-unknown-unknown
cargo build --profile wasm --target wasm32-unknown-unknown
- name: Download wasm-opt
run: |
wget https://github.com/WebAssembly/binaryen/releases/download/version_116/binaryen-version_116-x86_64-linux.tar.gz
tar -xvf binaryen-version_116-x86_64-linux.tar.gz
chmod +x binaryen-version_116/bin/wasm-opt
- name: Prepare package
run: |
wasm-bindgen --no-typescript --out-name bevy_game --out-dir wasm --target web target/wasm32-unknown-unknown/release/${{ env.binary }}.wasm
wasm-bindgen --no-typescript --out-name bevy_game --out-dir wasm --target web target/wasm32-unknown-unknown/wasm/${{ env.binary }}.wasm
cp -r assets wasm/
- name: Optimize Wasm Build
run: |
./binaryen-version_116/bin/wasm-opt -Oz -o wasm/bevy_game_bg.wasm wasm/bevy_game_bg.wasm
- name: Package as a zip
working-directory: ./wasm
run: |
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
[package]
name = "insta-kill"
version = "0.1.3"
version = "0.1.4"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

# Enable a small amount of optimization in debug mode
[profile.dev]
opt-level = 1

# Enable high optimizations for dependencies (incl. Bevy), but not for our code:
[profile.dev.package."*"]
opt-level = 3

# https://github.com/rust-lang/cargo/issues/4897
[profile.wasm]
inherits = "release"
panic = "abort"
opt-level = 'z'
lto = true
codegen-units = 1

[dependencies]
chrono = "0.4.31"
rand = "0.8.5"
Expand Down

0 comments on commit 8bcf5af

Please sign in to comment.