mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 07:04:22 +00:00
Move dylib version stuff to proc-macro-srv
This commit is contained in:
parent
5374ebbf36
commit
db15273d4d
8 changed files with 36 additions and 33 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -1329,13 +1329,10 @@ dependencies = [
|
|||
"base-db",
|
||||
"indexmap",
|
||||
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memmap2",
|
||||
"object 0.33.0",
|
||||
"paths",
|
||||
"rustc-hash",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"snap",
|
||||
"span",
|
||||
"stdx",
|
||||
"text-size",
|
||||
|
@ -1358,6 +1355,7 @@ dependencies = [
|
|||
"proc-macro-api",
|
||||
"proc-macro-test",
|
||||
"ra-ap-rustc_lexer",
|
||||
"snap",
|
||||
"span",
|
||||
"stdx",
|
||||
"tt",
|
||||
|
|
|
@ -120,6 +120,8 @@ hashbrown = { version = "0.14", features = [
|
|||
indexmap = "2.1.0"
|
||||
itertools = "0.12.0"
|
||||
libc = "0.2.150"
|
||||
libloading = "0.8.0"
|
||||
memmap2 = "0.5.4"
|
||||
nohash-hasher = "0.2.0"
|
||||
oorandom = "11.1.3"
|
||||
object = { version = "0.33.0", default-features = false, features = [
|
||||
|
@ -143,6 +145,7 @@ smallvec = { version = "1.10.0", features = [
|
|||
"const_generics",
|
||||
] }
|
||||
smol_str = "0.2.1"
|
||||
snap = "1.1.0"
|
||||
text-size = "1.1.1"
|
||||
tracing = "0.1.40"
|
||||
tracing-tree = "0.3.0"
|
||||
|
@ -156,6 +159,7 @@ url = "2.3.1"
|
|||
xshell = "0.2.5"
|
||||
|
||||
|
||||
|
||||
# We need to freeze the version of the crate, as the raw-api feature is considered unstable
|
||||
dashmap = { version = "=5.5.3", features = ["raw-api"] }
|
||||
|
||||
|
|
|
@ -12,15 +12,12 @@ rust-version.workspace = true
|
|||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
object.workspace = true
|
||||
serde.workspace = true
|
||||
serde_json = { workspace = true, features = ["unbounded_depth"] }
|
||||
tracing.workspace = true
|
||||
triomphe.workspace = true
|
||||
rustc-hash.workspace = true
|
||||
memmap2 = "0.5.4"
|
||||
snap = "1.1.0"
|
||||
indexmap = "2.1.0"
|
||||
indexmap.workspace = true
|
||||
|
||||
# local deps
|
||||
paths = { workspace = true, features = ["serde1"] }
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
pub mod msg;
|
||||
mod process;
|
||||
mod version;
|
||||
|
||||
use base_db::Env;
|
||||
use indexmap::IndexSet;
|
||||
|
@ -31,8 +30,6 @@ use crate::{
|
|||
process::ProcMacroProcessSrv,
|
||||
};
|
||||
|
||||
pub use version::{read_dylib_info, read_version, RustCInfo};
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
|
||||
pub enum ProcMacroKind {
|
||||
CustomDerive,
|
||||
|
|
|
@ -13,8 +13,9 @@ doctest = false
|
|||
|
||||
[dependencies]
|
||||
object.workspace = true
|
||||
libloading = "0.8.0"
|
||||
memmap2 = "0.5.4"
|
||||
libloading.workspace = true
|
||||
memmap2.workspace = true
|
||||
snap.workspace = true
|
||||
|
||||
stdx.workspace = true
|
||||
tt.workspace = true
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
//! Handles dynamic library loading for proc macro
|
||||
|
||||
mod version;
|
||||
|
||||
use std::{fmt, fs::File, io};
|
||||
|
||||
use libloading::Library;
|
||||
|
@ -7,7 +9,7 @@ use memmap2::Mmap;
|
|||
use object::Object;
|
||||
use paths::{AbsPath, Utf8Path, Utf8PathBuf};
|
||||
use proc_macro::bridge;
|
||||
use proc_macro_api::{read_dylib_info, ProcMacroKind};
|
||||
use proc_macro_api::ProcMacroKind;
|
||||
|
||||
use crate::ProcMacroSrvSpan;
|
||||
|
||||
|
@ -119,11 +121,14 @@ impl ProcMacroLibraryLibloading {
|
|||
let abs_file: &AbsPath = file
|
||||
.try_into()
|
||||
.map_err(|_| invalid_data_err(format!("expected an absolute path, got {file}")))?;
|
||||
let version_info = read_dylib_info(abs_file)?;
|
||||
let version_info = version::read_dylib_info(abs_file)?;
|
||||
|
||||
let lib = load_library(file).map_err(invalid_data_err)?;
|
||||
let proc_macros =
|
||||
crate::proc_macros::ProcMacros::from_lib(&lib, symbol_name, version_info)?;
|
||||
let proc_macros = crate::proc_macros::ProcMacros::from_lib(
|
||||
&lib,
|
||||
symbol_name,
|
||||
&version_info.version_string,
|
||||
)?;
|
||||
Ok(ProcMacroLibraryLibloading { _lib: lib, proc_macros })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ use paths::AbsPath;
|
|||
use snap::read::FrameDecoder as SnapDecoder;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)]
|
||||
pub struct RustCInfo {
|
||||
pub version: (usize, usize, usize),
|
||||
pub channel: String,
|
||||
|
@ -164,3 +165,16 @@ pub fn read_version(dylib_path: &AbsPath) -> io::Result<String> {
|
|||
let version_string = String::from_utf8(version_string_utf8);
|
||||
version_string.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_version_check() {
|
||||
let path = paths::AbsPathBuf::assert(crate::proc_macro_test_dylib_path());
|
||||
let info = read_dylib_info(&path).unwrap();
|
||||
assert_eq!(
|
||||
info.version_string,
|
||||
crate::RUSTC_VERSION_STRING,
|
||||
"sysroot ABI mismatch: dylib rustc version (read from .rustc section): {:?} != proc-macro-srv version (read from 'rustc --version'): {:?}",
|
||||
info.version_string,
|
||||
crate::RUSTC_VERSION_STRING,
|
||||
);
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use libloading::Library;
|
||||
use proc_macro::bridge;
|
||||
use proc_macro_api::{ProcMacroKind, RustCInfo};
|
||||
use proc_macro_api::ProcMacroKind;
|
||||
|
||||
use crate::{dylib::LoadProcMacroDylibError, ProcMacroSrvSpan};
|
||||
|
||||
|
@ -29,15 +29,15 @@ impl ProcMacros {
|
|||
pub(crate) fn from_lib(
|
||||
lib: &Library,
|
||||
symbol_name: String,
|
||||
info: RustCInfo,
|
||||
version_string: &str,
|
||||
) -> Result<ProcMacros, LoadProcMacroDylibError> {
|
||||
if info.version_string == crate::RUSTC_VERSION_STRING {
|
||||
if version_string == crate::RUSTC_VERSION_STRING {
|
||||
let macros =
|
||||
unsafe { lib.get::<&&[bridge::client::ProcMacro]>(symbol_name.as_bytes()) }?;
|
||||
|
||||
return Ok(Self { exported_macros: macros.to_vec() });
|
||||
}
|
||||
Err(LoadProcMacroDylibError::AbiMismatch(info.version_string))
|
||||
Err(LoadProcMacroDylibError::AbiMismatch(version_string.to_owned()))
|
||||
}
|
||||
|
||||
pub(crate) fn expand<S: ProcMacroSrvSpan>(
|
||||
|
@ -117,16 +117,3 @@ impl ProcMacros {
|
|||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_version_check() {
|
||||
let path = paths::AbsPathBuf::assert(crate::proc_macro_test_dylib_path());
|
||||
let info = proc_macro_api::read_dylib_info(&path).unwrap();
|
||||
assert_eq!(
|
||||
info.version_string,
|
||||
crate::RUSTC_VERSION_STRING,
|
||||
"sysroot ABI mismatch: dylib rustc version (read from .rustc section): {:?} != proc-macro-srv version (read from 'rustc --version'): {:?}",
|
||||
info.version_string,
|
||||
crate::RUSTC_VERSION_STRING,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue