diff options
| author | bors <bors@rust-lang.org> | 2022-07-20 16:04:23 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-07-20 16:04:23 +0000 |
| commit | fa883cb64715fb89c0ce673ee8bf5a141893d5da (patch) | |
| tree | d38ebe8d0914b5ac20cf5e3f51e4d46070a18c43 | |
| parent | cd2c2406c0c5a11d3e998998845ca5c8be683676 (diff) | |
| parent | dcd52ec327a72ed0ff9708b84e8384591f697224 (diff) | |
| download | rust-fa883cb64715fb89c0ce673ee8bf5a141893d5da.tar.gz rust-fa883cb64715fb89c0ce673ee8bf5a141893d5da.zip | |
Auto merge of #12834 - fasterthanlime:proc-macro-test-toolchain, r=Veykril
Add PROC_MACRO_TEST_TOOLCHAIN environment variable
This allows overriding the toolchain used to run `proc-macro-srv` tests.
---
Sample usage.
Testing the current ABI (variable unset/empty):
```shell
amos@tails ~/bearcove/rust-analyzer/crates/proc-macro-srv proc-macro-test-toolchain*
❯ PROC_MACRO_TEST_TOOLCHAIN="" cargo test --quiet
running 16 tests
................
test result: ok. 16 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s
```
Testing an older ABI:
```shell
amos@tails ~/bearcove/rust-analyzer/crates/proc-macro-srv proc-macro-test-toolchain*
❯ PROC_MACRO_TEST_TOOLCHAIN="1.58" cargo test --quiet
running 16 tests
................
test result: ok. 16 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s
```
Testing current nightly ABI:
```shell
❯ rustc +nightly --version
rustc 1.64.0-nightly (f8588549c 2022-07-18)
❯ PROC_MACRO_TEST_TOOLCHAIN="nightly" cargo test --quiet
running 16 tests
................
test result: ok. 16 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s
```
Testing future ABI (`rust-lang/rust` master):
```shell
amos@tails ~/bearcove/rust-analyzer/crates/proc-macro-srv proc-macro-test-toolchain
❯ PROC_MACRO_TEST_TOOLCHAIN="stage1" cargo test --quiet
running 16 tests
..........thread '<unnamed>' panicked at 'range end index 216221164920373249 out of range for slice of length 18', library/core/src/slice/index.rs:73:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
....F.
failures:
---- tests::test_fn_like_macro2 stdout ----
thread 'tests::test_fn_like_macro2' panicked at 'called `Result::unwrap()` on an `Err` value: "range end index 216221164920373249 out of range for slice of length 18"', crates/proc-macro-srv/src/tests/utils.rs:38:83
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
tests::test_fn_like_macro2
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--lib
```
---
Tagging `@jonas-schievink:` this might be helpful when updating versioned ABIs later on.
| -rw-r--r-- | crates/proc-macro-test/build.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/crates/proc-macro-test/build.rs b/crates/proc-macro-test/build.rs index c6bd5160d4d..cd99eea5ae3 100644 --- a/crates/proc-macro-test/build.rs +++ b/crates/proc-macro-test/build.rs @@ -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, @@ -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); @@ -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 |
