Skip to content

Commit 270461e

Browse files
ChrisDentoncuviper
authored andcommitted
Fix passing paths with space into dlltool
(cherry picked from commit 23c7bf0)
1 parent b7085f6 commit 270461e

4 files changed

Lines changed: 8 additions & 10 deletions

File tree

compiler/rustc_codegen_ssa/src/back/archive.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,10 @@ fn create_mingw_dll_import_lib(
217217
// able to control the *exact* spelling of each of the symbols that are being imported:
218218
// hence we don't want `dlltool` adding leading underscores automatically.
219219
let dlltool = find_binutils_dlltool(sess);
220-
let temp_prefix = {
221-
let mut path = PathBuf::from(&output_path);
222-
path.pop();
223-
path.push(lib_name);
224-
path
225-
};
220+
// temp_prefix doesn't handle paths with spaces so
221+
// use a relative path and set the current working directory
222+
let cwd = output_path.parent().unwrap_or(output_path);
223+
let temp_prefix = lib_name;
226224
// dlltool target architecture args from:
227225
// https://github.com/llvm/llvm-project-release-prs/blob/llvmorg-15.0.6/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp#L69
228226
let (dlltool_target_arch, dlltool_target_bitness) = match &sess.target.arch {
@@ -246,7 +244,8 @@ fn create_mingw_dll_import_lib(
246244
.arg(dlltool_target_bitness)
247245
.arg("--no-leading-underscore")
248246
.arg("--temp-prefix")
249-
.arg(temp_prefix);
247+
.arg(temp_prefix)
248+
.current_dir(cwd);
250249

251250
match dlltool_cmd.output() {
252251
Err(e) => {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
echo Called dlltool via script.cmd> actual.txt
1+
echo Called dlltool via script.cmd> %~dp0\actual.txt
22
dlltool.exe %*

tests/ui/linkage-attr/raw-dylib/windows/dlltool-failed.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//@ normalize-stderr: "[^ ]*/foo.dll_imports.lib" -> "$$LIB_FILE"
88
//@ normalize-stderr: "-m [^ ]*" -> "$$TARGET_MACHINE"
99
//@ normalize-stderr: "-f [^ ]*" -> "$$ASM_FLAGS"
10-
//@ normalize-stderr: "--temp-prefix [^ ]*/foo.dll" -> "$$TEMP_PREFIX"
1110
#[link(name = "foo", kind = "raw-dylib")]
1211
extern "C" {
1312
// `@1` is an invalid name to export, as it usually indicates that something

tests/ui/linkage-attr/raw-dylib/windows/dlltool-failed.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: dlltool could not create import library with $DLLTOOL -d $DEF_FILE -D foo.dll -l $LIB_FILE $TARGET_MACHINE $ASM_FLAGS --no-leading-underscore $TEMP_PREFIX:
1+
error: dlltool could not create import library with $DLLTOOL -d $DEF_FILE -D foo.dll -l $LIB_FILE $TARGET_MACHINE $ASM_FLAGS --no-leading-underscore --temp-prefix foo.dll:
22

33
$DLLTOOL: Syntax error in def file $DEF_FILE:1␍
44

0 commit comments

Comments
 (0)