Skip to content

Conversation

DaAlbrecht
Copy link
Collaborator

@DaAlbrecht DaAlbrecht commented Oct 5, 2025

Objective

Support building and linting packages that do not contain a binary or example target.

Solution

This was not possible because, in all cases, we were looking for a BinTarget (a binary or example target). This makes sense for running (and to some extent building) for the web. For native or linting, this has unintentional side effects.

Testing

Install the current branch:

 cargo install --git https://github.com/TheBevyFlock/bevy_cli --branch build-package --locked bevy_cli

Use the test repo: [email protected]:TimJentzsch/bevy_complex_repo.git

default-run native

bevy_complex_repo/workspace on  main via 🦀 v1.91.0-nightly took 1m14s
❯ bevy run -v
debug: running: `cargo metadata --format-version 1`
debug: running: `cargo run --profile dev`
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.19s
     Running `target/debug/cplx`

default-run web

❯ bevy run web -v
debug: running: `cargo metadata --format-version 1`
info: automatically configuring `getrandom` web backend
info: compiling to WebAssembly...
debug: running: `cargo build --config profile.web.inherits="dev" --config profile.web-release.inherits="release" --config profile.web-release.opt-level="s" --config profile.web-release.strip="debuginfo" --profile web --target wasm32-unknown-unknown`
debug: with env: RUSTFLAGS= --cfg getrandom_backend="wasm_js"
    Finished `web` profile [unoptimized + debuginfo] target(s) in 0.10s
info: bundling JavaScript bindings...
debug: running: `wasm-bindgen --no-typescript --out-name cplx --out-dir /home/squishy/bevy_org/bevy_complex_repo/workspace/target/wasm32-unknown-unknown/web --target web /home/squishy/bevy_org/bevy_complex_repo/workspace/target/wasm32-unknown-unknown/web/cplx.wasm`
info: no custom web assets found, using defaults.
info: open your app at <http://127.0.0.1:4000>!
debug: Serving linked bundle from "/home/squishy/bevy_org/bevy_complex_repo/workspace/target/wasm32-unknown-unknown/web"

Lint specific package (this did not work before)

bevy_complex_repo/workspace on  main via 🦀 v1.91.0-nightly took 23s
❯ bevy lint -p cplx_core
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s

Lint no specific package selected

bevy_complex_repo/workspace on  main via 🦀 v1.91.0-nightly
❯ bevy lint -v
debug: running: `bevy_lint --version`
debug: running: `cargo metadata --format-version 1`
debug: running: `bevy_lint --profile dev`
warning: created a `Bundle` containing a unit `()`
  --> bins/lint/src/main.rs:13:20
   |
13 |     commands.spawn(());
   |              ------^^- help: `spawn_empty()` is more efficient: `spawn_empty()`
   |
   = note: units `()` are not `Component`s and will be skipped
   = note: `#[warn(bevy::unit_in_bundle)]` on by default

