Rollup merge of #132820 - bjorn3:default_backend_link_impl, r=jieyouxu
Add a default implementation for CodegenBackend::link As a side effect this should add raw-dylib support to cg_gcc as the default ArchiveBuilderBuilder that is used implements create_dll_import_lib. I haven't tested if the raw-dylib support actually works however.
This commit is contained in:
commit
35225d61f4
11 changed files with 22 additions and 72 deletions
|
@ -304,6 +304,14 @@ pub trait ArchiveBuilder {
|
|||
fn build(self: Box<Self>, output: &Path) -> bool;
|
||||
}
|
||||
|
||||
pub struct ArArchiveBuilderBuilder;
|
||||
|
||||
impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
|
||||
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder + 'a> {
|
||||
Box::new(ArArchiveBuilder::new(sess, &DEFAULT_OBJECT_READER))
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use = "must call build() to finish building the archive"]
|
||||
pub struct ArArchiveBuilder<'a> {
|
||||
sess: &'a Session,
|
||||
|
|
|
@ -69,7 +69,7 @@ pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) {
|
|||
pub fn link_binary(
|
||||
sess: &Session,
|
||||
archive_builder_builder: &dyn ArchiveBuilderBuilder,
|
||||
codegen_results: &CodegenResults,
|
||||
codegen_results: CodegenResults,
|
||||
outputs: &OutputFilenames,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
let _timer = sess.timer("link_binary");
|
||||
|
@ -116,7 +116,7 @@ pub fn link_binary(
|
|||
link_rlib(
|
||||
sess,
|
||||
archive_builder_builder,
|
||||
codegen_results,
|
||||
&codegen_results,
|
||||
RlibFlavor::Normal,
|
||||
&path,
|
||||
)?
|
||||
|
@ -126,7 +126,7 @@ pub fn link_binary(
|
|||
link_staticlib(
|
||||
sess,
|
||||
archive_builder_builder,
|
||||
codegen_results,
|
||||
&codegen_results,
|
||||
&out_filename,
|
||||
&path,
|
||||
)?;
|
||||
|
@ -137,7 +137,7 @@ pub fn link_binary(
|
|||
archive_builder_builder,
|
||||
crate_type,
|
||||
&out_filename,
|
||||
codegen_results,
|
||||
&codegen_results,
|
||||
path.as_ref(),
|
||||
)?;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ use rustc_span::symbol::Symbol;
|
|||
|
||||
use super::CodegenObject;
|
||||
use super::write::WriteBackendMethods;
|
||||
use crate::back::archive::ArArchiveBuilderBuilder;
|
||||
use crate::back::link::link_binary;
|
||||
use crate::back::write::TargetMachineFactoryFn;
|
||||
use crate::{CodegenResults, ModuleCodegen};
|
||||
|
||||
|
@ -87,7 +89,9 @@ pub trait CodegenBackend {
|
|||
sess: &Session,
|
||||
codegen_results: CodegenResults,
|
||||
outputs: &OutputFilenames,
|
||||
) -> Result<(), ErrorGuaranteed>;
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
link_binary(sess, &ArArchiveBuilderBuilder, codegen_results, outputs)
|
||||
}
|
||||
|
||||
/// Returns `true` if this backend can be safely called from multiple threads.
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue