Skip to content

Commit

Permalink
Add dist profiles with more optimizations (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
rparrett authored Jul 25, 2024
1 parent 9a8cc02 commit ae03869
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
21 changes: 13 additions & 8 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@ jobs:
JORNET_LEADERBOARD_ID: ${{ secrets.JORNET_LEADERBOARD_ID }}
JORNET_LEADERBOARD_KEY: ${{ secrets.JORNET_LEADERBOARD_KEY }}
run: |
cargo build --release --target wasm32-unknown-unknown
cargo build --profile web-dist --target wasm32-unknown-unknown
- 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/web-dist/${{ env.binary }}.wasm
cp -r assets wasm/
- name: Optimize Wasm
uses: NiklasEi/wasm-opt-action@v2
with:
file: target/wasm32-unknown-unknown/web-dist/*.wasm
optimize_all: true
- name: Package as a zip
working-directory: ./wasm
run: |
Expand Down Expand Up @@ -78,11 +83,11 @@ jobs:
JORNET_LEADERBOARD_ID: ${{ secrets.JORNET_LEADERBOARD_ID }}
JORNET_LEADERBOARD_KEY: ${{ secrets.JORNET_LEADERBOARD_KEY }}
run: |
cargo build --release --target x86_64-unknown-linux-gnu
cargo build --profile dist --target x86_64-unknown-linux-gnu
- name: Prepare package
run: |
mkdir linux
cp target/x86_64-unknown-linux-gnu/release/${{ env.binary }} linux/
cp target/x86_64-unknown-linux-gnu/dist/${{ env.binary }} linux/
cp -r assets linux/
- name: Package as a zip
working-directory: ./linux
Expand Down Expand Up @@ -123,11 +128,11 @@ jobs:
JORNET_LEADERBOARD_ID: ${{ secrets.JORNET_LEADERBOARD_ID }}
JORNET_LEADERBOARD_KEY: ${{ secrets.JORNET_LEADERBOARD_KEY }}
run: |
cargo build --release --target x86_64-pc-windows-msvc
cargo build --profile dist --target x86_64-pc-windows-msvc
- name: Prepare package
run: |
mkdir windows
cp target/x86_64-pc-windows-msvc/release/${{ env.binary }}.exe windows/
cp target/x86_64-pc-windows-msvc/dist/${{ env.binary }}.exe windows/
cp -r assets windows/
- name: Package as a zip
run: |
Expand Down Expand Up @@ -170,11 +175,11 @@ jobs:
JORNET_LEADERBOARD_ID: ${{ secrets.JORNET_LEADERBOARD_ID }}
JORNET_LEADERBOARD_KEY: ${{ secrets.JORNET_LEADERBOARD_KEY }}
run: |
cargo build --release --target x86_64-apple-darwin
cargo build --profile dist --target x86_64-apple-darwin
- name: Prepare Package
run: |
mkdir -p ${{ env.binary }}.app/Contents/MacOS
cp target/x86_64-apple-darwin/release/${{ env.binary }} ${{ env.binary }}.app/Contents/MacOS/
cp target/x86_64-apple-darwin/dist/${{ env.binary }} ${{ env.binary }}.app/Contents/MacOS/
cp -r assets ${{ env.binary }}.app/Contents/MacOS/
hdiutil create -fs HFS+ -volname "${{ env.binary }}" -srcfolder ${{ env.binary }}.app ${{ env.binary }}.dmg
- name: Upload binaries to artifacts
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,24 @@ serde = "*"
ron = "0.8"
rand = "0.8"

# Disable low-severity logs at compile time for performance.
log = { version = "0.4", features = [
"max_level_debug",
"release_max_level_warn",
] }

# Dependencies for WASM only.
[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "*", features = ["console", "Window", "Storage"] }

[profile.dist]
inherits = "release"
lto = "thin"

[profile.web-dist]
inherits = "dist"
opt-level = "s"

# Enable max optimizations for dependencies, but not for our code:
[profile.dev.package."*"]
opt-level = 3
Expand Down
33 changes: 26 additions & 7 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
[env]
ENV_DIR = {source="${CARGO_MAKE_PROFILE}", default_value = "debug", mapping = {release = "release"}}
CARGO_TARGET_DIR = {value = "target", condition = {env_not_set = ["CARGO_TARGET_DIR"]}}
ENV_DIR = { source = "${CARGO_MAKE_PROFILE}", default_value = "debug", mapping = { release = "release" } }
CARGO_TARGET_DIR = { value = "target", condition = { env_not_set = [
"CARGO_TARGET_DIR",
] } }
CARGO_WASM_PATH = "${CARGO_TARGET_DIR}/wasm32-unknown-unknown/${ENV_DIR}/${CARGO_MAKE_CRATE_NAME}.wasm"
CARGO_MANIFEST_DIR = "${CARGO_MAKE_WORKING_DIRECTORY}"
PORT=4000
PORT = 4000

[env.release]
CARGO_RELEASE_ARGS = "--release"

[env.web-dist]
CARGO_RELEASE_ARGS = "--profile web-dist"

[tasks.show-env]
command = "env"

[tasks.build]
args = ["build", "--target", "wasm32-unknown-unknown", "@@split(CARGO_RELEASE_ARGS, )"]
args = [
"build",
"--target",
"wasm32-unknown-unknown",
"@@split(CARGO_RELEASE_ARGS, )",
]
command = "cargo"

[tasks.bindgen]
install_crate = {crate_name = "wasm-bindgen-cli", binary = "wasm-bindgen", test_arg="--help"}
args = ["--out-dir", "wasm", "--out-name", "bevy_game", "--target", "web", "--no-typescript", "${CARGO_WASM_PATH}"]
install_crate = { crate_name = "wasm-bindgen-cli", binary = "wasm-bindgen", test_arg = "--help" }
args = [
"--out-dir",
"wasm",
"--out-name",
"bevy_game",
"--target",
"web",
"--no-typescript",
"${CARGO_WASM_PATH}",
]
command = "wasm-bindgen"
dependencies = ["build"]

Expand All @@ -28,7 +47,7 @@ cp -r assets wasm/
dependencies = ["bindgen"]

[tasks.serve]
install_crate = {crate_name = "microserver", binary = "microserver", test_arg="--help"}
install_crate = { crate_name = "microserver", binary = "microserver", test_arg = "--help" }
command = "microserver"
args = ["--port", "${PORT}", "--no-spa", "wasm/"]
dependencies = ["static"]
Expand Down
4 changes: 2 additions & 2 deletions wasm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<head>
<style>
canvas {
width: 100% !important;
height: 100% !important;
width: 100%;
height: 100%;
}
</style>
</head>
Expand Down

0 comments on commit ae03869

Please sign in to comment.