Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from trunk to bevy run web #312

Merged
merged 14 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
workflow_dispatch:
inputs:
version:
description: 'Version number in the format `v1.2.3`'
description: "Version number in the format `v1.2.3`"
required: true
type: string

Expand Down Expand Up @@ -159,15 +159,15 @@ jobs:
- name: Prepare output directories
run: rm -rf tmp; mkdir -p tmp/binary '${{ env.app }}'

- name: Install cargo-binstall (Web)
- name: Install and run Bevy CLI (Web)
if: ${{ matrix.platform == 'web' }}
uses: cargo-bins/cargo-binstall@v1.9.0
run: |
cargo install --git=https://github.com/TheBevyFlock/bevy_cli --locked bevy_cli
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suspect that this will slow down the workflow to some degree because it'll need to compile bevy_cli, whereas cargo-bins/cargo-binstall installs cargo-binstall from binary, which is then used to install trunk from binary. Maybe cargo-binstall could be used to install bevy_cli in the future (if not now? idk how cargo-binstall works).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my testing it seems like binstall doesn't have a precompiled binary for Bevy CLI, so I thought we can save some time by not installing binstall.

I think it's because we don't have a GitHub release yet with the artifacts, but I'm also not sure how exactly binstall works.

But I assume we can eventually switch back to using cargo binstall!

Copy link
Collaborator

@benfrankel benfrankel Feb 10, 2025

Choose a reason for hiding this comment

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

Ok, this can be spun out as a blocked followup issue once this PR is merged.

bevy build --locked --release --yes web --bundle

- name: Install and run trunk (Web)
- name: Move web bundle (Web)
if: ${{ matrix.platform == 'web' }}
run: |
cargo binstall --no-confirm trunk wasm-bindgen-cli wasm-opt
trunk build --locked --release --dist '${{ env.app }}'
run: mv 'target/bevy_web/web-release/${{ env.cargo_build_binary_name }}' '${{ env.app }}'

- name: Build binaries (non-Web)
if: ${{ matrix.platform != 'web' }}
Expand Down Expand Up @@ -266,7 +266,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Do nothing
run: 'true'
run: "true"
outputs:
target: ${{ env.upload_to_itch }}

Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ jobs:
- name: Prepare output directories
run: rm -rf tmp; mkdir -p tmp/binary '${{ env.app }}'

- name: Install cargo-binstall (Web)
- name: Install and run Bevy CLI (Web)
if: ${{ matrix.platform == 'web' }}
uses: cargo-bins/cargo-binstall@v1.9.0
run: |
cargo install --git=https://github.com/TheBevyFlock/bevy_cli --locked bevy_cli
bevy build --locked --release --yes web --bundle

- name: Install and run trunk (Web)
- name: Move web bundle (Web)
if: ${{ matrix.platform == 'web' }}
run: |
cargo binstall --no-confirm trunk wasm-bindgen-cli wasm-opt
trunk build --locked --release --dist '${{ env.app }}'
run: mv 'target/bevy_web/web-release/${{ env.cargo_build_binary_name }}' '${{ env.app }}'

- name: Build binaries (non-Web)
if: ${{ matrix.platform != 'web' }}
Expand Down
37 changes: 13 additions & 24 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"presentation": {
"clear": true
},
"problemMatcher": [
"$rustc"
],
"problemMatcher": ["$rustc"],
"group": {
"kind": "build",
"isDefault": true
Expand All @@ -25,25 +23,18 @@
"label": "Run native release",
"type": "cargo",
"command": "run",
"args": [
"--release",
"--no-default-features"
],
"args": ["--release", "--no-default-features"],
Comment on lines 23 to +26
Copy link
Collaborator

@benfrankel benfrankel Feb 10, 2025

Choose a reason for hiding this comment

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

I'm curious why we suggest that users use the Bevy CLI for native release while the .vscode/tasks.json still uses cargo run directly. Is VS Code special-cased to interpret the output of cargo commands? Also, is there a benefit to bevy run over cargo run for native builds, or is it just for uniformity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now, the native build and run is just a wrapper around cargo.
Consistency makes sense though, I will adjust that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, the task type is set to cargo, so there might actually be some special handling happening. That needs to be investigated further

Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be investigated and potentially changed in a future PR, no need to block on this.

"presentation": {
"clear": true
},
"problemMatcher": [
"$rustc"
],
"problemMatcher": ["$rustc"],
"group": "build"
},
{
"label": "Run web dev",
"type": "process",
"command": "trunk",
"args": [
"serve"
],
"command": "bevy",
"args": ["run", "--yes", "--no-default-features", "web"],
"options": {
"env": {
"RUST_BACKTRACE": "full"
Expand All @@ -52,27 +43,25 @@
"presentation": {
"clear": true
},
"problemMatcher": [
"$rustc"
],
"problemMatcher": ["$rustc"],
"group": "build"
},
{
"label": "Run web release",
"type": "process",
"command": "trunk",
"command": "bevy",
"args": [
"serve",
"run",
"--yes",
"--release",
"--no-default-features"
"--no-default-features",
"web"
],
"presentation": {
"clear": true
},
"problemMatcher": [
"$rustc"
],
"problemMatcher": ["$rustc"],
"group": "build"
}
]
}
}
25 changes: 0 additions & 25 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,3 @@ opt-level = 3
# Remove expensive debug assertions due to <https://github.com/bevyengine/bevy/issues/14291>
[profile.dev.package.wgpu-types]
debug-assertions = false

# The default profile is optimized for Wasm builds because
# that's what [Trunk reads](https://github.com/trunk-rs/trunk/issues/605).
# Optimize for size in the wasm-release profile to reduce load times and bandwidth usage on web.
[profile.release]
# Compile the entire crate as one unit.
# Slows compile times, marginal improvements.
codegen-units = 1
# Do a second optimization pass over the entire program, including dependencies.
# Slows compile times, marginal improvements.
lto = "thin"
# Optimize with size in mind (also try "z", sometimes it is better).
# Slightly slows compile times, great improvements to file size and runtime performance.
opt-level = "s"
# Strip all debugging information from the binary to slightly reduce file size.
strip = "debuginfo"

# Override some settings for native builds.
[profile.release-native]
# Default to release profile values.
inherits = "release"
# Optimize with performance in mind.
opt-level = 3
# Keep debug information in the binary.
strip = "none"
25 changes: 0 additions & 25 deletions Cargo.toml.template
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,3 @@ opt-level = 3
# Remove expensive debug assertions due to <https://github.com/bevyengine/bevy/issues/14291>
[profile.dev.package.wgpu-types]
debug-assertions = false

# The default profile is optimized for Wasm builds because
# that's what [Trunk reads](https://github.com/trunk-rs/trunk/issues/605).
# Optimize for size in the wasm-release profile to reduce load times and bandwidth usage on web.
[profile.release]
# Compile the entire crate as one unit.
# Slows compile times, marginal improvements.
codegen-units = 1
# Do a second optimization pass over the entire program, including dependencies.
# Slows compile times, marginal improvements.
lto = "thin"
# Optimize with size in mind (also try "z", sometimes it is better).
# Slightly slows compile times, great improvements to file size and runtime performance.
opt-level = "s"
# Strip all debugging information from the binary to slightly reduce file size.
strip = "debuginfo"

# Override some settings for native builds.
[profile.release-native]
# Default to release profile values.
inherits = "release"
# Optimize with performance in mind.
opt-level = 3
# Keep debug information in the binary.
strip = "none"
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,20 @@ Feel free to move things around however you want, though.

## Run your game

We recommend running your game with the [Bevy CLI](https://github.com/TheBevyFlock/bevy_cli).

Running your game locally is very simple:

- Use `cargo run` to run a native dev build.
- Use [`trunk serve`](https://trunkrs.dev/) to run a web dev build.
- Use `bevy run` to run a native dev build.
- Use `bevy run --no-default-features web` to run a web dev build.

If you're using [VS Code](https://code.visualstudio.com/), this template comes with a [`.vscode/tasks.json`](./.vscode/tasks.json) file.

<details>
<summary>Run release builds</summary>

- Use `cargo run --profile release-native --no-default-features` to run a native release build.
- Use `trunk serve --release --no-default-features` to run a web release build.
- Use `bevy run --release --no-default-features` to run a native release build.
- Use `bevy run --release --no-default-features web` to run a web release build.

</details>

Expand Down
15 changes: 0 additions & 15 deletions Trunk.toml

This file was deleted.

1 change: 0 additions & 1 deletion post-generate.rhai
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Rename template files.
file::rename(".github/workflows/release.yaml.template", ".github/workflows/release.yaml");
file::rename("Cargo.toml.template", "Cargo.toml");
file::rename("web/index.html.template", "web/index.html");
file::rename("src/main.rs.template", "src/main.rs");
file::rename("src/lib.rs.template", "src/lib.rs");
file::rename("src/audio.rs.template", "src/audio.rs");
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ impl Plugin for AppPlugin {
.set(WindowPlugin {
primary_window: Window {
title: "Bevy New 2D".to_string(),
canvas: Some("#bevy".to_string()),
fit_canvas_to_parent: true,
prevent_default_event_handling: true,
..default()
}
.into(),
Expand Down
38 changes: 0 additions & 38 deletions web/index.html

This file was deleted.

41 changes: 0 additions & 41 deletions web/index.html.template

This file was deleted.

57 changes: 0 additions & 57 deletions web/restart-audio-context.js

This file was deleted.

Loading