2021-03-29 11:39:13 +02:00
|
|
|
//! Writing of the rustc metadata for dylibs
|
2020-09-23 15:13:49 +02:00
|
|
|
|
2020-08-28 12:10:48 +02:00
|
|
|
use rustc_middle::ty::TyCtxt;
|
2018-08-15 12:07:08 +02:00
|
|
|
|
2019-10-16 21:21:20 +02:00
|
|
|
use crate::backend::WriteMetadata;
|
2019-10-16 20:48:09 +02:00
|
|
|
|
2019-03-27 19:24:42 +01:00
|
|
|
// Adapted from https://github.com/rust-lang/rust/blob/da573206f87b5510de4b0ee1a9c044127e409bd3/src/librustc_codegen_llvm/base.rs#L47-L112
|
2021-04-30 14:49:58 +02:00
|
|
|
pub(crate) fn write_metadata<O: WriteMetadata>(tcx: TyCtxt<'_>, object: &mut O) {
|
2020-09-05 11:00:34 +02:00
|
|
|
use snap::write::FrameEncoder;
|
2019-08-31 22:58:09 +05:30
|
|
|
use std::io::Write;
|
2019-03-27 19:24:42 +01:00
|
|
|
|
|
|
|
let metadata = tcx.encode_metadata();
|
2021-06-01 09:05:22 +02:00
|
|
|
let mut compressed = tcx.metadata_encoding_version();
|
2021-03-05 19:12:59 +01:00
|
|
|
FrameEncoder::new(&mut compressed).write_all(&metadata.raw_data).unwrap();
|
2019-03-27 19:24:42 +01:00
|
|
|
|
2021-04-30 14:49:58 +02:00
|
|
|
object.add_rustc_section(
|
2020-03-31 13:20:19 +02:00
|
|
|
rustc_middle::middle::exported_symbols::metadata_symbol_name(tcx),
|
2019-10-16 20:48:09 +02:00
|
|
|
compressed,
|
|
|
|
);
|
2019-03-27 19:24:42 +01:00
|
|
|
}
|