dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

`rustflags` in `./cargo/config.toml` being ignored

Open pablosichert opened this issue 1 year ago • 2 comments

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
  • [x] I don't have time to fix this right now, but maybe later

pablosichert avatar Apr 24 '24 21:04 pablosichert

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

https://github.com/DioxusLabs/dioxus/blob/1ec6819ac88389dfb26102f8ad186f5fcbb9b2ae/packages/cli/src/builder.rs#L116

https://github.com/DioxusLabs/dioxus/blob/1ec6819ac88389dfb26102f8ad186f5fcbb9b2ae/packages/cli/src/server/fullstack/mod.rs#L10-L34

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 avatar Apr 24 '24 21:04 pablosichert

https://github.com/DioxusLabs/dioxus/issues/2259 seems to be somewhat related.

pablosichert avatar Apr 24 '24 21:04 pablosichert

This was fixed in https://github.com/DioxusLabs/dioxus/pull/2258

ealmloff avatar Jul 19 '24 23:07 ealmloff