Skip to content

Commit 7dc36ee

Browse files
committed
Auto merge of #12831 - fasterthanlime:proc-macro-test-in-tmp-dir, r=fasterthanlime
Build proc-macro-test-impl out-of-tree Building it in-place fails in rust CI because the source directory is read-only. This changes `proc-macro-test`'s build script to first copy `imp` under `OUT_DIR` (which is read-write). It also prints stdout/stderr for the nested cargo invocation, should it fail. (I've seen failures in rust CI that I couldn't explain, and when they take 25 minutes to reproduce, you want to have that info) This change is tracked in: * #12818 Maintainer impact: none.
2 parents bd4439f + 844aa8b commit 7dc36ee

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

crates/proc-macro-test/build.rs

+38-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,43 @@ use std::{
1212
use cargo_metadata::Message;
1313

1414
fn main() {
15+
println!("cargo:rerun-if-changed=imp");
16+
1517
let out_dir = env::var_os("OUT_DIR").unwrap();
1618
let out_dir = Path::new(&out_dir);
1719

1820
let name = "proc-macro-test-impl";
1921
let version = "0.0.0";
22+
23+
let imp_dir = std::env::current_dir().unwrap().join("imp");
24+
25+
let staging_dir = out_dir.join("proc-macro-test-imp-staging");
26+
// this'll error out if the staging dir didn't previously exist. using
27+
// `std::fs::exists` would suffer from TOCTOU so just do our best to
28+
// wipe it and ignore errors.
29+
let _ = std::fs::remove_dir_all(&staging_dir);
30+
31+
println!("Creating {}", staging_dir.display());
32+
std::fs::create_dir_all(&staging_dir).unwrap();
33+
34+
let src_dir = staging_dir.join("src");
35+
println!("Creating {}", src_dir.display());
36+
std::fs::create_dir_all(src_dir).unwrap();
37+
38+
for item_els in [&["Cargo.toml"][..], &["src", "lib.rs"]] {
39+
let mut src = imp_dir.clone();
40+
let mut dst = staging_dir.clone();
41+
for el in item_els {
42+
src.push(el);
43+
dst.push(el);
44+
}
45+
println!("Copying {} to {}", src.display(), dst.display());
46+
std::fs::copy(src, dst).unwrap();
47+
}
48+
2049
let target_dir = out_dir.join("target");
2150
let output = Command::new(toolchain::cargo())
22-
.current_dir("imp")
51+
.current_dir(&staging_dir)
2352
.args(&["build", "-p", "proc-macro-test-impl", "--message-format", "json"])
2453
// Explicit override the target directory to avoid using the same one which the parent
2554
// cargo is using, or we'll deadlock.
@@ -29,7 +58,14 @@ fn main() {
2958
.arg(&target_dir)
3059
.output()
3160
.unwrap();
32-
assert!(output.status.success());
61+
if !output.status.success() {
62+
println!("proc-macro-test-impl failed to build");
63+
println!("============ stdout ============");
64+
println!("{}", String::from_utf8_lossy(&output.stdout));
65+
println!("============ stderr ============");
66+
println!("{}", String::from_utf8_lossy(&output.stderr));
67+
panic!("proc-macro-test-impl failed to build");
68+
}
3369

3470
let mut artifact_path = None;
3571
for message in Message::parse_stream(output.stdout.as_slice()) {

0 commit comments

Comments
 (0)