Skip to content

Commit 23edbb6

Browse files
committed
Don't require dlltool with the dummy backend on MinGW
The dummy backend should be able to cross-compile to any target without requiring any external tool or library other than the rust standard library.
1 parent 23c7bad commit 23edbb6

File tree

1 file changed

+24
-2
lines changed
  • compiler/rustc_interface/src

1 file changed

+24
-2
lines changed

compiler/rustc_interface/src/util.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{env, thread};
77

88
use rustc_ast as ast;
99
use rustc_attr_parsing::{ShouldEmit, validate_attr};
10-
use rustc_codegen_ssa::back::archive::ArArchiveBuilderBuilder;
10+
use rustc_codegen_ssa::back::archive::{ArArchiveBuilderBuilder, ArchiveBuilderBuilder};
1111
use rustc_codegen_ssa::back::link::link_binary;
1212
use rustc_codegen_ssa::target_features::{self, cfg_target_feature};
1313
use rustc_codegen_ssa::traits::CodegenBackend;
@@ -440,7 +440,7 @@ impl CodegenBackend for DummyCodegenBackend {
440440

441441
link_binary(
442442
sess,
443-
&ArArchiveBuilderBuilder,
443+
&DummyArchiveBuilderBuilder,
444444
codegen_results,
445445
metadata,
446446
outputs,
@@ -449,6 +449,28 @@ impl CodegenBackend for DummyCodegenBackend {
449449
}
450450
}
451451

452+
struct DummyArchiveBuilderBuilder;
453+
454+
impl ArchiveBuilderBuilder for DummyArchiveBuilderBuilder {
455+
fn new_archive_builder<'a>(
456+
&self,
457+
sess: &'a Session,
458+
) -> Box<dyn rustc_codegen_ssa::back::archive::ArchiveBuilder + 'a> {
459+
ArArchiveBuilderBuilder.new_archive_builder(sess)
460+
}
461+
462+
fn create_dll_import_lib(
463+
&self,
464+
sess: &Session,
465+
_lib_name: &str,
466+
_items: Vec<rustc_codegen_ssa::back::archive::ImportLibraryItem>,
467+
output_path: &Path,
468+
) {
469+
// Build an empty static library to avoid calling an external dlltool on mingw
470+
ArArchiveBuilderBuilder.new_archive_builder(sess).build(output_path);
471+
}
472+
}
473+
452474
// This is used for rustdoc, but it uses similar machinery to codegen backend
453475
// loading, so we leave the code here. It is potentially useful for other tools
454476
// that want to invoke the rustc binary while linking to rustc as well.

0 commit comments

Comments
 (0)