Skip to content

Add host dependency path via -L for cargo_test. #4447

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

Merged
merged 4 commits into from
Aug 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/cargo/ops/cargo_rustc/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ pub struct Compilation<'cfg> {
/// Root output directory (for the local package's artifacts)
pub root_output: PathBuf,

/// Output directory for rust dependencies
/// Output directory for rust dependencies.
/// May be for the host or for a specific target.
pub deps_output: PathBuf,

/// Library search path for compiler plugins and build scripts
/// which have dynamic dependencies.
pub plugins_dylib_path: PathBuf,
/// Output directory for the rust host dependencies.
pub host_deps_output: PathBuf,

/// The path to rustc's own libstd
pub host_dylib_path: Option<PathBuf>,
Expand Down Expand Up @@ -64,7 +64,7 @@ impl<'cfg> Compilation<'cfg> {
native_dirs: HashSet::new(), // TODO: deprecated, remove
root_output: PathBuf::from("/"),
deps_output: PathBuf::from("/"),
plugins_dylib_path: PathBuf::from("/"),
host_deps_output: PathBuf::from("/"),
host_dylib_path: None,
target_dylib_path: None,
tests: Vec::new(),
Expand Down Expand Up @@ -124,7 +124,7 @@ impl<'cfg> Compilation<'cfg> {
-> CargoResult<ProcessBuilder> {

let mut search_path = if is_host {
let mut search_path = vec![self.plugins_dylib_path.clone()];
let mut search_path = vec![self.host_deps_output.clone()];
search_path.extend(self.host_dylib_path.clone());
search_path
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_rustc/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
None => {}
}

self.compilation.plugins_dylib_path = self.host.deps().to_path_buf();
self.compilation.host_deps_output = self.host.deps().to_path_buf();

let layout = self.target.as_ref().unwrap_or(&self.host);
self.compilation.root_output = layout.dest().to_path_buf();
Expand Down
7 changes: 7 additions & 0 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,17 @@ fn run_doc_tests(options: &TestOptions,
arg.push(rust_dep);
p.arg("-L").arg(arg);
}

for native_dep in compilation.native_dirs.iter() {
p.arg("-L").arg(native_dep);
}

for &host_rust_dep in &[&compilation.host_deps_output] {
let mut arg = OsString::from("dependency=");
arg.push(host_rust_dep);
p.arg("-L").arg(arg);
}

for arg in test_args {
p.arg("--test-args").arg(arg);
}
Expand Down
57 changes: 56 additions & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fs::File;
use std::io::prelude::*;
use std::str;

use cargotest::{sleep_ms, is_nightly};
use cargotest::{sleep_ms, is_nightly, rustc_host};
use cargotest::support::{project, execs, basic_bin_manifest, basic_lib_manifest, cargo_exe};
use cargotest::support::paths::CargoPathExt;
use cargotest::support::registry::Package;
Expand Down Expand Up @@ -2782,3 +2782,58 @@ fn publish_a_crate_without_tests() {
assert_that(p.cargo("test").arg("--package").arg("testless"),
execs().with_status(0));
}

#[test]
fn find_dependency_of_proc_macro_dependency_with_target() {
let workspace = project("workspace")
.file("Cargo.toml", r#"
[workspace]
members = ["root", "proc_macro_dep"]
"#)
.file("root/Cargo.toml", r#"
[project]
name = "root"
version = "0.1.0"
authors = []

[dependencies]
proc_macro_dep = { path = "../proc_macro_dep" }
"#)
.file("root/src/lib.rs", r#"
#[macro_use]
extern crate proc_macro_dep;

#[derive(Noop)]
pub struct X;
"#)
.file("proc_macro_dep/Cargo.toml", r#"
[project]
name = "proc_macro_dep"
version = "0.1.0"
authors = []

[lib]
proc-macro = true

[dependencies]
bar = "^0.1"
"#)
.file("proc_macro_dep/src/lib.rs", r#"
extern crate bar;
extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro_derive(Noop)]
pub fn noop(_input: TokenStream) -> TokenStream {
"".parse().unwrap()
}
"#);
Package::new("foo", "0.1.0").publish();
Package::new("bar", "0.1.0")
.dep("foo", "0.1")
.file("src/lib.rs", "extern crate foo;")
.publish();
workspace.build();
assert_that(workspace.cargo("test").arg("--all").arg("--target").arg(rustc_host()),
execs().with_status(0));
}