cargo
cargo copied to clipboard
RUSTC, RUSTC_WRAPPER, and `target.runner` are not respected for doctests
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.
target.runner is handled when using -Zdoctest-xcompile, even when not cross-compiling (https://github.com/rust-lang/cargo/issues/7040)
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 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?
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.
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.
It's the behavior that -Zdoctest-xcompile enables.
Oh I see, now I understand.
Does that also properly apply RUSTC/RUSTC_WRAPPER for doc test builds?
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).