-
Notifications
You must be signed in to change notification settings - Fork 24
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
Apply rustflags when probing rustc #10
Conversation
We should apply the RUSTFLAGS environment variable when probing with rustc. The RUSTFLAGS might get important flags, such as the sysroot, when doing cross-platform building with tools such as cargo-xbuild or Xargo.
CI failed only on the It would be nice to have some test for this though. I think you could do this with an integration test under It would be nice to see the At a higher level, I think we need to be careful not to over-apply these. Here's what Cargo says: /// Acquire extra flags to pass to the compiler from various locations.
///
/// The locations are:
///
/// - the `RUSTFLAGS` environment variable
///
/// then if this was not found
///
/// - `target.*.rustflags` from the manifest (Cargo.toml)
/// - `target.cfg(..).rustflags` from the manifest
///
/// then if neither of these were found
///
/// - `build.rustflags` from the manifest
///
/// Note that if a `target` is specified, no args will be passed to host code (plugins, build
/// scripts, ...), even if it is the same as the target. First, note that we're only covering the But that final note is the real concern -- if So I don't think we have enough information to perfectly copy what Cargo does, but good enough? Maybe we can also add a method |
A more implicit idea is to look at The "debug" might also be "release" or in the future a custom profile name. It also might not be called Anyway, maybe we can combine these for a heuristic: apply |
Thanks for the review! I fixed the rustfmt, cached the flags on AutoCfg struct creation, and added a simple test. Which is failing on 1.10 and earlier for some reason ?_?.
Yeah that's definitely the Maybe in the long run, we could get cargo to add a
Will try implementing this. |
Hmm, it doesn't seem to be possible to detect when
Which is exactly the same as when we run it directly with (Also, note that cargo_target_dir is not passed to build scripts, see rust-lang/cargo#7325, so I had to approximate it). |
Looks like somewhere between 1.10.0 and 1.15.0, rustc changed the location of test dependencies - on older versions they're in WRT |
Hmm. There's really only one case where cargo doesn't apply So I think the best incremental improvement we can make is to just use the flags when we see |
25: Try to determine if --target was passed to Cargo r=cuviper a=adamreichold This checks the output directory for the `$CARGO_TARGET_DIR/$TARGET` pattern making use of `MAIN_SEPARATOR` to try to handle Windows. It will also fail if either the path or that pattern are not valid UFT-8, but it will then fall back to the current behavior. (So this basically tries to implement #10 (comment).) Co-authored-by: Adam Reichold <adam.reichold@t-online.de> Co-authored-by: Josh Stone <cuviper@gmail.com>
We should apply the RUSTFLAGS environment variable when probing with rustc. The RUSTFLAGS might get important flags, such as the sysroot, when doing cross-platform building with tools such as cargo-xbuild or Xargo.
Without this PR, autocfg will fail when used in concert with xargo/cargo-xbuild, with the following problem:
The reason for this error is that autocfg is not providing the sysroot to
rustc
, and as such it can't find the core/std crates. To fix this, we should pass the sysroot, which is usually found in the RUSTFLAGS.