`rustflags` in `./cargo/config.toml` being ignored
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
rustflagsinconfig.toml. - Run
dx serveon a build that depends on specificrustflagsbeing 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
@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:
CARGO_ENCODED_RUSTFLAGSenvironment variable.RUSTFLAGSenvironment variable.- All matching
target.<triple>.rustflagsandtarget.<cfg>.rustflagsconfig entries joined together.build.rustflagsconfig 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.
https://github.com/DioxusLabs/dioxus/issues/2259 seems to be somewhat related.
This was fixed in https://github.com/DioxusLabs/dioxus/pull/2258