Skip to content

Commit 335bbc6

Browse files
committed
Move temp file name generation out of the create_dll_import_lib method
1 parent feaf895 commit 335bbc6

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,
@@ -19,9 +19,8 @@ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
1919
_sess: &Session,
2020
_lib_name: &str,
2121
_dll_imports: &[DllImport],
22-
_tmpdir: &Path,
23-
_is_direct_dependency: bool,
24-
) -> PathBuf {
22+
_output_path: &Path,
23+
) {
2524
unimplemented!("creating dll imports is not yet supported");
2625
}
2726
}

compiler/rustc_codegen_llvm/src/back/archive.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,8 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
124124
sess: &Session,
125125
lib_name: &str,
126126
dll_imports: &[DllImport],
127-
tmpdir: &Path,
128-
is_direct_dependency: bool,
129-
) -> PathBuf {
130-
let name_suffix = if is_direct_dependency { "_imports" } else { "_imports_indirect" };
131-
let output_path = tmpdir.join(format!("{lib_name}{name_suffix}.lib"));
132-
127+
output_path: &Path,
128+
) {
133129
let target = &sess.target;
134130
let mingw_gnu_toolchain = common::is_mingw_gnu_toolchain(target);
135131

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

158154
let def_file_content = format!(
159155
"EXPORTS\n{}",
@@ -283,9 +279,7 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
283279
error: llvm::last_error().unwrap_or("unknown LLVM error".to_string()),
284280
});
285281
}
286-
};
287-
288-
output_path
282+
}
289283
}
290284
}
291285

compiler/rustc_codegen_ssa/src/back/archive.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ pub trait ArchiveBuilderBuilder {
3333
sess: &Session,
3434
lib_name: &str,
3535
dll_imports: &[DllImport],
36-
tmpdir: &Path,
37-
is_direct_dependency: bool,
38-
) -> PathBuf;
36+
output_path: &Path,
37+
);
3938

4039
fn extract_bundled_libs<'a>(
4140
&'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)