Unnamed repository; edit this file 'description' to name the repository.
Move proc-macro-srv RUSTC_VERSION fetching from include to env var
Lukas Wirth 2024-06-30
parent 21a3d01 · commit 23b043a
-rw-r--r--crates/proc-macro-srv/build.rs16
-rw-r--r--crates/proc-macro-srv/src/lib.rs3
2 files changed, 3 insertions, 16 deletions
diff --git a/crates/proc-macro-srv/build.rs b/crates/proc-macro-srv/build.rs
index 874d1c6cd3..44511d44b3 100644
--- a/crates/proc-macro-srv/build.rs
+++ b/crates/proc-macro-srv/build.rs
@@ -4,24 +4,12 @@
use std::{env, fs::File, io::Write, path::PathBuf, process::Command};
fn main() {
- println!("cargo:rustc-check-cfg=cfg(rust_analyzer)");
-
- let mut path = PathBuf::from(env::var_os("OUT_DIR").unwrap());
- path.push("rustc_version.rs");
- let mut f = File::create(&path).unwrap();
+ println!("cargo::rustc-check-cfg=cfg(rust_analyzer)");
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();
+ println!("cargo::rustc-env=RUSTC_VERSION={}", version_string);
}
diff --git a/crates/proc-macro-srv/src/lib.rs b/crates/proc-macro-srv/src/lib.rs
index b86dceeb50..8bc308fce9 100644
--- a/crates/proc-macro-srv/src/lib.rs
+++ b/crates/proc-macro-srv/src/lib.rs
@@ -48,8 +48,7 @@ use span::Span;
use crate::server::TokenStream;
-// see `build.rs`
-include!(concat!(env!("OUT_DIR"), "/rustc_version.rs"));
+pub const RUSTC_VERSION_STRING: &str = env!("RUSTC_VERSION");
trait ProcMacroSrvSpan: Copy {
type Server: proc_macro::bridge::server::Server<TokenStream = TokenStream<Self>>;