Skip to content
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
1 change: 1 addition & 0 deletions src/cargo/core/compiler/build_runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
if unit.mode.is_doc_test() {
let mut unstable_opts = false;
let mut args = compiler::extern_args(&self, unit, &mut unstable_opts)?;
args.extend(compiler::lib_search_paths(&self, unit)?);
args.extend(compiler::lto_args(&self, unit));
args.extend(compiler::features_args(unit));
args.extend(compiler::check_cfg_args(unit));
Expand Down
68 changes: 38 additions & 30 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1700,37 +1700,9 @@ fn build_deps_args(
unit: &Unit,
) -> CargoResult<()> {
let bcx = build_runner.bcx;
if build_runner.bcx.gctx.cli_unstable().build_dir_new_layout {
let mut map = BTreeMap::new();

// Recursively add all dependency args to rustc process
add_dep_arg(&mut map, build_runner, unit);

let paths = map.into_iter().map(|(_, path)| path).sorted_unstable();

for path in paths {
cmd.arg("-L").arg(&{
let mut deps = OsString::from("dependency=");
deps.push(path);
deps
});
}
} else {
cmd.arg("-L").arg(&{
let mut deps = OsString::from("dependency=");
deps.push(build_runner.files().deps_dir(unit));
deps
});
}

// Be sure that the host path is also listed. This'll ensure that proc macro
// dependencies are correctly found (for reexported macros).
if !unit.kind.is_host() {
cmd.arg("-L").arg(&{
let mut deps = OsString::from("dependency=");
deps.push(build_runner.files().host_deps(unit));
deps
});
for arg in lib_search_paths(build_runner, unit)? {
cmd.arg(arg);
}

let deps = build_runner.unit_deps(unit);
Expand Down Expand Up @@ -1847,6 +1819,42 @@ fn add_custom_flags(
Ok(())
}

/// Generate a list of `-L` arguments
pub fn lib_search_paths(
build_runner: &BuildRunner<'_, '_>,
unit: &Unit,
) -> CargoResult<Vec<OsString>> {
let mut lib_search_paths = Vec::new();
if build_runner.bcx.gctx.cli_unstable().build_dir_new_layout {
let mut map = BTreeMap::new();

// Recursively add all dependency args to rustc process
add_dep_arg(&mut map, build_runner, unit);

let paths = map.into_iter().map(|(_, path)| path).sorted_unstable();

for path in paths {
let mut deps = OsString::from("dependency=");
deps.push(path);
lib_search_paths.extend(["-L".into(), deps]);
}
} else {
let mut deps = OsString::from("dependency=");
deps.push(build_runner.files().deps_dir(unit));
lib_search_paths.extend(["-L".into(), deps]);
}

// Be sure that the host path is also listed. This'll ensure that proc macro
// dependencies are correctly found (for reexported macros).
if !unit.kind.is_host() {
let mut deps = OsString::from("dependency=");
deps.push(build_runner.files().host_deps(unit));
lib_search_paths.extend(["-L".into(), deps]);
}

Ok(lib_search_paths)
}

/// Generates a list of `--extern` arguments.
pub fn extern_args(
build_runner: &BuildRunner<'_, '_>,
Expand Down
9 changes: 0 additions & 9 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,6 @@ fn run_doc_tests(
p.arg("-C").arg(format!("panic={}", unit.profile.panic));
}

for &rust_dep in &[
&compilation.deps_output[&unit.kind],
&compilation.deps_output[&CompileKind::Host],
] {
let mut arg = OsString::from("dependency=");
arg.push(rust_dep);
p.arg("-L").arg(arg);
}

for native_dep in compilation.native_dirs.iter() {
p.arg("-L").arg(native_dep);
}
Expand Down
70 changes: 70 additions & 0 deletions tests/testsuite/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2562,6 +2562,76 @@ fn doctest_dev_dep() {
p.cargo("test -v").run();
}

#[cargo_test]
fn doctest_dep() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []

[dependencies]
b = { path = "b" }
"#,
)
.file(
"src/lib.rs",
r#"
/// ```
/// foo::foo();
/// ```
pub fn foo() {
b::bar();
}
"#,
)
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
.file("b/src/lib.rs", "pub fn bar() {}")
.build();

p.cargo("test -v").run();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: -v verbose is not needed perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test I modeled it after did it and it helped as I debugged it. We aren't needing to test output so it doesn't make testing any more difficult.

}

#[cargo_test]
fn doctest_dep_new_layout() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []

[dependencies]
b = { path = "b" }
"#,
)
.file(
"src/lib.rs",
r#"
/// ```
/// foo::foo();
/// ```
pub fn foo() {
b::bar();
}
"#,
)
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
.file("b/src/lib.rs", "pub fn bar() {}")
.build();

p.cargo("-Zbuild-dir-new-layout test")
.masquerade_as_nightly_cargo(&["new build-dir layout"])
.run();
}

#[cargo_test]
fn filter_no_doc_tests() {
let p = project()
Expand Down