Skip to content

Commit 3468918

Browse files
committed
Auto merge of #6327 - ehuss:add_plugin_deps-tests, r=alexcrichton
Fix add_plugin_deps-related tests. These tests were modified in #3974 in such a way that they stopped testing the `add_plugin_deps` code path. The tests can't be directly reverted because #3651 changed it so that dylib paths must be within the root output directory. I compromised by just copying the dylib into `$OUT_DIR`. Closes #6318.
2 parents ebd0ef1 + 83ff57a commit 3468918

File tree

2 files changed

+35
-45
lines changed

2 files changed

+35
-45
lines changed

tests/testsuite/build_script.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,18 +1376,8 @@ fn test_dev_dep_build_script() {
13761376

13771377
#[test]
13781378
fn build_script_with_dynamic_native_dependency() {
1379-
let _workspace = project()
1380-
.at("ws")
1381-
.file(
1382-
"Cargo.toml",
1383-
r#"
1384-
[workspace]
1385-
members = ["builder", "foo"]
1386-
"#,
1387-
).build();
1388-
13891379
let build = project()
1390-
.at("ws/builder")
1380+
.at("builder")
13911381
.file(
13921382
"Cargo.toml",
13931383
r#"
@@ -1399,13 +1389,11 @@ fn build_script_with_dynamic_native_dependency() {
13991389
[lib]
14001390
name = "builder"
14011391
crate-type = ["dylib"]
1402-
plugin = true
14031392
"#,
14041393
).file("src/lib.rs", "#[no_mangle] pub extern fn foo() {}")
14051394
.build();
14061395

14071396
let foo = project()
1408-
.at("ws/foo")
14091397
.file(
14101398
"Cargo.toml",
14111399
r#"
@@ -1433,12 +1421,23 @@ fn build_script_with_dynamic_native_dependency() {
14331421
"bar/build.rs",
14341422
r#"
14351423
use std::env;
1424+
use std::fs;
14361425
use std::path::PathBuf;
14371426
14381427
fn main() {
1439-
let src = PathBuf::from(env::var("SRC").unwrap());
1440-
println!("cargo:rustc-link-search=native={}/target/debug/deps",
1441-
src.display());
1428+
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
1429+
let root = PathBuf::from(env::var("BUILDER_ROOT").unwrap());
1430+
let file = format!("{}builder{}",
1431+
env::consts::DLL_PREFIX,
1432+
env::consts::DLL_SUFFIX);
1433+
let src = root.join(&file);
1434+
let dst = out_dir.join(&file);
1435+
fs::copy(src, dst).unwrap();
1436+
if cfg!(windows) {
1437+
fs::copy(root.join("builder.dll.lib"),
1438+
out_dir.join("builder.dll.lib")).unwrap();
1439+
}
1440+
println!("cargo:rustc-link-search=native={}", out_dir.display());
14421441
}
14431442
"#,
14441443
).file(
@@ -1458,8 +1457,9 @@ fn build_script_with_dynamic_native_dependency() {
14581457
.env("RUST_LOG", "cargo::ops::cargo_rustc")
14591458
.run();
14601459

1460+
let root = build.root().join("target").join("debug");
14611461
foo.cargo("build -v")
1462-
.env("SRC", build.root())
1462+
.env("BUILDER_ROOT", root)
14631463
.env("RUST_LOG", "cargo::ops::cargo_rustc")
14641464
.run();
14651465
}

tests/testsuite/plugins.rs

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use std::env;
2-
use std::fs;
3-
41
use support::{basic_manifest, project};
52
use support::{is_nightly, rustc_host};
63

@@ -103,18 +100,8 @@ fn plugin_with_dynamic_native_dependency() {
103100
return;
104101
}
105102

106-
let workspace = project()
107-
.at("ws")
108-
.file(
109-
"Cargo.toml",
110-
r#"
111-
[workspace]
112-
members = ["builder", "foo"]
113-
"#,
114-
).build();
115-
116103
let build = project()
117-
.at("ws/builder")
104+
.at("builder")
118105
.file(
119106
"Cargo.toml",
120107
r#"
@@ -131,7 +118,6 @@ fn plugin_with_dynamic_native_dependency() {
131118
.build();
132119

133120
let foo = project()
134-
.at("ws/foo")
135121
.file(
136122
"Cargo.toml",
137123
r#"
@@ -167,12 +153,24 @@ fn plugin_with_dynamic_native_dependency() {
167153
).file(
168154
"bar/build.rs",
169155
r#"
170-
use std::path::PathBuf;
171156
use std::env;
157+
use std::fs;
158+
use std::path::PathBuf;
172159
173160
fn main() {
174-
let src = PathBuf::from(env::var("SRC").unwrap());
175-
println!("cargo:rustc-flags=-L {}/deps", src.parent().unwrap().display());
161+
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
162+
let root = PathBuf::from(env::var("BUILDER_ROOT").unwrap());
163+
let file = format!("{}builder{}",
164+
env::consts::DLL_PREFIX,
165+
env::consts::DLL_SUFFIX);
166+
let src = root.join(&file);
167+
let dst = out_dir.join(&file);
168+
fs::copy(src, dst).unwrap();
169+
if cfg!(windows) {
170+
fs::copy(root.join("builder.dll.lib"),
171+
out_dir.join("builder.dll.lib")).unwrap();
172+
}
173+
println!("cargo:rustc-flags=-L {}", out_dir.display());
176174
}
177175
"#,
178176
).file(
@@ -196,16 +194,8 @@ fn plugin_with_dynamic_native_dependency() {
196194

197195
build.cargo("build").run();
198196

199-
let src = workspace.root().join("target/debug");
200-
let lib = fs::read_dir(&src)
201-
.unwrap()
202-
.map(|s| s.unwrap().path())
203-
.find(|lib| {
204-
let lib = lib.file_name().unwrap().to_str().unwrap();
205-
lib.starts_with(env::consts::DLL_PREFIX) && lib.ends_with(env::consts::DLL_SUFFIX)
206-
}).unwrap();
207-
208-
foo.cargo("build -v").env("SRC", &lib).run();
197+
let root = build.root().join("target").join("debug");
198+
foo.cargo("build -v").env("BUILDER_ROOT", root).run();
209199
}
210200

211201
#[test]

0 commit comments

Comments
 (0)