about summary refs log tree commit diff
path: root/compiler/rustc_session/src/filesearch.rs
diff options
context:
space:
mode:
author王宇逸 <Strawberry_Str@hotmail.com>2025-04-22 16:16:23 +0800
committer王宇逸 <Strawberry_Str@hotmail.com>2025-05-15 23:34:11 +0800
commit49553be30784711d7dc6976ef1335b74df7cbe44 (patch)
tree4a507fb5e6dcd0c847672e2ed87c4375fe060ece /compiler/rustc_session/src/filesearch.rs
parentd163a28381c297a56417d4a5dfe88c6c65429265 (diff)
downloadrust-49553be30784711d7dc6976ef1335b74df7cbe44.tar.gz
rust-49553be30784711d7dc6976ef1335b74df7cbe44.zip
Experimental cygwin support in rustc
Co-authored-by: Ookiineko <chiisaineko@protonmail.com>
Diffstat (limited to 'compiler/rustc_session/src/filesearch.rs')
-rw-r--r--compiler/rustc_session/src/filesearch.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/compiler/rustc_session/src/filesearch.rs b/compiler/rustc_session/src/filesearch.rs
index bdeca91eb64..2a85f44278a 100644
--- a/compiler/rustc_session/src/filesearch.rs
+++ b/compiler/rustc_session/src/filesearch.rs
@@ -58,7 +58,7 @@ pub fn make_target_bin_path(sysroot: &Path, target_triple: &str) -> PathBuf {
     sysroot.join(rustlib_path).join("bin")
 }
 
-#[cfg(unix)]
+#[cfg(all(unix, not(target_os = "cygwin")))]
 fn current_dll_path() -> Result<PathBuf, String> {
     use std::sync::OnceLock;
 
@@ -132,6 +132,23 @@ fn current_dll_path() -> Result<PathBuf, String> {
         .clone()
 }
 
+#[cfg(target_os = "cygwin")]
+fn current_dll_path() -> Result<PathBuf, String> {
+    use std::ffi::{CStr, OsStr};
+    use std::os::unix::prelude::*;
+
+    unsafe {
+        let addr = current_dll_path as usize as *mut _;
+        let mut info = std::mem::zeroed();
+        if libc::dladdr(addr, &mut info) == 0 {
+            return Err("dladdr failed".into());
+        }
+        let bytes = CStr::from_ptr(info.dli_fname.as_ptr()).to_bytes();
+        let os = OsStr::from_bytes(bytes);
+        Ok(PathBuf::from(os))
+    }
+}
+
 #[cfg(windows)]
 fn current_dll_path() -> Result<PathBuf, String> {
     use std::ffi::OsString;