Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc tests run by cargo test do not include rustflags from .cargo/config #6650

Closed
tomjakubowski opened this issue Feb 11, 2019 · 3 comments
Closed
Labels
C-bug Category: bug

Comments

@tomjakubowski
Copy link
Contributor

tomjakubowski commented Feb 11, 2019

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

  1. 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.
  2. Run cargo build --verbose and note the presence of /opt/CANARY/lib in the compiler invocation.
  3. 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)
@tomjakubowski tomjakubowski added the C-bug Category: bug label Feb 11, 2019
@tomjakubowski
Copy link
Contributor Author

tomjakubowski commented Feb 11, 2019

I noticed that setting RUSTFLAGS manually didn't help either, and then found #4737. So I closed the issue thinking this one was a duplicate.

However, it seems that Rustdoc now does take -C flags, at least: rust-lang/rust#49956

So maybe you'd like to reconsider passing RUSTFLAGS on to rustdoc. I've re-opened so that you may close :-)

@ehuss
Copy link
Contributor

ehuss commented Feb 11, 2019

rustdoc does not support testing with --target (see #6460 with some upstream issues), so it doesn't recognize [target] tables.

Also, rustdoc uses a separate rustdocflags (or RUSTDOCFLAGS env var), though it is not supported in [target].

@tomjakubowski
Copy link
Contributor Author

Thanks! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants