Skip to content

Commit c052645

Browse files
authored
Rollup merge of rust-lang#140154 - Berrysoft:cygwin-host, r=jieyouxu
Cygwin support in rustc This PR builds host rustc targeting cygwin. - [x] rust-lang/stacker#122 - [x] nagisa/rust_libloading#173 - [x] Detegr/rust-ctrlc#131 - [x] rust-random/getrandom#654 - [x] msys2/MSYS2-packages#5350 - [x] rust-lang#140886 - [x] rust-lang#140921 - [x] rust-lang#140973 Currently supported: * rustc * rustdoc * rustfmt * clippy Blocking: * cargo: blocked by rust-lang/socket2#568 * rust-analyzer: needs `cargo update`, fixed upstream ``` $ rustc --version --verbose rustc 1.88.0-dev binary: rustc commit-hash: unknown commit-date: unknown host: x86_64-pc-cygwin release: 1.88.0-dev LLVM version: 20.1.4 ```
2 parents 77f54d1 + 12c8fb8 commit c052645

File tree

6 files changed

+20
-8
lines changed

6 files changed

+20
-8
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

+10-4
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,16 @@ fn current_dll_path() -> Result<PathBuf, String> {
7878
if libc::dladdr(addr, &mut info) == 0 {
7979
return Err("dladdr failed".into());
8080
}
81-
if info.dli_fname.is_null() {
82-
return Err("dladdr returned null pointer".into());
83-
}
84-
let bytes = CStr::from_ptr(info.dli_fname).to_bytes();
81+
#[cfg(target_os = "cygwin")]
82+
let fname_ptr = info.dli_fname.as_ptr();
83+
#[cfg(not(target_os = "cygwin"))]
84+
let fname_ptr = {
85+
if info.dli_fname.is_null() {
86+
return Err("dladdr returned null pointer".into());
87+
}
88+
info.dli_fname
89+
};
90+
let bytes = CStr::from_ptr(fname_ptr).to_bytes();
8591
let os = OsStr::from_bytes(bytes);
8692
Ok(PathBuf::from(os))
8793
}

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

+1-1
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"

src/tools/miri/src/shims/native_lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
117117
let mut info = std::mem::MaybeUninit::<libc::Dl_info>::uninit();
118118
unsafe {
119119
if libc::dladdr(*func.deref() as *const _, info.as_mut_ptr()) != 0 {
120-
if std::ffi::CStr::from_ptr(info.assume_init().dli_fname).to_str().unwrap()
120+
let info = info.assume_init();
121+
#[cfg(target_os = "cygwin")]
122+
let fname_ptr = info.dli_fname.as_ptr();
123+
#[cfg(not(target_os = "cygwin"))]
124+
let fname_ptr = info.dli_fname;
125+
if std::ffi::CStr::from_ptr(fname_ptr).to_str().unwrap()
121126
!= _lib_path.to_str().unwrap()
122127
{
123128
return None;

0 commit comments

Comments
 (0)