rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.3k stars 2.33k forks source link

RUSTC, RUSTC_WRAPPER are not respected for doctests #12532

Open RalfJung opened 10 months ago

RalfJung commented 10 months ago

When setting RUSTC or RUSTC_WRAPPER, ideally that would affect all rustc invocations that happen during a build. However, right now, rustdoc running doctests will still directly call rustc and bypass those environment variables. IMO this is a bug, cargo should instruct rustdoc to invoke the right rustc. The same goes for the target.runner.

Due to this issue, cargo-miri currently has to do some abhorrent hacks where it intercepts cargo invoking rustdoc, and adjusts the --runtool and --test-builder flags so that they match RUSTC and target.runner. But ideally cargo would just do that by itself.

For RUSTC_WRAPPER, rustdoc needs to gain a new flag with "wrapper" semantics; that is being worked in in https://github.com/rust-lang/rust/pull/114651.

Nemo157 commented 6 months ago

target.runner is handled when using -Zdoctest-xcompile, even when not cross-compiling (https://github.com/rust-lang/cargo/issues/7040)

ehuss commented 6 months ago

I believe that is the intended behavior. That is how the runner field works for cargo run, cargo test, and cargo bench. You don't have to pass --target to have it take effect.

RalfJung commented 6 months ago

@ehuss what exactly is the intended behavior? That I set runner and then only some of the things that are being run use the runner and the rest does something different? What is the motivation for such a surprising and problematic inconsistency?

Nemo157 commented 6 months ago

I think once that flag's behavior is stabilized as the default behavior it will be consistent: target.runner will work for cargo test --doc always. The reason I mentioned that it applies even when not cross-compiling is that it appears to be somewhat of an incidental bugfix bundled into that flag; applying target.runner is commonly necessary for cross-compilation, but makes sense even without it.

RalfJung commented 6 months ago

target.runner will work for cargo test --doc always

Is that the current behavior? At the time I wrote this bug report I think that was not the case.

Nemo157 commented 6 months ago

It's the behavior that -Zdoctest-xcompile enables.

RalfJung commented 6 months ago

Oh I see, now I understand.

Does that also properly apply RUSTC/RUSTC_WRAPPER for doc test builds?

Nemo157 commented 6 months ago

No, those still need implementing separately, and RUSTC_WRAPPER still needs the linked PR or something like it to be able to support on the rustdoc side (I'm gonna bring that up to be merged at the next meeting, so that a feature for it on the cargo side could be added).