Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cygwin support #774

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ mod c {
("__fe_raise_inexact", "fp_mode.c"),
]);

if target.os != "windows" {
if target.os != "windows" && target.os != "cygwin" {
sources.extend(&[("__multc3", "multc3.c")]);
}
}
Expand Down Expand Up @@ -608,13 +608,15 @@ mod c {
sources.remove(&["__aeabi_cdcmp", "__aeabi_cfcmp"]);
}

// Android uses emulated TLS so we need a runtime support function.
if target.os == "android" {
// Android and Cygwin uses emulated TLS so we need a runtime support function.
if target.os == "android" || target.os == "cygwin" {
sources.extend(&[("__emutls_get_address", "emutls.c")]);
}

// Work around a bug in the NDK headers (fixed in
// https://r.android.com/2038949 which will be released in a future
// NDK version) by providing a definition of LONG_BIT.
// Work around a bug in the NDK headers (fixed in
// https://r.android.com/2038949 which will be released in a future
// NDK version) by providing a definition of LONG_BIT.
if target.os == "android" {
cfg.define("LONG_BIT", "(8 * sizeof(long))");
}

Expand Down
6 changes: 3 additions & 3 deletions examples/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,17 +673,17 @@ pub fn __aeabi_unwind_cpp_pr0() {}
#[no_mangle]
pub fn __aeabi_unwind_cpp_pr1() {}

#[cfg(not(windows))]
#[cfg(not(any(windows, target_os = "cygwin")))]
#[allow(non_snake_case)]
#[no_mangle]
pub fn _Unwind_Resume() {}

#[cfg(not(windows))]
#[cfg(not(any(windows, target_os = "cygwin")))]
#[lang = "eh_personality"]
#[no_mangle]
pub extern "C" fn eh_personality() {}

#[cfg(all(windows, target_env = "gnu"))]
#[cfg(any(all(windows, target_env = "gnu"), target_os = "cygwin"))]
mod mingw_unwinding {
#[no_mangle]
pub fn rust_eh_personality() {}
Expand Down
18 changes: 9 additions & 9 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ macro_rules! intrinsics {

$($rest:tt)*
) => (
#[cfg(all(any(windows, all(target_os = "uefi", target_arch = "x86_64")), target_pointer_width = "64"))]
#[cfg(all(any(windows, target_os = "cygwin", all(target_os = "uefi", target_arch = "x86_64")), target_pointer_width = "64"))]
intrinsics! {
$(#[$($attr)*])*
pub extern "unadjusted" fn $name( $($argname: $ty),* ) $(-> $ret)? {
$($body)*
}
}

#[cfg(not(all(any(windows, all(target_os = "uefi", target_arch = "x86_64")), target_pointer_width = "64")))]
#[cfg(not(all(any(windows, target_os = "cygwin", all(target_os = "uefi", target_arch = "x86_64")), target_pointer_width = "64")))]
intrinsics! {
$(#[$($attr)*])*
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
Expand Down Expand Up @@ -257,7 +257,7 @@ macro_rules! intrinsics {
#[cfg(all(target_vendor = "apple", any(target_arch = "x86", target_arch = "x86_64"), not(feature = "mangled-names")))]
mod $name {
#[no_mangle]
#[cfg_attr(not(all(windows, target_env = "gnu")), linkage = "weak")]
#[cfg_attr(not(any(all(windows, target_env = "gnu"), target_os = "cygwin")), linkage = "weak")]
$(#[$($attr)*])*
extern $abi fn $name( $($argname: u16),* ) $(-> $ret)? {
super::$name($(f16::from_bits($argname)),*)
Expand Down Expand Up @@ -293,7 +293,7 @@ macro_rules! intrinsics {
#[cfg(all(target_vendor = "apple", any(target_arch = "x86", target_arch = "x86_64"), not(feature = "mangled-names")))]
mod $name {
#[no_mangle]
#[cfg_attr(not(all(windows, target_env = "gnu")), linkage = "weak")]
#[cfg_attr(not(any(all(windows, target_env = "gnu"), target_os = "cygwin")), linkage = "weak")]
$(#[$($attr)*])*
extern $abi fn $name( $($argname: $ty),* ) -> u16 {
super::$name($($argname),*).to_bits()
Expand Down Expand Up @@ -334,7 +334,7 @@ macro_rules! intrinsics {
#[cfg(all(target_arch = "arm", not(feature = "mangled-names")))]
mod $name {
#[no_mangle]
#[cfg_attr(not(all(windows, target_env = "gnu")), linkage = "weak")]
#[cfg_attr(not(any(all(windows, target_env = "gnu"), target_os = "cygwin")), linkage = "weak")]
$(#[$($attr)*])*
extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
super::$name($($argname),*)
Expand All @@ -344,7 +344,7 @@ macro_rules! intrinsics {
#[cfg(all(target_arch = "arm", not(feature = "mangled-names")))]
mod $alias {
#[no_mangle]
#[cfg_attr(not(all(windows, target_env = "gnu")), linkage = "weak")]
#[cfg_attr(not(any(all(windows, target_env = "gnu"), target_os = "cygwin")), linkage = "weak")]
$(#[$($attr)*])*
extern "aapcs" fn $alias( $($argname: $ty),* ) $(-> $ret)? {
super::$name($($argname),*)
Expand Down Expand Up @@ -411,7 +411,7 @@ macro_rules! intrinsics {
mod $name {
$(#[$($attr)*])*
#[no_mangle]
#[cfg_attr(not(all(windows, target_env = "gnu")), linkage = "weak")]
#[cfg_attr(not(any(all(windows, target_env = "gnu"), target_os = "cygwin")), linkage = "weak")]
unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
super::$name($($argname),*)
}
Expand All @@ -436,7 +436,7 @@ macro_rules! intrinsics {
#[naked]
$(#[$($attr)*])*
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
#[cfg_attr(not(all(windows, target_env = "gnu")), linkage = "weak")]
#[cfg_attr(not(any(all(windows, target_env = "gnu"), target_os = "cygwin")), linkage = "weak")]
pub unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
$($body)*
}
Expand Down Expand Up @@ -503,7 +503,7 @@ macro_rules! intrinsics {
mod $name {
$(#[$($attr)*])*
#[no_mangle]
#[cfg_attr(not(all(windows, target_env = "gnu")), linkage = "weak")]
#[cfg_attr(not(any(all(windows, target_env = "gnu"), target_os = "cygwin")), linkage = "weak")]
$(unsafe $($empty)?)? extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
super::$name($($argname),*)
}
Expand Down
4 changes: 2 additions & 2 deletions src/probestack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
//! be more than welcome to accept such a change!

#![cfg(not(feature = "mangled-names"))]
// Windows already has builtins to do this.
#![cfg(not(windows))]
// Windows and Cygwin already has builtins to do this.
#![cfg(not(any(windows, target_os = "cygwin")))]
Comment on lines +45 to +46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit if you have time, s/has/have/

// All these builtins require assembly
#![cfg(not(feature = "no-asm"))]
// We only define stack probing for these architectures today.
Expand Down
6 changes: 5 additions & 1 deletion src/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ use core::intrinsics;
intrinsics! {
#[naked]
#[cfg(all(
any(all(windows, target_env = "gnu"), target_os = "uefi"),
any(
all(windows, target_env = "gnu"),
target_os = "cygwin",
target_os = "uefi"
),
not(feature = "no-asm")
))]
pub unsafe extern "C" fn ___chkstk_ms() {
Expand Down