Skip to content

Commit

Permalink
Auto merge of rust-lang#17519 - Veykril:slim-proc-macro-api, r=Veykril
Browse files Browse the repository at this point in the history
internal: Move dylib version stuff to proc-macro-srv

The client no longer reads the proc-macro versions, so this has no need to be in the api crate
  • Loading branch information
bors committed Jun 30, 2024
2 parents 56ef240 + db15273 commit cbd3a7a
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 33 deletions.
4 changes: 1 addition & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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"
Expand All @@ -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"] }

Expand Down
5 changes: 1 addition & 4 deletions crates/proc-macro-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
3 changes: 0 additions & 3 deletions crates/proc-macro-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

pub mod msg;
mod process;
mod version;

use base_db::Env;
use indexmap::IndexSet;
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions crates/proc-macro-srv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions crates/proc-macro-srv/src/dylib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! Handles dynamic library loading for proc macro
mod version;

use std::{fmt, fs::File, io};

use libloading::Library;
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;

Expand Down Expand Up @@ -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 })
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
);
}
21 changes: 4 additions & 17 deletions crates/proc-macro-srv/src/proc_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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>(
Expand Down Expand Up @@ -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,
);
}

0 comments on commit cbd3a7a

Please sign in to comment.