mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 07:04:22 +00:00
Move version string to RustcInfo, read '.rustc' section only once
This commit is contained in:
parent
bbaf4daca0
commit
30769598a4
3 changed files with 7 additions and 7 deletions
|
@ -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 @@ pub fn read_dylib_info(dylib_path: &AbsPath) -> io::Result<RustCInfo> {
|
|||
}
|
||||
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
|
||||
|
|
|
@ -77,14 +77,13 @@ impl Abi {
|
|||
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 @@ impl Abi {
|
|||
} 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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use libloading::Library;
|
|||
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 @@ impl ProcMacroLibraryLibloading {
|
|||
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 })
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue