Skip to content

Commit fb95efa

Browse files
committed
Include current_exe in hash for linker wrapper path
Ensures that unique linker wrapper scripts are generated even when current_exe is different. Fixes an issue with concurrent builds driven through maturin. Closes rust-cross#318.
1 parent 6e6a046 commit fb95efa

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/zig.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,14 +1368,20 @@ pub fn prepare_zig_linker(target: &str) -> Result<ZigWrapper> {
13681368
}
13691369
}
13701370

1371+
let current_exe = if let Ok(exe) = env::var("CARGO_BIN_EXE_cargo-zigbuild") {
1372+
PathBuf::from(exe)
1373+
} else {
1374+
env::current_exe()?
1375+
};
13711376
let cc_args_str = cc_args.join(" ");
1372-
let hash = crc::Crc::<u16>::new(&crc::CRC_16_IBM_SDLC).checksum(cc_args_str.as_bytes());
1377+
let hash_input = current_exe.display().to_string() + &cc_args_str;
1378+
let hash = crc::Crc::<u16>::new(&crc::CRC_16_IBM_SDLC).checksum(hash_input.as_bytes());
13731379
let zig_cc = zig_linker_dir.join(format!("zigcc-{file_target}-{:x}.{file_ext}", hash));
13741380
let zig_cxx = zig_linker_dir.join(format!("zigcxx-{file_target}-{:x}.{file_ext}", hash));
13751381
let zig_ranlib = zig_linker_dir.join(format!("zigranlib.{file_ext}"));
1376-
write_linker_wrapper(&zig_cc, "cc", &cc_args_str)?;
1377-
write_linker_wrapper(&zig_cxx, "c++", &cc_args_str)?;
1378-
write_linker_wrapper(&zig_ranlib, "ranlib", "")?;
1382+
write_linker_wrapper(&current_exe, &zig_cc, "cc", &cc_args_str)?;
1383+
write_linker_wrapper(&current_exe, &zig_cxx, "c++", &cc_args_str)?;
1384+
write_linker_wrapper(&current_exe, &zig_ranlib, "ranlib", "")?;
13791385

13801386
let exe_ext = if cfg!(windows) { ".exe" } else { "" };
13811387
let zig_ar = zig_linker_dir.join(format!("ar{exe_ext}"));
@@ -1424,13 +1430,13 @@ fn symlink_wrapper(target: &Path) -> Result<()> {
14241430

14251431
/// Write a zig cc wrapper batch script for unix
14261432
#[cfg(target_family = "unix")]
1427-
fn write_linker_wrapper(path: &Path, command: &str, args: &str) -> Result<()> {
1433+
fn write_linker_wrapper(
1434+
current_exe: &PathBuf,
1435+
path: &Path,
1436+
command: &str,
1437+
args: &str,
1438+
) -> Result<()> {
14281439
let mut buf = Vec::<u8>::new();
1429-
let current_exe = if let Ok(exe) = env::var("CARGO_BIN_EXE_cargo-zigbuild") {
1430-
PathBuf::from(exe)
1431-
} else {
1432-
env::current_exe()?
1433-
};
14341440
writeln!(&mut buf, "#!/bin/sh")?;
14351441
writeln!(
14361442
&mut buf,
@@ -1458,13 +1464,13 @@ fn write_linker_wrapper(path: &Path, command: &str, args: &str) -> Result<()> {
14581464

14591465
/// Write a zig cc wrapper batch script for windows
14601466
#[cfg(not(target_family = "unix"))]
1461-
fn write_linker_wrapper(path: &Path, command: &str, args: &str) -> Result<()> {
1467+
fn write_linker_wrapper(
1468+
current_exe: &PathBuf,
1469+
path: &Path,
1470+
command: &str,
1471+
args: &str,
1472+
) -> Result<()> {
14621473
let mut buf = Vec::<u8>::new();
1463-
let current_exe = if let Ok(exe) = env::var("CARGO_BIN_EXE_cargo-zigbuild") {
1464-
PathBuf::from(exe)
1465-
} else {
1466-
env::current_exe()?
1467-
};
14681474
let current_exe = if is_mingw_shell() {
14691475
current_exe.to_slash_lossy().to_string()
14701476
} else {

0 commit comments

Comments
 (0)