Problem
We can specify RUSTFLAGS for a workspace in .cargo/config, like so:
[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-L/opt/CANARY/lib",
]
Cargo dutifully passes those flags on to the compiler when you invoke cargo build or cargo run for that target. It also seems to mostly pass them on when you run cargo test, with one exception: when building the doctest binary. My expectation is that Cargo should set these compiler flags when building the doctest binary.
Steps
- Clone this repository: https://github.com/tomjakubowski/doctest-rustflags. The repo is a Cargo library project with a doctest and a
.cargo/config file specifying some RUSTFLAGS.
- Run
cargo build --verbose and note the presence of /opt/CANARY/lib in the compiler invocation.
- Run
cargo test --verbose and note the absence of /opt/CANARY/lib when building the rustdoc binary:
Compiling doctest-rustflags v0.1.0 (/Users/tom/code/doctest-rustflags)
Running `rustc --edition=2018 --crate-name doctest_rustflags src/lib.rs --color always --crate-type lib --emit=dep-info,link -Cdebuginfo=2 -C metadata=533b040c3210b269 -C extra-filename=-533b040c3210b269 --out-dir /Users/tom/code/doctest-rustflags/target/debug/deps -C incremental=/Users/tom/code/doctest-rustflags/target/debug/incremental -L dependency=/Users/tom/code/doctest-rustflags/target/debug/deps -C link-arg=-L/opt/CANARY/lib`
Running `rustc --edition=2018 --crate-name doctest_rustflags src/lib.rs --color always --emit=dep-info,link -C debuginfo=2 --test -C metadata=f7f76e9875dad886 -C extra-filename=-f7f76e9875dad886 --out-dir /Users/tom/code/doctest-rustflags/target/debug/deps -C incremental=/Users/tom/code/doctest-rustflags/target/debug/incremental -L dependency=/Users/tom/code/doctest-rustflags/target/debug/deps -C link-arg=-L/opt/CANARY/lib`
[truncated]
Doc-tests doctest-rustflags
Running `rustdoc --edition=2018 --test /Users/tom/code/doctest-rustflags/src/lib.rs --crate-name doctest_rustflags -L dependency=/Users/tom/code/doctest-rustflags/target/debug/deps -L dependency=/Users/tom/code/doctest-rustflags/target/debug/deps --extern doctest_rustflags=/Users/tom/code/doctest-rustflags/target/debug/deps/libdoctest_rustflags-533b040c3210b269.rlib`
Possible Solution(s)
Beats me, though I would love to use this to get back to contributing something to rustdoc :-)
Notes
Output of cargo version:
cargo 1.32.0 (8610973aa 2019-01-02)
Problem
We can specify
RUSTFLAGSfor a workspace in.cargo/config, like so:Cargo dutifully passes those flags on to the compiler when you invoke
cargo buildorcargo runfor that target. It also seems to mostly pass them on when you runcargo test, with one exception: when building the doctest binary. My expectation is that Cargo should set these compiler flags when building the doctest binary.Steps
.cargo/configfile specifying someRUSTFLAGS.cargo build --verboseand note the presence of/opt/CANARY/libin the compiler invocation.cargo test --verboseand note the absence of/opt/CANARY/libwhen building the rustdoc binary:Possible Solution(s)
Beats me, though I would love to use this to get back to contributing something to rustdoc :-)
Notes
Output of
cargo version: