Skip to content

Commit fd9dce7

Browse files
committed
Move dylib version stuff to proc-macro-srv
1 parent eb72a9e commit fd9dce7

File tree

8 files changed

+36
-33
lines changed

8 files changed

+36
-33
lines changed

src/tools/rust-analyzer/Cargo.lock

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,13 +1329,10 @@ dependencies = [
13291329
"base-db",
13301330
"indexmap",
13311331
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
1332-
"memmap2",
1333-
"object 0.33.0",
13341332
"paths",
13351333
"rustc-hash",
13361334
"serde",
13371335
"serde_json",
1338-
"snap",
13391336
"span",
13401337
"stdx",
13411338
"text-size",
@@ -1358,6 +1355,7 @@ dependencies = [
13581355
"proc-macro-api",
13591356
"proc-macro-test",
13601357
"ra-ap-rustc_lexer",
1358+
"snap",
13611359
"span",
13621360
"stdx",
13631361
"tt",

src/tools/rust-analyzer/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ hashbrown = { version = "0.14", features = [
120120
indexmap = "2.1.0"
121121
itertools = "0.12.0"
122122
libc = "0.2.150"
123+
libloading = "0.8.0"
124+
memmap2 = "0.5.4"
123125
nohash-hasher = "0.2.0"
124126
oorandom = "11.1.3"
125127
object = { version = "0.33.0", default-features = false, features = [
@@ -143,6 +145,7 @@ smallvec = { version = "1.10.0", features = [
143145
"const_generics",
144146
] }
145147
smol_str = "0.2.1"
148+
snap = "1.1.0"
146149
text-size = "1.1.1"
147150
tracing = "0.1.40"
148151
tracing-tree = "0.3.0"
@@ -156,6 +159,7 @@ url = "2.3.1"
156159
xshell = "0.2.5"
157160

158161

162+
159163
# We need to freeze the version of the crate, as the raw-api feature is considered unstable
160164
dashmap = { version = "=5.5.3", features = ["raw-api"] }
161165

src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ rust-version.workspace = true
1212
doctest = false
1313

1414
[dependencies]
15-
object.workspace = true
1615
serde.workspace = true
1716
serde_json = { workspace = true, features = ["unbounded_depth"] }
1817
tracing.workspace = true
1918
triomphe.workspace = true
2019
rustc-hash.workspace = true
21-
memmap2 = "0.5.4"
22-
snap = "1.1.0"
23-
indexmap = "2.1.0"
20+
indexmap.workspace = true
2421

2522
# local deps
2623
paths = { workspace = true, features = ["serde1"] }

src/tools/rust-analyzer/crates/proc-macro-api/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
pub mod msg;
1111
mod process;
12-
mod version;
1312

1413
use base_db::Env;
1514
use indexmap::IndexSet;
@@ -31,8 +30,6 @@ use crate::{
3130
process::ProcMacroProcessSrv,
3231
};
3332

34-
pub use version::{read_dylib_info, read_version, RustCInfo};
35-
3633
#[derive(Copy, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
3734
pub enum ProcMacroKind {
3835
CustomDerive,

src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ doctest = false
1313

1414
[dependencies]
1515
object.workspace = true
16-
libloading = "0.8.0"
17-
memmap2 = "0.5.4"
16+
libloading.workspace = true
17+
memmap2.workspace = true
18+
snap.workspace = true
1819

1920
stdx.workspace = true
2021
tt.workspace = true

src/tools/rust-analyzer/crates/proc-macro-srv/src/dylib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
//! Handles dynamic library loading for proc macro
22
3+
mod version;
4+
35
use std::{fmt, fs::File, io};
46

57
use libloading::Library;
68
use memmap2::Mmap;
79
use object::Object;
810
use paths::{AbsPath, Utf8Path, Utf8PathBuf};
911
use proc_macro::bridge;
10-
use proc_macro_api::{read_dylib_info, ProcMacroKind};
12+
use proc_macro_api::ProcMacroKind;
1113

1214
use crate::ProcMacroSrvSpan;
1315

@@ -119,11 +121,14 @@ impl ProcMacroLibraryLibloading {
119121
let abs_file: &AbsPath = file
120122
.try_into()
121123
.map_err(|_| invalid_data_err(format!("expected an absolute path, got {file}")))?;
122-
let version_info = read_dylib_info(abs_file)?;
124+
let version_info = version::read_dylib_info(abs_file)?;
123125

124126
let lib = load_library(file).map_err(invalid_data_err)?;
125-
let proc_macros =
126-
crate::proc_macros::ProcMacros::from_lib(&lib, symbol_name, version_info)?;
127+
let proc_macros = crate::proc_macros::ProcMacros::from_lib(
128+
&lib,
129+
symbol_name,
130+
&version_info.version_string,
131+
)?;
127132
Ok(ProcMacroLibraryLibloading { _lib: lib, proc_macros })
128133
}
129134
}

src/tools/rust-analyzer/crates/proc-macro-api/src/version.rs renamed to src/tools/rust-analyzer/crates/proc-macro-srv/src/dylib/version.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use paths::AbsPath;
1111
use snap::read::FrameDecoder as SnapDecoder;
1212

1313
#[derive(Debug)]
14+
#[allow(dead_code)]
1415
pub struct RustCInfo {
1516
pub version: (usize, usize, usize),
1617
pub channel: String,
@@ -164,3 +165,16 @@ pub fn read_version(dylib_path: &AbsPath) -> io::Result<String> {
164165
let version_string = String::from_utf8(version_string_utf8);
165166
version_string.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
166167
}
168+
169+
#[test]
170+
fn test_version_check() {
171+
let path = paths::AbsPathBuf::assert(crate::proc_macro_test_dylib_path());
172+
let info = read_dylib_info(&path).unwrap();
173+
assert_eq!(
174+
info.version_string,
175+
crate::RUSTC_VERSION_STRING,
176+
"sysroot ABI mismatch: dylib rustc version (read from .rustc section): {:?} != proc-macro-srv version (read from 'rustc --version'): {:?}",
177+
info.version_string,
178+
crate::RUSTC_VERSION_STRING,
179+
);
180+
}

src/tools/rust-analyzer/crates/proc-macro-srv/src/proc_macros.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use libloading::Library;
44
use proc_macro::bridge;
5-
use proc_macro_api::{ProcMacroKind, RustCInfo};
5+
use proc_macro_api::ProcMacroKind;
66

77
use crate::{dylib::LoadProcMacroDylibError, ProcMacroSrvSpan};
88

@@ -29,15 +29,15 @@ impl ProcMacros {
2929
pub(crate) fn from_lib(
3030
lib: &Library,
3131
symbol_name: String,
32-
info: RustCInfo,
32+
version_string: &str,
3333
) -> Result<ProcMacros, LoadProcMacroDylibError> {
34-
if info.version_string == crate::RUSTC_VERSION_STRING {
34+
if version_string == crate::RUSTC_VERSION_STRING {
3535
let macros =
3636
unsafe { lib.get::<&&[bridge::client::ProcMacro]>(symbol_name.as_bytes()) }?;
3737

3838
return Ok(Self { exported_macros: macros.to_vec() });
3939
}
40-
Err(LoadProcMacroDylibError::AbiMismatch(info.version_string))
40+
Err(LoadProcMacroDylibError::AbiMismatch(version_string.to_owned()))
4141
}
4242

4343
pub(crate) fn expand<S: ProcMacroSrvSpan>(
@@ -117,16 +117,3 @@ impl ProcMacros {
117117
.collect()
118118
}
119119
}
120-
121-
#[test]
122-
fn test_version_check() {
123-
let path = paths::AbsPathBuf::assert(crate::proc_macro_test_dylib_path());
124-
let info = proc_macro_api::read_dylib_info(&path).unwrap();
125-
assert_eq!(
126-
info.version_string,
127-
crate::RUSTC_VERSION_STRING,
128-
"sysroot ABI mismatch: dylib rustc version (read from .rustc section): {:?} != proc-macro-srv version (read from 'rustc --version'): {:?}",
129-
info.version_string,
130-
crate::RUSTC_VERSION_STRING,
131-
);
132-
}

0 commit comments

Comments
 (0)