Skip to content

Commit ee89db9

Browse files
committed
Move temp file name generation out of the create_dll_import_lib method
1 parent ba5ff07 commit ee89db9

File tree

5 files changed

+19
-24
lines changed

5 files changed

+19
-24
lines changed

compiler/rustc_codegen_cranelift/src/archive.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::path::{Path, PathBuf};
1+
use std::path::Path;
22

33
use rustc_codegen_ssa::back::archive::{
44
ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder, DEFAULT_OBJECT_READER,
@@ -17,9 +17,8 @@ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
1717
sess: &Session,
1818
_lib_name: &str,
1919
_dll_imports: &[rustc_session::cstore::DllImport],
20-
_tmpdir: &Path,
21-
_is_direct_dependency: bool,
22-
) -> PathBuf {
20+
_output_path: &Path,
21+
) {
2322
sess.dcx().fatal("raw-dylib is not yet supported by rustc_codegen_cranelift");
2423
}
2524
}

compiler/rustc_codegen_gcc/src/archive.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::path::{Path, PathBuf};
1+
use std::path::Path;
22

33
use rustc_codegen_ssa::back::archive::{
44
ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder, DEFAULT_OBJECT_READER,
@@ -18,9 +18,8 @@ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
1818
_sess: &Session,
1919
_lib_name: &str,
2020
_dll_imports: &[DllImport],
21-
_tmpdir: &Path,
22-
_is_direct_dependency: bool,
23-
) -> PathBuf {
21+
_output_path: &Path,
22+
) {
2423
unimplemented!("creating dll imports is not yet supported");
2524
}
2625
}

compiler/rustc_codegen_llvm/src/back/archive.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,8 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
120120
sess: &Session,
121121
lib_name: &str,
122122
dll_imports: &[DllImport],
123-
tmpdir: &Path,
124-
is_direct_dependency: bool,
125-
) -> PathBuf {
126-
let name_suffix = if is_direct_dependency { "_imports" } else { "_imports_indirect" };
127-
let output_path = tmpdir.join(format!("{lib_name}{name_suffix}.lib"));
128-
123+
output_path: &Path,
124+
) {
129125
let target = &sess.target;
130126
let mingw_gnu_toolchain = common::is_mingw_gnu_toolchain(target);
131127

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

154150
let def_file_content = format!(
155151
"EXPORTS\n{}",
@@ -279,9 +275,7 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
279275
error: llvm::last_error().unwrap_or("unknown LLVM error".to_string()),
280276
});
281277
}
282-
};
283-
284-
output_path
278+
}
285279
}
286280
}
287281

compiler/rustc_codegen_ssa/src/back/archive.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ pub trait ArchiveBuilderBuilder {
3131
sess: &Session,
3232
lib_name: &str,
3333
dll_imports: &[DllImport],
34-
tmpdir: &Path,
35-
is_direct_dependency: bool,
36-
) -> PathBuf;
34+
output_path: &Path,
35+
);
3736

3837
fn extract_bundled_libs<'a>(
3938
&'a self,

compiler/rustc_codegen_ssa/src/back/link.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -494,13 +494,17 @@ fn create_dll_import_libs<'a>(
494494
Ok(collate_raw_dylibs(sess, used_libraries)?
495495
.into_iter()
496496
.map(|(raw_dylib_name, raw_dylib_imports)| {
497+
let name_suffix = if is_direct_dependency { "_imports" } else { "_imports_indirect" };
498+
let output_path = tmpdir.join(format!("{raw_dylib_name}{name_suffix}.lib"));
499+
497500
archive_builder_builder.create_dll_import_lib(
498501
sess,
499502
&raw_dylib_name,
500503
&raw_dylib_imports,
501-
tmpdir,
502-
is_direct_dependency,
503-
)
504+
&output_path,
505+
);
506+
507+
output_path
504508
})
505509
.collect())
506510
}

0 commit comments

Comments
 (0)