Skip to content

Commit 6ae46a8

Browse files
committed
Auto merge of #4017 - Xanewok:wip-disambiguate-extern, r=oli-obk
compiletest: Disambiguate extern crate deps shared with the compiler Fixes #4015. changelog: Handle deps shared with the compiler in the internal compiletest suite Attempts to fix the multiple matching crates error using the `--extern dep=path` disambiguation. This only includes `serde` at the moment because it's the only problematic dep right now (is inside Rust sysroot and pulled via `extern crate` in the test suite). I'm not exactly sure this is the right approach (FWIW it fixes the issue locally), please do tell if this should be done differently.
2 parents d420589 + 56389f3 commit 6ae46a8

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

tests/compile-test.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,32 @@ fn config(mode: &str, dir: PathBuf) -> compiletest::Config {
4646
config.run_lib_path = rustc_lib_path();
4747
config.compile_lib_path = rustc_lib_path();
4848
}
49+
50+
// When we'll want to use `extern crate ..` for a dependency that is used
51+
// both by the crate and the compiler itself, we can't simply pass -L flags
52+
// as we'll get a duplicate matching versions. Instead, disambiguate with
53+
// `--extern dep=path`.
54+
// See https://github.com/rust-lang/rust-clippy/issues/4015.
55+
let needs_disambiguation = ["serde"];
56+
// This assumes that deps are compiled (they are for Cargo integration tests).
57+
let deps = std::fs::read_dir(host_libs().join("deps")).unwrap();
58+
let disambiguated = deps
59+
.filter_map(|dep| {
60+
let path = dep.ok()?.path();
61+
let name = path.file_name()?.to_string_lossy();
62+
// NOTE: This only handles a single dep
63+
// https://github.com/laumann/compiletest-rs/issues/101
64+
needs_disambiguation
65+
.iter()
66+
.find(|dep| name.starts_with(&format!("lib{}-", dep)))
67+
.map(|dep| format!("--extern {}={}", dep, path.display()))
68+
})
69+
.collect::<Vec<_>>();
70+
4971
config.target_rustcflags = Some(format!(
50-
"-L {0} -L {0}/deps -Dwarnings -Zui-testing",
51-
host_libs().display()
72+
"-L {0} -L {0}/deps -Dwarnings -Zui-testing {1}",
73+
host_libs().display(),
74+
disambiguated.join(" ")
5275
));
5376

5477
config.mode = cfg_mode;

0 commit comments

Comments
 (0)