1 //! This will build the proc macro in `imp`, and copy the resulting dylib artifact into the
4 //! `proc_macro_test` itself contains only a path to that artifact.
12 use cargo_metadata::Message;
15 let out_dir = env::var_os("OUT_DIR").unwrap();
16 let out_dir = Path::new(&out_dir);
18 let name = "proc_macro_test_impl";
19 let version = "0.0.0";
20 let target_dir = out_dir.join("target");
21 let output = Command::new(toolchain::cargo())
23 .args(&["build", "-p", "proc_macro_test_impl", "--message-format", "json"])
24 // Explicit override the target directory to avoid using the same one which the parent
25 // cargo is using, or we'll deadlock.
26 // This can happen when `CARGO_TARGET_DIR` is set or global config forces all cargo
27 // instance to use the same target directory.
32 assert!(output.status.success());
34 let mut artifact_path = None;
35 for message in Message::parse_stream(output.stdout.as_slice()) {
36 match message.unwrap() {
37 Message::CompilerArtifact(artifact) => {
38 if artifact.target.kind.contains(&"proc-macro".to_string()) {
39 let repr = format!("{} {}", name, version);
40 if artifact.package_id.repr.starts_with(&repr) {
41 artifact_path = Some(PathBuf::from(&artifact.filenames[0]));
45 _ => (), // Unknown message
49 // This file is under `target_dir` and is already under `OUT_DIR`.
50 let artifact_path = artifact_path.expect("no dylib for proc_macro_test_impl found");
52 let info_path = out_dir.join("proc_macro_test_location.txt");
53 fs::write(info_path, artifact_path.to_str().unwrap()).unwrap();