rust/src/metadata.rs

21 lines
708 B
Rust
Raw Normal View History

//! Writing of the rustc metadata for dylibs
use rustc_middle::ty::TyCtxt;
2018-08-15 12:07:08 +02:00
use crate::backend::WriteMetadata;
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
pub(crate) fn write_metadata<O: WriteMetadata>(tcx: TyCtxt<'_>, object: &mut O) {
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();
let mut compressed = tcx.metadata_encoding_version();
FrameEncoder::new(&mut compressed).write_all(&metadata.raw_data).unwrap();
2019-03-27 19:24:42 +01:00
object.add_rustc_section(
rustc_middle::middle::exported_symbols::metadata_symbol_name(tcx),
compressed,
);
2019-03-27 19:24:42 +01:00
}