Skip to content

Commit fba37a0

Browse files
committed
Auto merge of #132402 - bjorn3:remove_snap_decompression, r=jieyouxu,Veykril
Remove support for decompressing dylib metadata We haven't been compressing dylib metadata for a while now. Removing decompression support will regress error messages about an incompatible rustc version being used, but dylibs are pretty rare anyway. Fixes rust-lang#18451
2 parents a45eb33 + ad85884 commit fba37a0

File tree

4 files changed

+4
-22
lines changed

4 files changed

+4
-22
lines changed

Cargo.lock

Lines changed: 0 additions & 7 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
@@ -145,7 +145,6 @@ smallvec = { version = "1.10.0", features = [
145145
"const_generics",
146146
] }
147147
smol_str = "0.3.2"
148-
snap = "1.1.0"
149148
text-size = "1.1.1"
150149
tracing = "0.1.40"
151150
tracing-tree = "0.3.0"

crates/proc-macro-srv/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ doctest = false
1616
object.workspace = true
1717
libloading.workspace = true
1818
memmap2.workspace = true
19-
snap.workspace = true
2019

2120
stdx.workspace = true
2221
tt.workspace = true

crates/proc-macro-srv/src/dylib/version.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::{
88
use memmap2::Mmap;
99
use object::read::{File as BinaryFile, Object, ObjectSection};
1010
use paths::AbsPath;
11-
use snap::read::FrameDecoder as SnapDecoder;
1211

1312
#[derive(Debug)]
1413
#[allow(dead_code)]
@@ -123,9 +122,8 @@ pub fn read_version(dylib_path: &AbsPath) -> io::Result<String> {
123122
let version = u32::from_be_bytes([dot_rustc[4], dot_rustc[5], dot_rustc[6], dot_rustc[7]]);
124123
// Last supported version is:
125124
// https://github.com/rust-lang/rust/commit/b94cfefc860715fb2adf72a6955423d384c69318
126-
let (snappy_portion, bytes_before_version) = match version {
127-
5 | 6 => (&dot_rustc[8..], 13),
128-
7 | 8 => {
125+
let (mut metadata_portion, bytes_before_version) = match version {
126+
8 => {
129127
let len_bytes = &dot_rustc[8..12];
130128
let data_len = u32::from_be_bytes(len_bytes.try_into().unwrap()) as usize;
131129
(&dot_rustc[12..data_len + 12], 13)
@@ -143,25 +141,18 @@ pub fn read_version(dylib_path: &AbsPath) -> io::Result<String> {
143141
}
144142
};
145143

146-
let mut uncompressed: Box<dyn Read> = if &snappy_portion[0..4] == b"rust" {
147-
// Not compressed.
148-
Box::new(snappy_portion)
149-
} else {
150-
Box::new(SnapDecoder::new(snappy_portion))
151-
};
152-
153144
// We're going to skip over the bytes before the version string, so basically:
154145
// 8 bytes for [b'r',b'u',b's',b't',0,0,0,5]
155146
// 4 or 8 bytes for [crate root bytes]
156147
// 1 byte for length of version string
157148
// so 13 or 17 bytes in total, and we should check the last of those bytes
158149
// to know the length
159150
let mut bytes = [0u8; 17];
160-
uncompressed.read_exact(&mut bytes[..bytes_before_version])?;
151+
metadata_portion.read_exact(&mut bytes[..bytes_before_version])?;
161152
let length = bytes[bytes_before_version - 1];
162153

163154
let mut version_string_utf8 = vec![0u8; length as usize];
164-
uncompressed.read_exact(&mut version_string_utf8)?;
155+
metadata_portion.read_exact(&mut version_string_utf8)?;
165156
let version_string = String::from_utf8(version_string_utf8);
166157
version_string.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
167158
}

0 commit comments

Comments
 (0)