From a88e088fa782820c7a594bbdff2eae011f5f286d Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Wed, 20 Jul 2022 16:14:53 +0200 Subject: [PATCH 1/5] 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) --- crates/proc-macro-test/build.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/proc-macro-test/build.rs b/crates/proc-macro-test/build.rs index 767a790437e..8e13563c14e 100644 --- a/crates/proc-macro-test/build.rs +++ b/crates/proc-macro-test/build.rs @@ -17,9 +17,25 @@ fn main() { let name = "proc-macro-test-impl"; let version = "0.0.0"; + + let imp_dir = std::env::current_dir().unwrap().join("imp"); + let staging_dir = out_dir.join("staging"); + std::fs::create_dir_all(&staging_dir).unwrap(); + std::fs::create_dir_all(staging_dir.join("src")).unwrap(); + + for item_els in [&["Cargo.toml"][..], &["Cargo.lock"], &["src", "lib.rs"]] { + let mut src = imp_dir.clone(); + let mut dst = staging_dir.clone(); + for el in item_els { + src.push(el); + dst.push(el); + } + std::fs::copy(src, dst).unwrap(); + } + let target_dir = out_dir.join("target"); let output = Command::new(toolchain::cargo()) - .current_dir("imp") + .current_dir(&staging_dir) .args(&["build", "-p", "proc-macro-test-impl", "--message-format", "json"]) // Explicit override the target directory to avoid using the same one which the parent // cargo is using, or we'll deadlock. @@ -29,7 +45,14 @@ fn main() { .arg(&target_dir) .output() .unwrap(); - assert!(output.status.success()); + if !output.status.success() { + println!("proc-macro-test-impl failed to build"); + println!("============ stdout ============"); + println!("{}", String::from_utf8_lossy(&output.stdout)); + println!("============ stderr ============"); + println!("{}", String::from_utf8_lossy(&output.stderr)); + panic!("proc-macro-test-impl failed to build"); + } let mut artifact_path = None; for message in Message::parse_stream(output.stdout.as_slice()) { From 4375cf365e0355ad81eeedb7592d87999710bda6 Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Wed, 20 Jul 2022 16:22:48 +0200 Subject: [PATCH 2/5] proc-macro-test build script: wipe before, be more verbose --- crates/proc-macro-test/build.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/proc-macro-test/build.rs b/crates/proc-macro-test/build.rs index 8e13563c14e..cec2f87b327 100644 --- a/crates/proc-macro-test/build.rs +++ b/crates/proc-macro-test/build.rs @@ -12,6 +12,8 @@ use std::{ use cargo_metadata::Message; fn main() { + println!("cargo:rerun-if-changed=imp"); + let out_dir = env::var_os("OUT_DIR").unwrap(); let out_dir = Path::new(&out_dir); @@ -19,9 +21,19 @@ fn main() { let version = "0.0.0"; let imp_dir = std::env::current_dir().unwrap().join("imp"); - let staging_dir = out_dir.join("staging"); + + let staging_dir = out_dir.join("proc-macro-test-imp-staging"); + // this'll error out if the staging dir didn't previously. using + // `std::fs::exists` would suffer from TOCTOU so just do our best to + // wip it and ignore errors. + let _ = std::fs::remove_dir_all(&staging_dir); + + println!("Creating {}", staging_dir.display()); std::fs::create_dir_all(&staging_dir).unwrap(); - std::fs::create_dir_all(staging_dir.join("src")).unwrap(); + + let src_dir = staging_dir.join("src"); + println!("Creating {}", src_dir.display()); + std::fs::create_dir_all(src_dir).unwrap(); for item_els in [&["Cargo.toml"][..], &["Cargo.lock"], &["src", "lib.rs"]] { let mut src = imp_dir.clone(); @@ -30,6 +42,7 @@ fn main() { src.push(el); dst.push(el); } + println!("Copying {} to {}", src.display(), dst.display()); std::fs::copy(src, dst).unwrap(); } From 898898df89f8519741b0f04ed0e9d83276c6c396 Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Wed, 20 Jul 2022 16:30:08 +0200 Subject: [PATCH 3/5] Don't copy the Cargo.lock --- crates/proc-macro-test/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/proc-macro-test/build.rs b/crates/proc-macro-test/build.rs index cec2f87b327..5502e3ba7c9 100644 --- a/crates/proc-macro-test/build.rs +++ b/crates/proc-macro-test/build.rs @@ -35,7 +35,7 @@ fn main() { println!("Creating {}", src_dir.display()); std::fs::create_dir_all(src_dir).unwrap(); - for item_els in [&["Cargo.toml"][..], &["Cargo.lock"], &["src", "lib.rs"]] { + for item_els in [&["Cargo.toml"][..], &["src", "lib.rs"]] { let mut src = imp_dir.clone(); let mut dst = staging_dir.clone(); for el in item_els { From 9a8efe235f28e67521a620713b4ad23b2b4bd48f Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Wed, 20 Jul 2022 16:56:25 +0200 Subject: [PATCH 4/5] Update crates/proc-macro-test/build.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Laurențiu Nicola --- crates/proc-macro-test/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/proc-macro-test/build.rs b/crates/proc-macro-test/build.rs index 5502e3ba7c9..9e92b5de9ec 100644 --- a/crates/proc-macro-test/build.rs +++ b/crates/proc-macro-test/build.rs @@ -25,7 +25,7 @@ fn main() { let staging_dir = out_dir.join("proc-macro-test-imp-staging"); // this'll error out if the staging dir didn't previously. using // `std::fs::exists` would suffer from TOCTOU so just do our best to - // wip it and ignore errors. + // wipe it and ignore errors. let _ = std::fs::remove_dir_all(&staging_dir); println!("Creating {}", staging_dir.display()); From 844aa8b53e47934e30bff1ba9f70a0986874ae97 Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Wed, 20 Jul 2022 16:56:30 +0200 Subject: [PATCH 5/5] Update crates/proc-macro-test/build.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Laurențiu Nicola --- crates/proc-macro-test/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/proc-macro-test/build.rs b/crates/proc-macro-test/build.rs index 9e92b5de9ec..c6bd5160d4d 100644 --- a/crates/proc-macro-test/build.rs +++ b/crates/proc-macro-test/build.rs @@ -23,7 +23,7 @@ fn main() { let imp_dir = std::env::current_dir().unwrap().join("imp"); let staging_dir = out_dir.join("proc-macro-test-imp-staging"); - // this'll error out if the staging dir didn't previously. using + // this'll error out if the staging dir didn't previously exist. using // `std::fs::exists` would suffer from TOCTOU so just do our best to // wipe it and ignore errors. let _ = std::fs::remove_dir_all(&staging_dir);