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

test --doc can't find dependency of dependency with a proc macro when passing --target #4224

Closed
parched opened this issue Jun 25, 2017 · 3 comments · Fixed by #4447
Closed

Comments

@parched
Copy link

parched commented Jun 25, 2017

I was trying to add CI to a proc macro crate of mine, but the CI passes --target explicitly even though it's unneeded. To my surprise the test failed https://travis-ci.org/parched/runtime-target-feature-rs/jobs/246862218

I've tried to create a minimal repro below, possibly there are some extra things that aren't needed.

Cargo.toml

...

[lib]
proc-macro = true

[dependencies]
syn = "0.11"

src/lib.rs

#![feature(proc_macro)]

extern crate proc_macro;
extern crate syn;

use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn test(_: TokenStream, function: TokenStream) -> TokenStream {
    function
}
$ cargo test --doc --target x86_64-unknown-linux-gnu
   Compiling quote v0.3.15
   Compiling unicode-xid v0.0.4
   Compiling synom v0.11.3
   Compiling syn v0.11.11
   Compiling runtime-target-feature v0.1.0 (file:///home/james/junk/cargo-dep-test)
    Finished dev [unoptimized + debuginfo] target(s) in 5.35 secs
   Doc-tests runtime-target-feature
error[E0463]: can't find crate for `quote` which `syn` depends on
 --> /home/james/junk/cargo-dep-test/src/lib.rs:4:1
  |
4 | extern crate syn;
  | ^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error(s)

thread '<unnamed>' panicked at 'Box<Any>', src/librustc_errors/lib.rs:512
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: test failed, to rerun pass '--doc'

without explicitly passing my native target

$ cargo test --doc
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
   Doc-tests runtime-target-feature

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
$ rustc --version
rustc 1.20.0-dev (ec5c2e8fb 2017-06-20)
$ cargo --version
cargo 0.20.0-nightly (0d0f3baad 2017-06-13)
@parched parched changed the title test --doc can't find crate with a proc macro with --target test --doc can't find dependency of dependency with a proc macro when passing --target Jun 25, 2017
@ashleygwilliams
Copy link
Member

thanks for filing @parched ! sorry that you are running into this, and appreciate the repro case. one thing we'll need to figure out here is whether this is being caused by cargo itself or by the "rust module loader" (not sure the official term, but hopefully you get the gist)

one way to figure this out might be to run cargo build --verbose to see what rust command cargo is generating, and see if they are different when the target is directly passed. also: does this issue happen when you run cargo build or only with test --doc? isolating that as well might be helpful.

sorry these aren't super clear directives, but hopefully this gives you an idea of where to start investigating and we'll take a look as well!

@parched
Copy link
Author

parched commented Jul 7, 2017

Hi @ashleygwilliams, thanks for the pointers, yes it's only with test --doc. I ran with verbose and this is what I see

$ cargo test --doc --verbose --target=x86_64-unknown-linux-gnu
...
 Running `rustdoc --test /home/james/junk/cargo-dep-test/src/lib.rs --crate-name runtime_target_feature -L dependency=/home/james/junk/cargo-dep-test/target/x86_64-unknown-linux-gnu/debug/deps --extern runtime_target_feature=/home/james/junk/cargo-dep-test/target/debug/deps/libruntime_target_feature-98b7f9c74b1b8141.so --extern syn=/home/james/junk/cargo-dep-test/target/debug/deps/libsyn-e662069961d8f963.rlib`

vs

$ cargo test --doc --verbose
...
Running `rustdoc --test /home/james/junk/cargo-dep-test/src/lib.rs --crate-name runtime_target_feature -L dependency=/home/james/junk/cargo-dep-test/target/debug/deps --extern syn=/home/james/junk/cargo-dep-test/target/debug/deps/libsyn-e662069961d8f963.rlib --extern runtime_target_feature=/home/james/junk/cargo-dep-test/target/debug/deps/libruntime_target_feature-98b7f9c74b1b8141.so`

So looks like cargo is passing the wrong -L dependency=... in the first case. For cargo build it is the same, .../target/debug/... for both cases.

@parched
Copy link
Author

parched commented Jul 10, 2017

Looks like there probably needs to be a similar fix like a298346 that @alexcrichton made but applied to cargo_test.rs.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants