@@ -12,6 +12,8 @@ use std::str;
12
12
use anyhow:: { anyhow, bail, Context , Result } ;
13
13
use fs_err as fs;
14
14
use path_slash:: PathBufExt ;
15
+ #[ cfg( not( target_family = "unix" ) ) ]
16
+ use path_slash:: PathExt ;
15
17
use serde:: Deserialize ;
16
18
use target_lexicon:: { Architecture , Environment , OperatingSystem , Triple } ;
17
19
@@ -1368,14 +1370,20 @@ pub fn prepare_zig_linker(target: &str) -> Result<ZigWrapper> {
1368
1370
}
1369
1371
}
1370
1372
1373
+ let current_exe = if let Ok ( exe) = env:: var ( "CARGO_BIN_EXE_cargo-zigbuild" ) {
1374
+ PathBuf :: from ( exe)
1375
+ } else {
1376
+ env:: current_exe ( ) ?
1377
+ } ;
1371
1378
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 ( ) ) ;
1379
+ let hash_input = current_exe. display ( ) . to_string ( ) + & cc_args_str;
1380
+ let hash = crc:: Crc :: < u16 > :: new ( & crc:: CRC_16_IBM_SDLC ) . checksum ( hash_input. as_bytes ( ) ) ;
1373
1381
let zig_cc = zig_linker_dir. join ( format ! ( "zigcc-{file_target}-{:x}.{file_ext}" , hash) ) ;
1374
1382
let zig_cxx = zig_linker_dir. join ( format ! ( "zigcxx-{file_target}-{:x}.{file_ext}" , hash) ) ;
1375
1383
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" , "" ) ?;
1384
+ write_linker_wrapper ( & current_exe , & zig_cc, "cc" , & cc_args_str) ?;
1385
+ write_linker_wrapper ( & current_exe , & zig_cxx, "c++" , & cc_args_str) ?;
1386
+ write_linker_wrapper ( & current_exe , & zig_ranlib, "ranlib" , "" ) ?;
1379
1387
1380
1388
let exe_ext = if cfg ! ( windows) { ".exe" } else { "" } ;
1381
1389
let zig_ar = zig_linker_dir. join ( format ! ( "ar{exe_ext}" ) ) ;
@@ -1424,13 +1432,13 @@ fn symlink_wrapper(target: &Path) -> Result<()> {
1424
1432
1425
1433
/// Write a zig cc wrapper batch script for unix
1426
1434
#[ cfg( target_family = "unix" ) ]
1427
- fn write_linker_wrapper ( path : & Path , command : & str , args : & str ) -> Result < ( ) > {
1435
+ fn write_linker_wrapper (
1436
+ current_exe : & Path ,
1437
+ path : & Path ,
1438
+ command : & str ,
1439
+ args : & str ,
1440
+ ) -> Result < ( ) > {
1428
1441
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
- } ;
1434
1442
writeln ! ( & mut buf, "#!/bin/sh" ) ?;
1435
1443
writeln ! (
1436
1444
& mut buf,
@@ -1458,13 +1466,13 @@ fn write_linker_wrapper(path: &Path, command: &str, args: &str) -> Result<()> {
1458
1466
1459
1467
/// Write a zig cc wrapper batch script for windows
1460
1468
#[ cfg( not( target_family = "unix" ) ) ]
1461
- fn write_linker_wrapper ( path : & Path , command : & str , args : & str ) -> Result < ( ) > {
1469
+ fn write_linker_wrapper (
1470
+ current_exe : & Path ,
1471
+ path : & Path ,
1472
+ command : & str ,
1473
+ args : & str ,
1474
+ ) -> Result < ( ) > {
1462
1475
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
- } ;
1468
1476
let current_exe = if is_mingw_shell ( ) {
1469
1477
current_exe. to_slash_lossy ( ) . to_string ( )
1470
1478
} else {
0 commit comments