Skip to content

Doctest cannot find reexported proc-macro crate when --target is given #4254

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

Closed
kennytm opened this issue Jul 7, 2017 · 2 comments · Fixed by #4447
Closed

Doctest cannot find reexported proc-macro crate when --target is given #4254

kennytm opened this issue Jul 7, 2017 · 2 comments · Fixed by #4447

Comments

@kennytm
Copy link
Member

kennytm commented Jul 7, 2017

Repro step:

Execute these in the shell:

cargo init --lib
echo 'serde = { version = "1.0", features = ["derive"] }' >> Cargo.toml
echo 'extern crate serde;' > src/lib.rs
cargo test --target x86_64-apple-darwin

(The x86_64-apple-darwin should be replaced by the HOST triple. The same happens with x86_64-unknown-linux-gnu as the HOST.)

Actual result:

The doc test failed by complaining serde_derive not found:

   Doc-tests test2
error[E0463]: can't find crate for `serde_derive` which `serde` depends on
 --> $DIR/src/lib.rs:1:1
  |
1 | extern crate serde;
  | ^^^^^^^^^^^^^^^^^^^ can't find crate
  • Adding a [dev-dependencies] to serde_derive will not solve it.
  • Depending on serde_derive directly in [dependencies] + extern crate serde_derive; will solve it (but it defeats the purpose of features = ["derive"])

The problem is that libserde_derive-* are placed in the HOST folder (target/debug/deps), while libserde-* is in the TARGET folder (target/<triple>/debug/deps). rustdoc is executed only with -L dependency=target/<triple>/debug/deps, so libserde_derive-* is not found.

$ find . -name libserde*
./target/debug/deps/libserde_derive-277a82a8f5bc6353.dylib
./target/debug/deps/libserde_derive-277a82a8f5bc6353.dylib.dSYM
./target/debug/deps/libserde_derive-277a82a8f5bc6353.dylib.dSYM/Contents/Resources/DWARF/libserde_derive-277a82a8f5bc6353.dylib
./target/debug/deps/libserde_derive_internals-558d9b0ee0da671d.rlib
./target/x86_64-apple-darwin/debug/deps/libserde-5b01ff1fa5c50deb.rlib

Versions
$ rustc -vV
rustc 1.20.0-nightly (696412de7 2017-07-06)
binary: rustc
commit-hash: 696412de7e4e119f8536686c643621115b90c775
commit-date: 2017-07-06
host: x86_64-apple-darwin
release: 1.20.0-nightly
LLVM version: 4.0

$ cargo -vV
cargo 0.21.0-nightly (eb6cf012a 2017-07-02)
release: 0.21.0
commit-hash: eb6cf012a6cc23c9c89c4009564de9fccc38b9cb
commit-date: 2017-07-02
@parched
Copy link

parched commented Jul 9, 2017

Duplicate of #4224 by the sounds of things

@kennytm
Copy link
Member Author

kennytm commented Jul 9, 2017

@parched Seems so. Thanks for the pointer.

@kennytm kennytm closed this as completed Jul 9, 2017
kennytm added a commit to kennytm/cov that referenced this issue Jul 10, 2017
Doing so will cause doc test to fail when serde's feature="derive"
is used. See rust-lang/cargo#4254.
bors added a commit that referenced this issue Aug 31, 2017
…e, r=alexcrichton

Add host dependency path via -L for cargo_test.

Proc-macro crates' dependencies in the host dependency directory cannot
be found when running `cargo test` with the `--target {target}` flag
set as reported in #4224. This adds the host dependency directory to the
search path to find those missing dependencies with -L when building tests
and adds a test case that fails before and passes after this patch.

A new function `find_host_deps(..)` is added to accomplish this which can
determine the path of the host dependencies directory from within
`run_doc_tests(..)` where the missing library search path is needed.

Fixes #4224
Fixes #4254

Modeled after a similar patch: a298346

**Concerns**

The test case seems to require a non-local crate from crates.io to example the failure before this patch. Couldn't make it fail with simply another local subcrate, but if others think it's possible that'd be great. This means that during tests for the cargo project itself that this test case actually downloads and compiles a crate, which I don't think any other tests do and is obviously not ideal and is perhaps even unacceptable. I've used the base64 crate pretty arbitrarily, but which crate it is really doesn't matter to test the case's content. So if anyone knows a tiny or empty crate on crates.io to use instead that'd speed this up and if someone can figure out how to make it fail before this patch is applied without downloading an external crate that would help as well.

Also, I'm not 100% confident about the `find_host_deps(..)` style and whether it's the best way to find the host dependencies directory with just the `TestOptions` and `Compilation` structs available since I'm new to this project. Any comments are appreciated.
faern added a commit to mullvad/openvpn-plugin-rs that referenced this issue Oct 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants