-
Notifications
You must be signed in to change notification settings - Fork 29
Automatically configure getrandom web backend #547
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
base: main
Are you sure you want to change the base?
Conversation
This is now functional and can be tested already, but it's blocked on #540. |
Just tested this with the new examples I am doing for |
#540 is no longer blocked, so this can be reviewed :) |
- Setting `build.rustflags` in `Cargo.toml` | ||
- Setting the `RUSTFLAGS` env variable when running `cargo` | ||
|
||
However, not that the rustflags are not merged, but _overwritten_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, not that the rustflags are not merged, but _overwritten_. | |
However, note that the rustflags are not merged, but _overwritten_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! I only got it to work for the current main branch of bevy
This does not work for me
[dependencies]
bevy = "0.16.1"
rand_core = "0.9.3"
rand = "0.9.2"
It should not be a problem that we have multiple versions of getrandom
right?
❯ cargo tree -i getrandom
error: There are multiple `getrandom` packages in your project, and the specification `getrandom` is ambiguous.
Please re-run this command with one of the following specifications:
[email protected]
[email protected]
@@ -33,6 +34,13 @@ pub fn build_web( | |||
profile_args.append(&mut args.cargo_args.common_args.config); | |||
args.cargo_args.common_args.config = profile_args; | |||
|
|||
// Apply the `getrandom` web backend if necessary | |||
if let Some(target) = args.target() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to check if the target specified is actually wasm32-unkown-unkown
(or perhaps we should just overwrite the flag to wasm32-unkown-unkown
when using the web subcommand)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are also other potential web targets like wasm32v1-none
, so I think it's enough to know that the user used a web subcommand
fn add_feature_config(config: &mut Vec<String>, version: &Version, feature: &str) { | ||
// Distinguish entries by version to allow multiple versions to be configured | ||
let table = format!("dependencies.getrandom_{}{}", version.major, version.minor); | ||
// The config arg doesn't support inline tables, so each entries must be configured separately |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo:
// The config arg doesn't support inline tables, so each entries must be configured separately | |
// The config arg doesn't support inline tables, so each entry must be configured separately |
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic | |||
|
|||
### Added | |||
|
|||
- The `bevy build web` and `bevy run web` commands will now automatically apply the web backend for `getrandom` if necessary. It requires both a feature and a rustflag to be enabled by the user, which can quickly lead to compile errors when not set up correctly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it's just me as a none native speaker but at first it read for me like
"for bevy build web
to automatically configure it, you have to enable a feature and some rustflags" until I then realize that the "It" refers to getrandom
.
This should work, I will look into it. |
Created a new project with |
Objective
Closes #546.
Automatically configure the
getrandom
web backend when necessary, to avoid build failures.Solution
getrandom
(and whether the backend is applied) viacargo metadata
--config
flags to pass tocargo build
RUSTFLAGS
Note: Blocked on #540 to add to the
RUSTFLAGS
instead of overwriting them!Testing
First, install the CLI from this branch:
Then execute
bevy run web
on a package that doesn't have thegetrandom
backend configured.This most often happens on the in-development Bevy 0.17.
One good example is the
breakout
example in thebevy
repository itself.Try running this:
You should see an info log "automatically configuring
getrandom
web backend" and also see that the fix is applied to thecargo build
command.