fdddd83224
Otherwise, fall back to the multi ABI scheme, except in testing, where it becomes a hard error. This should make it possible to use a rustup-provided rust-analyzer with proc macro dylibs compiled by older rustcs, and it'll also catch changes to the format of `rustc --version` or the `.rustc` section that would make them impossible to compare for equality.
26 lines
875 B
Rust
26 lines
875 B
Rust
use std::{env, fs::File, io::Write, path::PathBuf, process::Command};
|
|
|
|
fn main() {
|
|
// Determine rustc version `proc-macro-srv` (and thus the sysroot ABI) is
|
|
// build with and make it accessible at runtime for ABI selection.
|
|
|
|
let mut path = PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
|
path.push("rustc_version.rs");
|
|
let mut f = File::create(&path).unwrap();
|
|
|
|
let rustc = env::var("RUSTC").expect("proc-macro-srv's build script expects RUSTC to be set");
|
|
let output = Command::new(rustc).arg("--version").output().expect("rustc --version must run");
|
|
let version_string = std::str::from_utf8(&output.stdout[..])
|
|
.expect("rustc --version output must be UTF-8")
|
|
.trim();
|
|
|
|
write!(
|
|
f,
|
|
"
|
|
#[allow(dead_code)]
|
|
pub(crate) const RUSTC_VERSION_STRING: &str = {version_string:?};
|
|
"
|
|
)
|
|
.unwrap();
|
|
}
|