Skip to content

Commit 49553be

Browse files
BerrysoftOokiineko
and
Ookiineko
committed
Experimental cygwin support in rustc
Co-authored-by: Ookiineko <[email protected]>
1 parent d163a28 commit 49553be

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

compiler/rustc_llvm/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ fn main() {
255255
} else if target.contains("haiku")
256256
|| target.contains("darwin")
257257
|| (is_crossed && (target.contains("dragonfly") || target.contains("solaris")))
258+
|| target.contains("cygwin")
258259
{
259260
println!("cargo:rustc-link-lib=z");
260261
} else if target.contains("netbsd") {

compiler/rustc_session/src/filesearch.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn make_target_bin_path(sysroot: &Path, target_triple: &str) -> PathBuf {
5858
sysroot.join(rustlib_path).join("bin")
5959
}
6060

61-
#[cfg(unix)]
61+
#[cfg(all(unix, not(target_os = "cygwin")))]
6262
fn current_dll_path() -> Result<PathBuf, String> {
6363
use std::sync::OnceLock;
6464

@@ -132,6 +132,23 @@ fn current_dll_path() -> Result<PathBuf, String> {
132132
.clone()
133133
}
134134

135+
#[cfg(target_os = "cygwin")]
136+
fn current_dll_path() -> Result<PathBuf, String> {
137+
use std::ffi::{CStr, OsStr};
138+
use std::os::unix::prelude::*;
139+
140+
unsafe {
141+
let addr = current_dll_path as usize as *mut _;
142+
let mut info = std::mem::zeroed();
143+
if libc::dladdr(addr, &mut info) == 0 {
144+
return Err("dladdr failed".into());
145+
}
146+
let bytes = CStr::from_ptr(info.dli_fname.as_ptr()).to_bytes();
147+
let os = OsStr::from_bytes(bytes);
148+
Ok(PathBuf::from(os))
149+
}
150+
}
151+
135152
#[cfg(windows)]
136153
fn current_dll_path() -> Result<PathBuf, String> {
137154
use std::ffi::OsString;

src/bootstrap/src/core/builder/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ impl<'a> Builder<'a> {
13881388
// Windows doesn't need dylib path munging because the dlls for the
13891389
// compiler live next to the compiler and the system will find them
13901390
// automatically.
1391-
if cfg!(windows) {
1391+
if cfg!(any(windows, target_os = "cygwin")) {
13921392
return;
13931393
}
13941394

src/bootstrap/src/utils/helpers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub fn is_debug_info(name: &str) -> bool {
130130
/// Returns the corresponding relative library directory that the compiler's
131131
/// dylibs will be found in.
132132
pub fn libdir(target: TargetSelection) -> &'static str {
133-
if target.is_windows() { "bin" } else { "lib" }
133+
if target.is_windows() || target.contains("cygwin") { "bin" } else { "lib" }
134134
}
135135

136136
/// Adds a list of lookup paths to `cmd`'s dynamic library lookup path.

src/bootstrap/src/utils/shared_helpers.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::str::FromStr;
2020
/// Returns the environment variable which the dynamic library lookup path
2121
/// resides in for this platform.
2222
pub fn dylib_path_var() -> &'static str {
23-
if cfg!(target_os = "windows") {
23+
if cfg!(any(target_os = "windows", target_os = "cygwin")) {
2424
"PATH"
2525
} else if cfg!(target_vendor = "apple") {
2626
"DYLD_LIBRARY_PATH"
@@ -46,7 +46,7 @@ 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+
if target.contains("windows") || target.contains("cygwin") {
5050
format!("{name}.exe")
5151
} else if target.contains("uefi") {
5252
format!("{name}.efi")

0 commit comments

Comments
 (0)