Skip to content

Commit a88e088

Browse files
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)
1 parent bd4439f commit a88e088

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

crates/proc-macro-test/build.rs

+25-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,25 @@ fn main() {
1717

1818
let name = "proc-macro-test-impl";
1919
let version = "0.0.0";
20+
21+
let imp_dir = std::env::current_dir().unwrap().join("imp");
22+
let staging_dir = out_dir.join("staging");
23+
std::fs::create_dir_all(&staging_dir).unwrap();
24+
std::fs::create_dir_all(staging_dir.join("src")).unwrap();
25+
26+
for item_els in [&["Cargo.toml"][..], &["Cargo.lock"], &["src", "lib.rs"]] {
27+
let mut src = imp_dir.clone();
28+
let mut dst = staging_dir.clone();
29+
for el in item_els {
30+
src.push(el);
31+
dst.push(el);
32+
}
33+
std::fs::copy(src, dst).unwrap();
34+
}
35+
2036
let target_dir = out_dir.join("target");
2137
let output = Command::new(toolchain::cargo())
22-
.current_dir("imp")
38+
.current_dir(&staging_dir)
2339
.args(&["build", "-p", "proc-macro-test-impl", "--message-format", "json"])
2440
// Explicit override the target directory to avoid using the same one which the parent
2541
// cargo is using, or we'll deadlock.
@@ -29,7 +45,14 @@ fn main() {
2945
.arg(&target_dir)
3046
.output()
3147
.unwrap();
32-
assert!(output.status.success());
48+
if !output.status.success() {
49+
println!("proc-macro-test-impl failed to build");
50+
println!("============ stdout ============");
51+
println!("{}", String::from_utf8_lossy(&output.stdout));
52+
println!("============ stderr ============");
53+
println!("{}", String::from_utf8_lossy(&output.stderr));
54+
panic!("proc-macro-test-impl failed to build");
55+
}
3356

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

0 commit comments

Comments
 (0)