Skip to content

Add PROC_MACRO_TEST_TOOLCHAIN environment variable #12834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion crates/proc-macro-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
//! `OUT_DIR`.
//!
//! `proc-macro-test` itself contains only a path to that artifact.
//!
//! The `PROC_MACRO_TEST_TOOLCHAIN` environment variable can be exported to use
//! a specific rustup toolchain: this allows testing against older ABIs (e.g.
//! 1.58) and future ABIs (stage1, nightly)

use std::{
env, fs,
Expand All @@ -13,6 +17,7 @@ use cargo_metadata::Message;

fn main() {
println!("cargo:rerun-if-changed=imp");
println!("cargo:rerun-if-env-changed=PROC_MACRO_TEST_TOOLCHAIN");

let out_dir = env::var_os("OUT_DIR").unwrap();
let out_dir = Path::new(&out_dir);
Expand Down Expand Up @@ -47,7 +52,17 @@ fn main() {
}

let target_dir = out_dir.join("target");
let output = Command::new(toolchain::cargo())

let mut cmd = if let Ok(toolchain) = std::env::var("PROC_MACRO_TEST_TOOLCHAIN") {
// leverage rustup to find user-specific toolchain
let mut cmd = Command::new("cargo");
cmd.arg(format!("+{toolchain}"));
cmd
} else {
Command::new(toolchain::cargo())
};

let output = cmd
.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
Expand Down