Skip to content

Commit

Permalink
Move temp file name generation out of the create_dll_import_lib method
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Jul 30, 2024
1 parent ba5ff07 commit ee89db9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 24 deletions.
7 changes: 3 additions & 4 deletions compiler/rustc_codegen_cranelift/src/archive.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::{Path, PathBuf};
use std::path::Path;

use rustc_codegen_ssa::back::archive::{
ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder, DEFAULT_OBJECT_READER,
Expand All @@ -17,9 +17,8 @@ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
sess: &Session,
_lib_name: &str,
_dll_imports: &[rustc_session::cstore::DllImport],
_tmpdir: &Path,
_is_direct_dependency: bool,
) -> PathBuf {
_output_path: &Path,
) {
sess.dcx().fatal("raw-dylib is not yet supported by rustc_codegen_cranelift");
}
}
7 changes: 3 additions & 4 deletions compiler/rustc_codegen_gcc/src/archive.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::{Path, PathBuf};
use std::path::Path;

use rustc_codegen_ssa::back::archive::{
ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder, DEFAULT_OBJECT_READER,
Expand All @@ -18,9 +18,8 @@ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
_sess: &Session,
_lib_name: &str,
_dll_imports: &[DllImport],
_tmpdir: &Path,
_is_direct_dependency: bool,
) -> PathBuf {
_output_path: &Path,
) {
unimplemented!("creating dll imports is not yet supported");
}
}
14 changes: 4 additions & 10 deletions compiler/rustc_codegen_llvm/src/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,8 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
sess: &Session,
lib_name: &str,
dll_imports: &[DllImport],
tmpdir: &Path,
is_direct_dependency: bool,
) -> PathBuf {
let name_suffix = if is_direct_dependency { "_imports" } else { "_imports_indirect" };
let output_path = tmpdir.join(format!("{lib_name}{name_suffix}.lib"));

output_path: &Path,
) {
let target = &sess.target;
let mingw_gnu_toolchain = common::is_mingw_gnu_toolchain(target);

Expand All @@ -149,7 +145,7 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
// that loaded but crashed with an AV upon calling one of the imported
// functions. Therefore, use binutils to create the import library instead,
// by writing a .DEF file to the temp dir and calling binutils's dlltool.
let def_file_path = tmpdir.join(format!("{lib_name}{name_suffix}.def"));
let def_file_path = output_path.with_extension("def");

let def_file_content = format!(
"EXPORTS\n{}",
Expand Down Expand Up @@ -279,9 +275,7 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
error: llvm::last_error().unwrap_or("unknown LLVM error".to_string()),
});
}
};

output_path
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_ssa/src/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ pub trait ArchiveBuilderBuilder {
sess: &Session,
lib_name: &str,
dll_imports: &[DllImport],
tmpdir: &Path,
is_direct_dependency: bool,
) -> PathBuf;
output_path: &Path,
);

fn extract_bundled_libs<'a>(
&'a self,
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,17 @@ fn create_dll_import_libs<'a>(
Ok(collate_raw_dylibs(sess, used_libraries)?
.into_iter()
.map(|(raw_dylib_name, raw_dylib_imports)| {
let name_suffix = if is_direct_dependency { "_imports" } else { "_imports_indirect" };
let output_path = tmpdir.join(format!("{raw_dylib_name}{name_suffix}.lib"));

archive_builder_builder.create_dll_import_lib(
sess,
&raw_dylib_name,
&raw_dylib_imports,
tmpdir,
is_direct_dependency,
)
&output_path,
);

output_path
})
.collect())
}
Expand Down

0 comments on commit ee89db9

Please sign in to comment.