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 #4279

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

Berrysoft
Copy link
Contributor

Description

rust-lang/rust#134999

Most changes are ported from https://github.com/ookiineko-cygport/libc

Sources

https://github.com/cygwin/cygwin/tree/main/winsup/cygwin/include

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI

I'm not sure how to test a no_std target. Actually I need these changes to implement std for cygwin target.

Berrysoft and others added 2 commits February 22, 2025 23:06
Co-authored-by: Ookiineko <[email protected]>
Co-authored-by: Ookiineko <[email protected]>
@rustbot
Copy link
Collaborator

rustbot commented Feb 22, 2025

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@Berrysoft
Copy link
Contributor Author

Stable compilers failed because cygwin target is only supported by nightly ones nowadays. Are there some ways to solve this problem?

@tgross35
Copy link
Contributor

Stable compilers failed because cygwin target is only supported by nightly ones nowadays. Are there some ways to solve this problem?

If it's just check-cfg failing, then it needs an update in

libc/build.rs

Line 25 in 3695157

const CHECK_CFG_EXTRA: &'static [(&'static str, &'static [&'static str])] = &[

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

Most of this looks pretty good but there are a handful of changes to get this more in line with the other OSs.

Does cygwin only ever use newlib, or are there other libc implementations?


cfg.skip_const(move |name| {
match name {
// FIXME: these constants do not exist on Cygwin
Copy link
Contributor

Choose a reason for hiding this comment

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

Could add a tag like FIXME(cygwin) for all FIXMEs? We're trying to get everything greppable.

@@ -136,9 +136,18 @@ s! {
}

pub struct hostent {
Copy link
Contributor

Choose a reason for hiding this comment

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

hostent and linger seem to have pretty different definitions between Cygwin and the rest of Unix. Would it be possible to move the existing structures into a cfg(not(target_os = "cygwin")) block, then redefine them in cygwin/mod.rs instead?

Comment on lines +4 to +6
pub type c_char = i8;
pub type c_long = i64;
pub type c_ulong = u64;
Copy link
Contributor

Choose a reason for hiding this comment

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

These shouldn't be needed, the types are now defined in primitives.rs

Comment on lines +8 to +15
cfg_if! {
if #[cfg(doc)] {
pub(crate) type Ioctl = c_int;
} else {
#[doc(hidden)]
pub type Ioctl = c_int;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this config needed?

Comment on lines +44 to +51
#[cfg_attr(feature = "extra_traits", derive(Debug))]
pub enum timezone {}
impl Copy for timezone {}
impl Clone for timezone {
fn clone(&self) -> timezone {
*self
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this go in an e! macro so it gets these derived? Same for enum sem.

}
}

s_no_extra_traits! {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do all of the items here need to be in s_no_extra_traits? It looks like at least a few of them don't have an alignment requirement or contain a union so could probably go in s!.

}
}

impl PartialEq for __c_anonymous_ifr_ifru {
Copy link
Contributor

Choose a reason for hiding this comment

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

We aren't doing any traits that read values for unions anymore, or anything that contains them, since the implementations are too often unsound (as is the case here, possible uninitialized data read). So please drop these, the unions should still get a default debug impl from

libc/src/macros.rs

Lines 163 to 168 in 268e1b3

#[cfg(feature = "extra_traits")]
impl ::core::fmt::Debug for $i {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct(::core::stringify!($i)).finish_non_exhaustive()
}
}
.

Comment on lines +2477 to +2486
// intentionally not public, only used for fd_set
cfg_if! {
if #[cfg(target_pointer_width = "32")] {
const ULONG_SIZE: usize = 32;
} else if #[cfg(target_pointer_width = "64")] {
const ULONG_SIZE: usize = 64;
} else {
// Unknown target_pointer_width
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could these use core::mem::size_of::<c_ulong>() instead?

Comment on lines +2514 to +2515
let _dummy: cpu_set_t = core::mem::zeroed();
let size_in_bits = 8 * core::mem::size_of_val(&_dummy.bits[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

core::mem::zeroed() is advised against nowadays. Could this just be cpu_set_t { bits: [0; 16] }?

Applies a couple of other places.

Comment on lines +375 to +382
pub struct siginfo_t {
pub si_signo: c_int,
pub si_code: c_int,
pub si_pid: pid_t,
pub si_uid: uid_t,
pub si_errno: c_int,
__pad: [u32; 32],
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants