Skip to content

Commit 6e79943

Browse files
committed
Add an Mmap wrapper to rustc_data_structures
This wrapper implements StableAddress and falls back to directly reading the file on wasm32
1 parent 07968a0 commit 6e79943

File tree

3 files changed

+4
-28
lines changed

3 files changed

+4
-28
lines changed

Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg
2222
indexmap = "1.0.2"
2323
libloading = { version = "0.6.0", optional = true }
2424
smallvec = "1.6.1"
25-
memmap2 = "0.2.1"
2625

2726
# Uncomment to use local checkout of cranelift
2827
#[patch."https://github.com/bytecodealliance/wasmtime/"]

src/metadata.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Reading and writing of the rustc metadata for rlibs and dylibs
22
33
use std::fs::File;
4-
use std::ops::Deref;
54
use std::path::Path;
65

76
use rustc_codegen_ssa::METADATA_FILENAME;
8-
use rustc_data_structures::owning_ref::{OwningRef, StableAddress};
7+
use rustc_data_structures::memmap::Mmap;
8+
use rustc_data_structures::owning_ref::OwningRef;
99
use rustc_data_structures::rustc_erase_owner;
1010
use rustc_data_structures::sync::MetadataRef;
1111
use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoader};
@@ -17,26 +17,13 @@ use crate::backend::WriteMetadata;
1717

1818
pub(crate) struct CraneliftMetadataLoader;
1919

20-
struct StableMmap(memmap2::Mmap);
21-
22-
impl Deref for StableMmap {
23-
type Target = [u8];
24-
25-
fn deref(&self) -> &[u8] {
26-
&*self.0
27-
}
28-
}
29-
30-
unsafe impl StableAddress for StableMmap {}
31-
3220
fn load_metadata_with(
3321
path: &Path,
3422
f: impl for<'a> FnOnce(&'a [u8]) -> Result<&'a [u8], String>,
3523
) -> Result<MetadataRef, String> {
3624
let file = File::open(path).map_err(|e| format!("{:?}", e))?;
37-
let data = unsafe { memmap2::MmapOptions::new().map_copy_read_only(&file) }
38-
.map_err(|e| format!("{:?}", e))?;
39-
let metadata = OwningRef::new(StableMmap(data)).try_map(f)?;
25+
let data = unsafe { Mmap::map(file) }.map_err(|e| format!("{:?}", e))?;
26+
let metadata = OwningRef::new(data).try_map(f)?;
4027
return Ok(rustc_erase_owner!(metadata.map_owner_box()));
4128
}
4229

0 commit comments

Comments
 (0)