rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.61k stars 12.74k forks source link

rustdoc ignores `cargo` and linker settings when compiling doc tests #125657

Open alice-i-cecile opened 5 months ago

alice-i-cecile commented 5 months ago

When building doc tests, cargo settings like --jobs are ignored, and the linker specified in config.toml is also ignored.

However, by setting rustdocflags we can control the linker correctly. This should use the project-level linker by default.

Context

These limitations make problems with slow / high memory doc test construction (see #75341) much harder to mitigate. The approach proposed in #51228 may offer a way to fix this.

Initially discovered by Giooschi on the Bevy Discord while investigating https://github.com/bevyengine/bevy/issues/12207.

Meta

rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-pc-windows-msvc
release: 1.78.0
LLVM version: 18.1.2
ehuss commented 5 months ago

I believe linker support is gated behind the doctest-xcompile feature.

I think jobs support is already tracked as a request in https://github.com/rust-lang/cargo/issues/10702 and https://github.com/rust-lang/rust/issues/53143.

TheLostLambda commented 1 week ago

This bug also seems to be causing problems here: https://github.com/TheLostLambda/knus/issues/11

On Macos we need to use the lld linker to compile this crate, but because there is a doctest in the repo that's currently causing these linking errors, actually fixing this error in cargo test is blocked by this, I believe.

We have a .cargo/config.toml that seems to fix the issue everywhere except for doctests!