Skip to content

Commit 86760c2

Browse files
authored
Unrolled build for #141374
Rollup merge of #141374 - jeremyd2019:patch-1, r=jieyouxu make shared_helpers exe function work for both cygwin and non-cygwin hosts On Cygwin, it needs to not append .exe, because /proc/self/exe (and therefore `std::env::current_exe`) does not include the .exe extension, breaking bootstrap's rustc wrapper. On hosts other than Cygwin, it *does* need to append .exe because the file really does have a .exe extension, and non-Cygwin hosts won't be doing the same filename rewriting that Cygwin does when looking for a file X but finding only X.exe in its place. Arising from discussion in #140154 (review) ``@mati865`` ``@Berrysoft``
2 parents e88e854 + 1f862a8 commit 86760c2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/bootstrap/src/utils/shared_helpers.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,16 @@ pub fn dylib_path() -> Vec<std::path::PathBuf> {
4646
/// Given an executable called `name`, return the filename for the
4747
/// executable for a particular target.
4848
pub fn exe(name: &str, target: &str) -> String {
49-
if target.contains("windows") {
49+
// On Cygwin, the decision to append .exe or not is not as straightforward.
50+
// Executable files do actually have .exe extensions so on hosts other than
51+
// Cygwin it is necessary. But on a Cygwin host there is magic happening
52+
// that redirects requests for file X to file X.exe if it exists, and
53+
// furthermore /proc/self/exe (and thus std::env::current_exe) always
54+
// returns the name *without* the .exe extension. For comparisons against
55+
// that to match, we therefore do not append .exe for Cygwin targets on
56+
// a Cygwin host.
57+
if target.contains("windows") || (cfg!(not(target_os = "cygwin")) && target.contains("cygwin"))
58+
{
5059
format!("{name}.exe")
5160
} else if target.contains("uefi") {
5261
format!("{name}.efi")

0 commit comments

Comments
 (0)