cargo icon indicating copy to clipboard operation
cargo copied to clipboard

RUSTC, RUSTC_WRAPPER, and `target.runner` are not respected for doctests

Open RalfJung opened this issue 2 years ago • 8 comments

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.

RalfJung avatar Aug 20 '23 08:08 RalfJung

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

Nemo157 avatar Dec 21 '23 00:12 Nemo157

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.

ehuss avatar Dec 21 '23 01:12 ehuss

@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?

RalfJung avatar Dec 21 '23 11:12 RalfJung

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.

Nemo157 avatar Dec 21 '23 11:12 Nemo157

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.

RalfJung avatar Dec 21 '23 11:12 RalfJung

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

Nemo157 avatar Dec 21 '23 11:12 Nemo157

Oh I see, now I understand.

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

RalfJung avatar Dec 21 '23 12:12 RalfJung

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).

Nemo157 avatar Dec 21 '23 13:12 Nemo157