]> git.lizzy.rs Git - rust.git/commitdiff
Move version string to RustcInfo, read '.rustc' section only once
authorAmos Wenger <amoswenger@gmail.com>
Thu, 21 Jul 2022 11:57:36 +0000 (13:57 +0200)
committerAmos Wenger <amoswenger@gmail.com>
Thu, 21 Jul 2022 11:57:36 +0000 (13:57 +0200)
crates/proc-macro-api/src/version.rs
crates/proc-macro-srv/src/abis/mod.rs
crates/proc-macro-srv/src/dylib.rs

index 8cef971f3325537514f071bb8785b3170884fb8a..030531b80d7bb0d7b511a6e1ba00016561a846c9 100644 (file)
@@ -16,6 +16,8 @@ pub struct RustCInfo {
     pub channel: String,
     pub commit: Option<String>,
     pub date: Option<String>,
+    // something like "rustc 1.58.1 (db9d1b20b 2022-01-20)"
+    pub version_string: String,
 }
 
 /// Read rustc dylib information
@@ -68,7 +70,7 @@ macro_rules! err {
     }
     let version = (version_numbers[0], version_numbers[1], version_numbers[2]);
 
-    Ok(RustCInfo { version, channel, commit, date })
+    Ok(RustCInfo { version, channel, commit, date, version_string: ver_str })
 }
 
 /// This is used inside read_version() to locate the ".rustc" section
index a59da0f6b10bbdd9ed0ff79260f2861d4312ad26..bcf3f1184cf6515dd8844f54833eb25e5ce0dd71 100644 (file)
@@ -77,14 +77,13 @@ pub fn from_lib(
         lib: &Library,
         symbol_name: String,
         info: RustCInfo,
-        #[cfg_attr(not(feature = "sysroot-abi"), allow(unused_variables))] version_string: String,
     ) -> Result<Abi, LoadProcMacroDylibError> {
         // the sysroot ABI relies on `extern proc_macro` with unstable features,
         // instead of a snapshot of the proc macro bridge's source code. it's only
         // enabled if we have an exact version match.
         #[cfg(feature = "sysroot-abi")]
         {
-            if version_string == RUSTC_VERSION_STRING {
+            if info.version_string == RUSTC_VERSION_STRING {
                 let inner = unsafe { Abi_Sysroot::from_lib(lib, symbol_name) }?;
                 return Ok(Abi::AbiSysroot(inner));
             }
@@ -104,7 +103,7 @@ pub fn from_lib(
                 } else {
                     panic!(
                         "sysroot ABI mismatch: dylib rustc version (read from .rustc section): {:?} != proc-macro-srv version (read from 'rustc --version'): {:?}",
-                        version_string, RUSTC_VERSION_STRING
+                        info.version_string, RUSTC_VERSION_STRING
                     );
                 }
             }
index 6439fb2130bce46101f5eccc9212df8dda21f69d..2b6c070fece3f746c0ca48e6c2940e8c801d5ea1 100644 (file)
@@ -12,7 +12,7 @@
 use memmap2::Mmap;
 use object::Object;
 use paths::AbsPath;
-use proc_macro_api::{read_dylib_info, read_version, ProcMacroKind};
+use proc_macro_api::{read_dylib_info, ProcMacroKind};
 
 use super::abis::Abi;
 
@@ -122,10 +122,9 @@ fn open(file: &Path) -> Result<Self, LoadProcMacroDylibError> {
             invalid_data_err(format!("expected an absolute path, got {}", file.display()))
         })?;
         let version_info = read_dylib_info(abs_file)?;
-        let version_string = read_version(abs_file)?;
 
         let lib = load_library(file).map_err(invalid_data_err)?;
-        let abi = Abi::from_lib(&lib, symbol_name, version_info, version_string)?;
+        let abi = Abi::from_lib(&lib, symbol_name, version_info)?;
         Ok(ProcMacroLibraryLibloading { _lib: lib, abi })
     }
 }