Skip to content

Commit 43bc101

Browse files
Rollup merge of rust-lang#155899 - ChrisDenton:dlltool, r=mati865
`dlltool`: Set the working directory to workaround `--temp-prefix` bug dlltool's `--temp-prefix` argument incorrectly splits paths that contain spaces. To workaround this, we pass a relative path to `--temp-prefix` and set the working directory. fixes rust-lang#155591
2 parents 83ddfe0 + f0b0950 commit 43bc101

3 files changed

Lines changed: 39 additions & 7 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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
type BOOL = i32;
2+
3+
#[cfg_attr(
4+
target_arch = "x86",
5+
link(name = "bcryptprimitives", kind = "raw-dylib", import_name_type = "undecorated")
6+
)]
7+
#[cfg_attr(not(target_arch = "x86"), link(name = "bcryptprimitives", kind = "raw-dylib"))]
8+
extern "system" {
9+
fn ProcessPrng(pbdata: *mut u8, cbdata: usize) -> BOOL;
10+
}
11+
12+
fn main() {
13+
let mut num: u8 = 0;
14+
unsafe {
15+
ProcessPrng(&mut num, 1);
16+
}
17+
println!("{num}");
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Ensure that raw-dylib still works if the output directory contains spaces.
2+
3+
//@ only-windows-gnu
4+
//@ ignore-cross-compile
5+
6+
use run_make_support::{rfs, rustc};
7+
8+
fn main() {
9+
let out_dir = "path with spaces";
10+
rfs::create_dir_all(out_dir);
11+
unsafe {
12+
std::env::set_var("TMP", out_dir);
13+
}
14+
rustc().crate_type("bin").input("main.rs").out_dir(out_dir).run();
15+
}

0 commit comments

Comments
 (0)