mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 05:08:52 +00:00
Use mmap for proc macro libs
This commit is contained in:
parent
69f0cb6cd7
commit
93fcf1c133
3 changed files with 17 additions and 2 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -675,6 +675,16 @@ version = "2.3.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
|
||||
|
||||
[[package]]
|
||||
name = "memmap"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memoffset"
|
||||
version = "0.5.4"
|
||||
|
@ -1112,6 +1122,7 @@ dependencies = [
|
|||
"difference",
|
||||
"goblin",
|
||||
"libloading",
|
||||
"memmap",
|
||||
"ra_mbe",
|
||||
"ra_proc_macro",
|
||||
"ra_tt",
|
||||
|
|
|
@ -14,6 +14,7 @@ ra_mbe = { path = "../ra_mbe" }
|
|||
ra_proc_macro = { path = "../ra_proc_macro" }
|
||||
goblin = "0.2.1"
|
||||
libloading = "0.6.0"
|
||||
memmap = "0.7"
|
||||
test_utils = { path = "../test_utils" }
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
//! Handles dynamic library loading for proc macro
|
||||
|
||||
use crate::{proc_macro::bridge, rustc_server::TokenStream};
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
|
||||
use goblin::{mach::Mach, Object};
|
||||
use libloading::Library;
|
||||
use memmap::Mmap;
|
||||
use ra_proc_macro::ProcMacroKind;
|
||||
|
||||
use std::io::Error as IoError;
|
||||
|
@ -21,7 +23,8 @@ fn is_derive_registrar_symbol(symbol: &str) -> bool {
|
|||
}
|
||||
|
||||
fn find_registrar_symbol(file: &Path) -> Result<Option<String>, IoError> {
|
||||
let buffer = std::fs::read(file)?;
|
||||
let file = File::open(file)?;
|
||||
let buffer = unsafe { Mmap::map(&file)? };
|
||||
let object = Object::parse(&buffer).map_err(invalid_data_err)?;
|
||||
|
||||
match object {
|
||||
|
@ -55,7 +58,7 @@ fn find_registrar_symbol(file: &Path) -> Result<Option<String>, IoError> {
|
|||
&s.name
|
||||
}
|
||||
})
|
||||
.find(|s| is_derive_registrar_symbol(&s))
|
||||
.find(|s| is_derive_registrar_symbol(s))
|
||||
.map(|s| s.to_string());
|
||||
Ok(name)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue