Skip to content

Conversation

DaAlbrecht
Copy link
Collaborator

@DaAlbrecht DaAlbrecht commented Aug 9, 2025

Support merging rustflags from the resolved cargo config together with the rustflags passed in the CliConfig using cargo_config2

Closes #537

@@ -53,6 +53,9 @@ dialoguer = { version = "0.11.0", default-features = false }
# Cargo like styling for clap
clap-cargo = "0.16.0"

# Load and resolve Cargo configuration.
cargo-config2 = "0.1"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some bigger crates depend on this so i think its fine: https://lib.rs/crates/cargo-config2/rev

Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO well worth it to keep consistent with Cargo and handle all the complexity

src/config.rs Outdated
let target = if is_web {
"wasm32-unknown-unknown"
} else {
config.host_triple().ok()?
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems super useful. For that alone the crate is probably worth it!

src/config.rs Outdated
@@ -184,6 +184,30 @@ impl CliConfig {

self
}

pub fn merge_cargo_config_rustflags(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm unsure where to put this. First, I had the merging logic inside of CliConfig::rustflags, but I don't like that because:

  1. merging rustflag configs is not what I would expect to happen if I create a CliConfig. I expect to... just get the config :)
  2. It's harder to test

While not 100% happy, I think having this live inside of CliConfig is the best place for now

@DaAlbrecht DaAlbrecht force-pushed the cargo-config-rustflags branch from a460a9a to ea977d9 Compare August 9, 2025 13:56
…ustflags`

We do not actually merge anything yet so this fits better.
@DaAlbrecht DaAlbrecht changed the title Merge cli rustflags with cargo config rustflags Append cargo config rustflags to CliConfig Aug 9, 2025
@DaAlbrecht DaAlbrecht marked this pull request as ready for review August 9, 2025 14:23
@DaAlbrecht DaAlbrecht added A-CLI Related to the main CLI and not a more specific subcommand D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review The PR needs to be reviewed before it can be merged labels Aug 9, 2025
@janhohenheim
Copy link
Member

Also closes #536 and #444

@DaAlbrecht DaAlbrecht requested a review from TimJentzsch August 10, 2025 17:46
Copy link
Collaborator

@TimJentzsch TimJentzsch left a comment

Choose a reason for hiding this comment

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

Just one code quality comment, but otherwise it looks good!

@TimJentzsch
Copy link
Collaborator

Tested and seems to work. Though it should be noted that a .cargo/config.toml in a package is only considered when you run the CLI from that package folder.
But I think that's consistent with cargo?

@TimJentzsch
Copy link
Collaborator

Oh and another nit, we should check if any documentation should be updated.
Also @DaAlbrecht I think this warrants an entry in the changelog :)

@BD103 BD103 linked an issue Aug 11, 2025 that may be closed by this pull request
@TimJentzsch TimJentzsch added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review The PR needs to be reviewed before it can be merged labels Aug 12, 2025
@DaAlbrecht
Copy link
Collaborator Author

Tested and seems to work. Though it should be noted that a .cargo/config.toml in a package is only considered when you run the CLI from that package folder. But I think that's consistent with cargo?

Yes see here: https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure

@DaAlbrecht DaAlbrecht enabled auto-merge (squash) August 13, 2025 18:02
@DaAlbrecht DaAlbrecht merged commit cf601c9 into main Aug 13, 2025
10 checks passed
@DaAlbrecht DaAlbrecht deleted the cargo-config-rustflags branch August 13, 2025 18:10
TimJentzsch added a commit that referenced this pull request Sep 9, 2025
# Objective

Closes #546.

Automatically configure the `getrandom` web backend when necessary, to
avoid build failures.

# Solution

- Detect usage of `getrandom` (and whether the backend is applied) via
`cargo metadata`
- Configure the feature flag via `--config` flags to pass to `cargo
build`
- Configure the backend by adding to the `RUSTFLAGS`

Note: Blocked on #540 to add to the `RUSTFLAGS` instead of overwriting
them!

# Testing

First, install the CLI from this branch:

```sh
cargo install --git https://github.com/TheBevyFlock/bevy_cli --branch 546-getrandom-fix --locked bevy_cli
```

Then execute `bevy run web` on a package that doesn't have the
`getrandom` backend configured.
This most often happens on the in-development Bevy 0.17.

One good example is the `breakout` example in the `bevy` repository
itself.
Try running this:

```sh
bevy run --example=breakout web --verbose
```

You should see an info log "automatically configuring `getrandom` web
backend" and also see that the fix is applied to the `cargo build`
command.
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 D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge RUSTFLAGS rustflags in config.toml are overwritten instead of merged
3 participants