warning: `lint` (bin "lint") generated 1 warning (run `cargo fix --bin "lint"` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s
This is equivalent to `cargo check`
❯ cargo check
    Checking lint v0.1.0 (/home/squishy/bevy_org/bevy_complex_repo/workspace/bins/lint)
    Checking package_asset_folder v0.1.0 (/home/squishy/bevy_org/bevy_complex_repo/workspace/bins/package_asset_folder)
    Checking cplx_teaser v0.1.0 (/home/squishy/bevy_org/bevy_complex_repo/workspace/bins/cplx_teaser)
    Checking cplx v0.1.0 (/home/squishy/bevy_org/bevy_complex_repo/workspace/bins/cplx)
    Checking cplx_core v0.1.0 (/home/squishy/bevy_org/bevy_complex_repo/workspace/libs/cplx_core)
    Checking custom_web_folder v0.1.0 (/home/squishy/bevy_org/bevy_complex_repo/workspace/bins/custom_web_folder)
    Checking rustflags v0.1.0 (/home/squishy/bevy_org/bevy_complex_repo/workspace/bins/rustflags)
    Checking cplx_demo v0.1.0 (/home/squishy/bevy_org/bevy_complex_repo/workspace/bins/cplx_demo)
    Checking wasm_opt v0.1.0 (/home/squishy/bevy_org/bevy_complex_repo/workspace/bins/wasm_opt)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.21s

Build native no package specified

❯ bevy build -v
debug: running: `cargo metadata --format-version 1`
debug: running: `cargo build --profile dev`
   Compiling rand_core v0.9.3
   Compiling cplx_teaser v0.1.0 (/home/squishy/bevy_org/bevy_complex_repo/workspace/bins/cplx_teaser)
   Compiling cplx_core v0.1.0 (/home/squishy/bevy_org/bevy_complex_repo/workspace/libs/cplx_core)
   Compiling wasm_opt v0.1.0 (/home/squishy/bevy_org/bevy_complex_repo/workspace/bins/wasm_opt)
   Compiling lint v0.1.0 (/home/squishy/bevy_org/bevy_complex_repo/workspace/bins/lint)
   Compiling cplx_demo v0.1.0 (/home/squishy/bevy_org/bevy_complex_repo/workspace/bins/cplx_demo)
   Compiling package_asset_folder v0.1.0 (/home/squishy/bevy_org/bevy_complex_repo/workspace/bins/package_asset_folder)
   Compiling custom_web_folder v0.1.0 (/home/squishy/bevy_org/bevy_complex_repo/workspace/bins/custom_web_folder)
   Compiling wyrand v0.3.2
   Compiling rand_chacha v0.9.0
   Compiling bevy_prng v0.10.0 (https://github.com/Bluefinger/bevy_rand?branch=prepare-v0.16#2cb84de2)
   Compiling bevy_rand v0.10.0 (https://github.com/Bluefinger/bevy_rand?branch=prepare-v0.16#2cb84de2)
   Compiling rustflags v0.1.0 (/home/squishy/bevy_org/bevy_complex_repo/workspace/bins/rustflags)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 7.99s

Build web no package specified

bevy_complex_repo/workspace on  main via 🦀 v1.91.0-nightly took 2m42s
❯ bevy build web -v
debug: running: `cargo metadata --format-version 1`
info: automatically configuring `getrandom` web backend
info: compiling to WebAssembly...
debug: running: `cargo build --config profile.web.inherits="dev" --config profile.web-release.inherits="release" --config profile.web-release.opt-level="s" --config profile.web-release.strip="debuginfo" --profile web --target wasm32-unknown-unknown`
debug: with env: RUSTFLAGS= --cfg getrandom_backend="wasm_js"
    Finished `web` profile [unoptimized + debuginfo] target(s) in 0.10s
info: bundling JavaScript bindings...
debug: running: `wasm-bindgen --no-typescript --out-name cplx --out-dir /home/squishy/bevy_org/bevy_complex_repo/workspace/target/wasm32-unknown-unknown/web --target web /home/squishy/bevy_org/bevy_complex_repo/workspace/target/wasm32-unknown-unknown/web/cplx.wasm`
info: no custom web assets found, using defaults.

Build Default members native, no package arg

bevy_complex_repo/default_members on  main via 🦀 v1.90.0 took 41s
❯ bevy build -v
debug: running: `cargo metadata --format-version 1`
debug: running: `cargo build --profile dev`
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.09s

Build Default members web, no package arg

bevy_complex_repo/default_members on  main via 🦀 v1.90.0 took 51s
❯ bevy build web -v
debug: running: `cargo metadata --format-version 1`
info: automatically configuring `getrandom` web backend
info: compiling to WebAssembly...
debug: running: `cargo build --config profile.web.inherits="dev" --config profile.web-release.inherits="release" --config profile.web-release.strip="debuginfo" --config profile.web-release.opt-level="s" --profile web --target wasm32-unknown-unknown`
debug: with env: RUSTFLAGS= --cfg getrandom_backend="wasm_js"
    Finished `web` profile [unoptimized + debuginfo] target(s) in 0.11s
info: bundling JavaScript bindings...
debug: running: `wasm-bindgen --no-typescript --out-name default --out-dir /home/squishy/bevy_org/bevy_complex_repo/default_members/target/wasm32-unknown-unknown/web --target web /home/squishy/bevy_org/bevy_complex_repo/default_members/target/wasm32-unknown-unknown/web/default.wasm`
info: no custom web assets found, using defaults.

Run Default members native

bevy_complex_repo/default_members on  main via 🦀 v1.90.0 took 2s
❯ bevy run -v
debug: running: `cargo metadata --format-version 1`
debug: running: `cargo run --profile dev`
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.18s
     Running `target/debug/default`

Run Default members Web

bevy_complex_repo/default_members on  main via 🦀 v1.90.0 took 38s
❯ bevy run web -v
debug: running: `cargo metadata --format-version 1`
info: automatically configuring `getrandom` web backend
info: compiling to WebAssembly...
debug: running: `cargo build --config profile.web.inherits="dev" --config profile.web-release.inherits="release" --config profile.web-release.opt-level="s" --config profile.web-release.strip="debuginfo" --profile web --target wasm32-unknown-unknown`
debug: with env: RUSTFLAGS= --cfg getrandom_backend="wasm_js"
    Finished `web` profile [unoptimized + debuginfo] target(s) in 0.09s
info: bundling JavaScript bindings...
debug: running: `wasm-bindgen --no-typescript --out-name default --out-dir /home/squishy/bevy_org/bevy_complex_repo/default_members/target/wasm32-unknown-unknown/web --target web /home/squishy/bevy_org/bevy_complex_repo/default_members/target/wasm32-unknown-unknown/web/default.wasm`
info: no custom web assets found, using defaults.
info: open your app at <http://127.0.0.1:4000>!
debug: Serving linked bundle from "/home/squishy/bevy_org/bevy_complex_repo/default_members/target/wasm32-unknown-unknown/web"

Build all examples (this did not work before)

bevy on  main is 📦 v0.18.0-dev via 🦀 v1.90.0
❯ bevy build --examples  -v
debug: running: `cargo metadata --format-version 1`
debug: running: `cargo build --examples --profile dev`

Follow up

I wanted to implement #622 and got nerdsniped by: #622 (comment) so this sets the foundation for this issue.

I would also like to be able to do the same for the web (maybe behind a --compile-only flag that only runs the cargo build command)

@DaAlbrecht DaAlbrecht added A-CLI Related to the main CLI and not a more specific subcommand A-Cross-Cutting Affects multiple areas of the repository S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes labels Oct 5, 2025
Cargo does the following for `build` / `check`:

https://doc.rust-lang.org/cargo/commands/cargo-build.html
> By default, when no package selection options are given, the packages selected depend on the selected manifest file (based on the current working directory if --manifest-path is not given). If the manifest is the root of a workspace then the workspaces default members are selected, otherwise only the package defined by the manifest will be selected.

https://doc.rust-lang.org/cargo/commands/cargo-run.html
When no target selection options are given, cargo run will run the binary target. If there are multiple binary targets, you must pass a target flag to choose one. Or, the default-run field may be specified in the [package] section of Cargo.toml to choose the name of the binary to run by default.
@DaAlbrecht DaAlbrecht marked this pull request as ready for review October 5, 2025 20:43
@DaAlbrecht DaAlbrecht added S-Needs-Review The PR needs to be reviewed before it can be merged C-Bug A bug in the program and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Oct 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Related to the main CLI and not a more specific subcommand A-Cross-Cutting Affects multiple areas of the repository C-Bug A bug in the program D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review The PR needs to be reviewed before it can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant