Skip to content

Commit 17a6bb5

Browse files
committed
Support reading uncompressed proc macro metadata
#113695 makes the dylib metadata uncompressed for perf reasons. This commit allows reading both the current compressed and future uncompressed dylib metadata.
1 parent 8174450 commit 17a6bb5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

crates/proc-macro-api/src/version.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,12 @@ pub fn read_version(dylib_path: &AbsPath) -> io::Result<String> {
135135
}
136136
};
137137

138-
let mut snappy_decoder = SnapDecoder::new(snappy_portion);
138+
let mut uncompressed: Box<dyn Read> = if &snappy_portion[0..4] == b"rust" {
139+
// Not compressed.
140+
Box::new(snappy_portion)
141+
} else {
142+
Box::new(SnapDecoder::new(snappy_portion))
143+
};
139144

140145
// the bytes before version string bytes, so this basically is:
141146
// 8 bytes for [b'r',b'u',b's',b't',0,0,0,5]
@@ -144,11 +149,11 @@ pub fn read_version(dylib_path: &AbsPath) -> io::Result<String> {
144149
// so 13 bytes in total, and we should check the 13th byte
145150
// to know the length
146151
let mut bytes_before_version = [0u8; 13];
147-
snappy_decoder.read_exact(&mut bytes_before_version)?;
152+
uncompressed.read_exact(&mut bytes_before_version)?;
148153
let length = bytes_before_version[12];
149154

150155
let mut version_string_utf8 = vec![0u8; length as usize];
151-
snappy_decoder.read_exact(&mut version_string_utf8)?;
156+
uncompressed.read_exact(&mut version_string_utf8)?;
152157
let version_string = String::from_utf8(version_string_utf8);
153158
version_string.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
154159
}

0 commit comments

Comments
 (0)