Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3076959

Browse files
Move version string to RustcInfo, read '.rustc' section only once
1 parent bbaf4da commit 3076959

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

crates/proc-macro-api/src/version.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ pub struct RustCInfo {
1616
pub channel: String,
1717
pub commit: Option<String>,
1818
pub date: Option<String>,
19+
// something like "rustc 1.58.1 (db9d1b20b 2022-01-20)"
20+
pub version_string: String,
1921
}
2022

2123
/// Read rustc dylib information
@@ -68,7 +70,7 @@ pub fn read_dylib_info(dylib_path: &AbsPath) -> io::Result<RustCInfo> {
6870
}
6971
let version = (version_numbers[0], version_numbers[1], version_numbers[2]);
7072

71-
Ok(RustCInfo { version, channel, commit, date })
73+
Ok(RustCInfo { version, channel, commit, date, version_string: ver_str })
7274
}
7375

7476
/// This is used inside read_version() to locate the ".rustc" section

crates/proc-macro-srv/src/abis/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,13 @@ impl Abi {
7777
lib: &Library,
7878
symbol_name: String,
7979
info: RustCInfo,
80-
#[cfg_attr(not(feature = "sysroot-abi"), allow(unused_variables))] version_string: String,
8180
) -> Result<Abi, LoadProcMacroDylibError> {
8281
// the sysroot ABI relies on `extern proc_macro` with unstable features,
8382
// instead of a snapshot of the proc macro bridge's source code. it's only
8483
// enabled if we have an exact version match.
8584
#[cfg(feature = "sysroot-abi")]
8685
{
87-
if version_string == RUSTC_VERSION_STRING {
86+
if info.version_string == RUSTC_VERSION_STRING {
8887
let inner = unsafe { Abi_Sysroot::from_lib(lib, symbol_name) }?;
8988
return Ok(Abi::AbiSysroot(inner));
9089
}
@@ -104,7 +103,7 @@ impl Abi {
104103
} else {
105104
panic!(
106105
"sysroot ABI mismatch: dylib rustc version (read from .rustc section): {:?} != proc-macro-srv version (read from 'rustc --version'): {:?}",
107-
version_string, RUSTC_VERSION_STRING
106+
info.version_string, RUSTC_VERSION_STRING
108107
);
109108
}
110109
}

crates/proc-macro-srv/src/dylib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use libloading::Library;
1212
use memmap2::Mmap;
1313
use object::Object;
1414
use paths::AbsPath;
15-
use proc_macro_api::{read_dylib_info, read_version, ProcMacroKind};
15+
use proc_macro_api::{read_dylib_info, ProcMacroKind};
1616

1717
use super::abis::Abi;
1818

@@ -122,10 +122,9 @@ impl ProcMacroLibraryLibloading {
122122
invalid_data_err(format!("expected an absolute path, got {}", file.display()))
123123
})?;
124124
let version_info = read_dylib_info(abs_file)?;
125-
let version_string = read_version(abs_file)?;
126125

127126
let lib = load_library(file).map_err(invalid_data_err)?;
128-
let abi = Abi::from_lib(&lib, symbol_name, version_info, version_string)?;
127+
let abi = Abi::from_lib(&lib, symbol_name, version_info)?;
129128
Ok(ProcMacroLibraryLibloading { _lib: lib, abi })
130129
}
131130
}

0 commit comments

Comments
 (0)