-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Mostly fix metadata_only backend and extract some code out of rustc_codegen_llvm #51590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6ceb163
95ed511
edd6ed5
f44ec64
d7bc293
097de53
e65db81
cd4989e
b95ef95
b723bc1
c61531d
c5a6b51
c504d26
6797436
c7c534f
a533041
163cb57
ff12beb
23c0b3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ crate-type = ["dylib"] | |
test = false | ||
|
||
[dependencies] | ||
ar = "0.3.0" | ||
flate2 = "1.0" | ||
log = "0.4" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,15 +22,13 @@ | |
#![feature(box_syntax)] | ||
|
||
use std::any::Any; | ||
use std::io::prelude::*; | ||
use std::io::{self, Cursor}; | ||
use std::io::{self, Write}; | ||
use std::fs::File; | ||
use std::path::Path; | ||
use std::sync::mpsc; | ||
use std::sync::{mpsc, Arc}; | ||
|
||
use rustc_data_structures::owning_ref::OwningRef; | ||
use rustc_data_structures::sync::Lrc; | ||
use ar::{Archive, Builder, Header}; | ||
use flate2::Compression; | ||
use flate2::write::DeflateEncoder; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compressing the metadata, when rustc_metadata expects it. |
||
|
||
|
@@ -81,89 +79,21 @@ pub trait CodegenBackend { | |
) -> Result<(), CompileIncomplete>; | ||
} | ||
|
||
pub struct DummyCodegenBackend; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It isn't used anywere There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not even in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No |
||
|
||
impl CodegenBackend for DummyCodegenBackend { | ||
fn metadata_loader(&self) -> Box<MetadataLoader + Sync> { | ||
box DummyMetadataLoader(()) | ||
} | ||
|
||
fn provide(&self, _providers: &mut Providers) { | ||
bug!("DummyCodegenBackend::provide"); | ||
} | ||
|
||
fn provide_extern(&self, _providers: &mut Providers) { | ||
bug!("DummyCodegenBackend::provide_extern"); | ||
} | ||
|
||
fn codegen_crate<'a, 'tcx>( | ||
&self, | ||
_tcx: TyCtxt<'a, 'tcx, 'tcx>, | ||
_rx: mpsc::Receiver<Box<Any + Send>> | ||
) -> Box<Any> { | ||
bug!("DummyCodegenBackend::codegen_backend"); | ||
} | ||
|
||
fn join_codegen_and_link( | ||
&self, | ||
_ongoing_codegen: Box<Any>, | ||
_sess: &Session, | ||
_dep_graph: &DepGraph, | ||
_outputs: &OutputFilenames, | ||
) -> Result<(), CompileIncomplete> { | ||
bug!("DummyCodegenBackend::join_codegen_and_link"); | ||
} | ||
} | ||
|
||
pub struct DummyMetadataLoader(()); | ||
|
||
impl MetadataLoader for DummyMetadataLoader { | ||
fn get_rlib_metadata( | ||
&self, | ||
_target: &Target, | ||
_filename: &Path | ||
) -> Result<MetadataRef, String> { | ||
bug!("DummyMetadataLoader::get_rlib_metadata"); | ||
} | ||
|
||
fn get_dylib_metadata( | ||
&self, | ||
_target: &Target, | ||
_filename: &Path | ||
) -> Result<MetadataRef, String> { | ||
bug!("DummyMetadataLoader::get_dylib_metadata"); | ||
} | ||
} | ||
|
||
pub struct NoLlvmMetadataLoader; | ||
|
||
impl MetadataLoader for NoLlvmMetadataLoader { | ||
fn get_rlib_metadata(&self, _: &Target, filename: &Path) -> Result<MetadataRef, String> { | ||
let file = File::open(filename) | ||
let mut file = File::open(filename) | ||
.map_err(|e| format!("metadata file open err: {:?}", e))?; | ||
let mut archive = Archive::new(file); | ||
|
||
while let Some(entry_result) = archive.next_entry() { | ||
let mut entry = entry_result | ||
.map_err(|e| format!("metadata section read err: {:?}", e))?; | ||
if entry.header().identifier() == "rust.metadata.bin" { | ||
let mut buf = Vec::new(); | ||
io::copy(&mut entry, &mut buf).unwrap(); | ||
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into(); | ||
return Ok(rustc_erase_owner!(buf.map_owner_box())); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It couldn't load all metadata produced by |
||
|
||
Err("Couldn't find metadata section".to_string()) | ||
let mut buf = Vec::new(); | ||
io::copy(&mut file, &mut buf).unwrap(); | ||
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into(); | ||
return Ok(rustc_erase_owner!(buf.map_owner_box())); | ||
} | ||
|
||
fn get_dylib_metadata( | ||
&self, | ||
_target: &Target, | ||
_filename: &Path, | ||
) -> Result<MetadataRef, String> { | ||
// FIXME: Support reading dylibs from llvm enabled rustc | ||
self.get_rlib_metadata(_target, _filename) | ||
fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<MetadataRef, String> { | ||
self.get_rlib_metadata(target, filename) | ||
} | ||
} | ||
|
||
|
@@ -205,8 +135,13 @@ impl CodegenBackend for MetadataOnlyCodegenBackend { | |
providers.target_features_whitelist = |_tcx, _cnum| { | ||
Lrc::new(FxHashMap()) // Just a dummy | ||
}; | ||
providers.is_reachable_non_generic = |_tcx, _defid| true; | ||
providers.exported_symbols = |_tcx, _crate| Arc::new(Vec::new()); | ||
providers.wasm_custom_sections = |_tcx, _crate| Lrc::new(Vec::new()); | ||
} | ||
fn provide_extern(&self, providers: &mut Providers) { | ||
providers.is_reachable_non_generic = |_tcx, _defid| true; | ||
} | ||
fn provide_extern(&self, _providers: &mut Providers) {} | ||
|
||
fn codegen_crate<'a, 'tcx>( | ||
&self, | ||
|
@@ -225,7 +160,8 @@ impl CodegenBackend for MetadataOnlyCodegenBackend { | |
collector::MonoItemCollectionMode::Eager | ||
).0.iter() | ||
); | ||
::rustc::middle::dependency_format::calculate(tcx); | ||
// FIXME: Fix this | ||
// ::rustc::middle::dependency_format::calculate(tcx); | ||
let _ = tcx.link_args(LOCAL_CRATE); | ||
let _ = tcx.native_libraries(LOCAL_CRATE); | ||
for mono_item in | ||
|
@@ -280,9 +216,8 @@ impl CodegenBackend for MetadataOnlyCodegenBackend { | |
} else { | ||
&ongoing_codegen.metadata.raw_data | ||
}; | ||
let mut builder = Builder::new(File::create(&output_name).unwrap()); | ||
let header = Header::new("rust.metadata.bin".to_string(), metadata.len() as u64); | ||
builder.append(&header, Cursor::new(metadata)).unwrap(); | ||
let mut file = File::create(&output_name).unwrap(); | ||
file.write_all(metadata).unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So all library types are effectively the same as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the metadata-only backend yes, except for dylibs, because these must have compressed metadata. |
||
} | ||
|
||
sess.abort_if_errors(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ all: | |
/bin/echo || exit 0 # This test requires /bin/echo to exist | ||
$(RUSTC) the_backend.rs --crate-name the_backend --crate-type dylib \ | ||
-o $(TMPDIR)/the_backend.dylib | ||
$(RUSTC) some_crate.rs --crate-name some_crate --crate-type bin -o $(TMPDIR)/some_crate \ | ||
$(RUSTC) some_crate.rs --crate-name some_crate --crate-type lib -o $(TMPDIR)/some_crate \ | ||
-Z codegen-backend=$(TMPDIR)/the_backend.dylib -Z unstable-options | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we have two tests here, one for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bin doesn't work without adding several lang items. |
||
grep -x "This has been \"compiled\" successfully." $(TMPDIR)/some_crate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does something else depend on this crate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was asking because there's a "checksum" line that would also be removed if this was the last use of
ar
.I just checked and
rustc_driver
also depends onar
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what??? how did tidy pass then? i removed ar as whitelisted dep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed unused dep