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

Add support for cargo's --config arg #209

Merged
merged 12 commits into from
Jan 19, 2025
Merged

Add support for cargo's --config arg #209

merged 12 commits into from
Jan 19, 2025

Conversation

TimJentzsch
Copy link
Collaborator

@TimJentzsch TimJentzsch commented Dec 31, 2024

Objective

Closes #201.

Allows users to quickly try out different configurations without modifying Cargo.toml.

For us, it's most useful for finding the best default config for the web profiles.

Solution

Add support for --config argument for bevy build and bevy run, analogue to the cargo counterpart.
This essentially allows you to modify the Cargo.toml without editing the file, e.g. --config "profile.web.debug=false".

We already exploit cargo's --config arg to configure our default web compilation profiles.
So we have to ensure that the user-provided args overwrite our default ones.

To do this, we change the default web profiles to be prepended to the user-provided --config args, instead of converting them to --config arguments directly.
Since --config is resolved left-to-right, the defaults will be overwritten by the user.

Testing

Try for example:

bevy build --config "profile.web.debug=false" --config 'profile.web.inherits= "release"' web

Now instead of

Finished `web` profile [unoptimized + debuginfo] target(s)

you should get

Finished `web` profile [optimized] target(s)

Debug info removed and optimizations enabled!
(Of course this can be done easier via bevy build --release web, but like this it's easier to benchmark different compilation profiles to choose the best default)

@TimJentzsch TimJentzsch added C-Feature Make something new possible A-Run Related to the bevy run command A-Build Related to the bevy build command labels Dec 31, 2024
@TimJentzsch TimJentzsch added the S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged label Jan 18, 2025
@TimJentzsch TimJentzsch marked this pull request as ready for review January 18, 2025 12:49
@TimJentzsch TimJentzsch added S-Needs-Review The PR needs to be reviewed before it can be merged D-Straightforward Simple bug fixes and API improvements, docs, test and examples and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jan 18, 2025
Copy link
Contributor

@DaAlbrecht DaAlbrecht left a comment

Choose a reason for hiding this comment

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

Works like a charm! Tested with config options as arguments or by passing a file.
If the comment about the cargo build options is resolved this can be merged IMO 😊

src/external_cli/arg_builder.rs Show resolved Hide resolved
src/external_cli/arg_builder.rs Outdated Show resolved Hide resolved
src/external_cli/cargo/build.rs Outdated Show resolved Hide resolved
@DaAlbrecht
Copy link
Contributor

Perhaps a test case for add_values_separately would be nice

Copy link
Contributor

@DaAlbrecht DaAlbrecht left a comment

Choose a reason for hiding this comment

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

Nice work!

@TimJentzsch TimJentzsch merged commit 10d0dbc into main Jan 19, 2025
8 checks passed
@TimJentzsch TimJentzsch deleted the 201-config-arg branch January 19, 2025 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Build Related to the bevy build command A-Run Related to the bevy run command C-Feature Make something new possible 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support --config argument for bevy build and bevy run
2 participants