Skip to content

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

@tomjakubowski

Description

@tomjakubowski
Contributor

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)

Activity

tomjakubowski

tomjakubowski commented on Feb 11, 2019

@tomjakubowski
ContributorAuthor

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

ehuss commented on Feb 11, 2019

@ehuss
Contributor

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

tomjakubowski commented on Feb 11, 2019

@tomjakubowski
ContributorAuthor

Thanks! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ehuss@tomjakubowski

        Issue actions

          Doc tests run by `cargo test` do not include rustflags from .cargo/config · Issue #6650 · rust-lang/cargo