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

rustflags in ./cargo/config.toml being ignored #2366

Open
1 of 3 tasks
Tracked by #2372
pablosichert opened this issue Apr 24, 2024 · 2 comments
Open
1 of 3 tasks
Tracked by #2372

rustflags in ./cargo/config.toml being ignored #2366

pablosichert opened this issue Apr 24, 2024 · 2 comments
Labels
bug Something isn't working cli Related to the dioxus-cli program fullstack related to the fullstack crate

Comments

@pablosichert
Copy link

Problem

When having a ./cargo/config.toml file that contains e.g. (commonly used in combination with web-sys)

[build]
rustflags = ["--cfg=web_sys_unstable_apis"]

and running dx serve, the build fails since it does not consider the specified rustflags. Running cargo build succeeds.

Steps To Reproduce

Steps to reproduce the behavior:

  • Set up project using default_platform = "fullstack".
  • Set rustflags in config.toml.
  • Run dx serve on a build that depends on specific rustflags being set.

Expected behavior

dx serve should succeed when cargo build does.

Environment:

  • Dioxus version: 0.5.4, latest
  • Rust version: 1.76.0, stable
  • App platform: fullstack

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later
@pablosichert
Copy link
Author

@ealmloff pointed me to the following locations of interest where dioxus sets the rustflags:

.set_rust_flags(rust_flags)

static CLIENT_RUST_FLAGS: &str = "-C debuginfo=none -C strip=debuginfo";
// The `opt-level=2` increases build times, but can noticeably decrease time
// between saving changes and being able to interact with an app. The "overall"
// time difference (between having and not having the optimization) can be
// almost imperceptible (~1 s) but also can be very noticeable (~6 s) — depends
// on setup (hardware, OS, browser, idle load).
static SERVER_RUST_FLAGS: &str = "-C opt-level=2";
static DEBUG_RUST_FLAG: &str = "-C debug-assertions";
fn rust_flags(build: &ConfigOptsBuild, base_flags: &str) -> String {
let mut rust_flags = base_flags.to_string();
if !build.release {
rust_flags += " ";
rust_flags += DEBUG_RUST_FLAG;
};
rust_flags
}
pub fn client_rust_flags(build: &ConfigOptsBuild) -> String {
rust_flags(build, CLIENT_RUST_FLAGS)
}
pub fn server_rust_flags(build: &ConfigOptsBuild) -> String {
rust_flags(build, SERVER_RUST_FLAGS)
}

The Cargo Book states on build.rustflags:

There are four mutually exclusive sources of extra flags. They are checked in order, with the first one being used:

  1. CARGO_ENCODED_RUSTFLAGS environment variable.
  2. RUSTFLAGS environment variable.
  3. All matching target.<triple>.rustflags and target.<cfg>.rustflags config entries joined together.
  4. build.rustflags config value.

So this behavior is not entirely unsurprising.

I don't know of any obvious solution, but one (rather elaborate) approach would be to search the hierarchy for config.toml and read the files in Dioxus itself: https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure.

@pablosichert
Copy link
Author

#2259 seems to be somewhat related.

@ealmloff ealmloff added bug Something isn't working cli Related to the dioxus-cli program fullstack related to the fullstack crate labels Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cli Related to the dioxus-cli program fullstack related to the fullstack crate
Projects
None yet
Development

No branches or pull requests

2 participants