Repository: tokio-rs/tokio (language: rust)

Issue:
Can't build Tokio crate, on Haiku
**Version**
List the versions of all `tokio` crates you are using. The easiest way to get
this information is using `cargo tree` subcommand:
```
  Downloaded tokio v1.41.1
  Downloaded tokio-util v0.7.12
  Downloaded tokio-tungstenite v0.21.0
  Downloaded tokio-rustls v0.26.0
  Downloaded tokio-macros v2.4.0
  Downloaded tokio-io-utility v0.7.6
   Compiling tokio-macros v2.4.0
```

**Platform**
The output of `uname -a` (UNIX), or version and 32 or 64-bit (Windows)
Haiku shredder 1 hrev57937+125 Oct 26 2024 21:25 x86_64 x86_64 Haiku
 
**Description**
After installing Rust 1.83.0, on Haiku, along with OpenSSL 1.1.1w-2, and attempting to build the "rustic-rs" project, using Cargo, I encountered a failure to build the Tokio crate:

```
   Compiling tokio v1.41.1
error[E0425]: cannot find function `get_peer_cred` in module `ucred`
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/unix/stream.rs:932:16
    |
932 |         ucred::get_peer_cred(self)
    |                ^^^^^^^^^^^^^ not found in `ucred`
    |
note: found an item that was configured out
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/unix/ucred.rs:40:34
    |
40  | pub(crate) use self::impl_linux::get_peer_cred;
    |                                  ^^^^^^^^^^^^^
note: the item is gated here
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/unix/ucred.rs:34:1
    |
34  | / #[cfg(any(
35  | |     target_os = "linux",
36  | |     target_os = "redox",
37  | |     target_os = "android",
38  | |     target_os = "openbsd"
39  | | ))]
    | |___^
note: found an item that was configured out
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/unix/ucred.rs:43:35
    |
43  | pub(crate) use self::impl_netbsd::get_peer_cred;
    |                                   ^^^^^^^^^^^^^
note: the item is gated here
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/unix/ucred.rs:42:1
    |
42  | #[cfg(any(target_os = "netbsd", target_os = "nto"))]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: found an item that was configured out
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/unix/ucred.rs:46:32
    |
46  | pub(crate) use self::impl_bsd::get_peer_cred;
    |                                ^^^^^^^^^^^^^
note: the item is gated here
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/unix/ucred.rs:45:1
    |
45  | #[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: found an item that was configured out
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/unix/ucred.rs:55:34
    |
55  | pub(crate) use self::impl_macos::get_peer_cred;
    |                                  ^^^^^^^^^^^^^
note: the item is gated here
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/unix/ucred.rs:48:1
    |
48  | / #[cfg(any(
49  | |     target_os = "macos",
50  | |     target_os = "ios",
51  | |     target_os = "tvos",
52  | |     target_os = "watchos",
53  | |     target_os = "visionos"
54  | | ))]
    | |___^
note: found an item that was configured out
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/unix/ucred.rs:58:36
    |
58  | pub(crate) use self::impl_solaris::get_peer_cred;
    |                                    ^^^^^^^^^^^^^
note: the item is gated here
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/unix/ucred.rs:57:1
    |
57  | #[cfg(any(target_os = "solaris", target_os = "illumos"))]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: found an item that was configured out
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/unix/ucred.rs:61:32
    |
61  | pub(crate) use self::impl_aix::get_peer_cred;
    |                                ^^^^^^^^^^^^^
note: the item is gated behind the `aix` feature
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/unix/ucred.rs:60:7
    |
60  | #[cfg(target_os = "aix")]
    |       ^^^^^^^^^^^^^^^^^
note: found an item that was configured out
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/unix/ucred.rs:64:35
    |
64  | pub(crate) use self::impl_noproc::get_peer_cred;
    |                                   ^^^^^^^^^^^^^
note: the item is gated here
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/unix/ucred.rs:63:1
    |
63  | #[cfg(any(target_os = "espidf", target_os = "vita"))]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0425]: cannot find value `SIGIO` in crate `libc`
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/signal/unix.rs:152:20
    |
152 |         Self(libc::SIGIO)
    |                    ^^^^^ help: a constant with a similar name exists: `SIGIOT`
    |
   ::: /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.167/src/unix/mod.rs:247:1
    |
247 | pub const SIGIOT: c_int = 6;
    | ----------------------- similarly named constant `SIGIOT` defined here

   Compiling zerofrom-derive v0.1.5
error[E0599]: no method named `tos` found for struct `Socket` in the current scope
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/tcp/socket.rs:483:20
    |
483 |         self.inner.tos()
    |                    ^^^ method not found in `Socket`

error[E0599]: no method named `set_tos` found for struct `Socket` in the current scope
   --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/tcp/socket.rs:510:20
    |
510 |         self.inner.set_tos(tos)
    |                    ^^^^^^^
    |
help: there is a method `set_mss` with a similar name
    |
510 |         self.inner.set_mss(tos)
    |                    ~~~~~~~

error[E0599]: no method named `tos` found for struct `SockRef<'_>` in the current scope
    --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/udp.rs:1878:26
     |
1878 |         self.as_socket().tos()
     |         ----             ^^^ method not found in `SockRef<'_>`
     |         |
     |         method `tos` is available on `&udp::UdpSocket`

error[E0599]: no method named `set_tos` found for struct `SockRef<'_>` in the current scope
    --> /boot/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/net/udp.rs:1905:26
     |
1905 |         self.as_socket().set_tos(tos)
     |         ----             ^^^^^^^
     |         |
     |         method `set_tos` is available on `&udp::UdpSocket`
     |
help: there is a method `set_mss` with a similar name
     |
1905 |         self.as_socket().set_mss(tos)
     |                          ~~~~~~~

```

As I am unfamiliar with the Rust ecosystem, and the Rust language, I figured that it'd make sense, to report this as a Tokio bug, to get the most "bang for the buck", in terms of enabling stuff to build. (There's a sibling bug, at https://github.com/haikuports/haikuports/issues/11407, that bundles together issues related to this, on the Haiku side).

Unfortunately, I don't have an example of code that triggers this error, as it applies during the process of building the crate, itself, as a prerequisite.

Apologies, if this has already been reported, or if I'm better off, reporting it elsewhere...


Discussion / hints:
@Thomasdezeeuw What is the state of haiku support in mio/socket2?
Haiku is supported in both Mio and socket2 with CI (using `cargo check`). However in socket2 it doesn't support all options, so this might be as simple as checking if the missing options are supported on Haiku or disabling/`cfg`ing-out the code in Tokio. 

Fix patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 3718cfa1c55..407df8a4a54 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -467,6 +467,7 @@ jobs:
     strategy:
       matrix:
         target:
+          - name: x86_64-unknown-haiku
           - name: armv7-sony-vita-newlibeabihf
             exclude_features: "process,signal,rt-process-signal,full"
     steps:
diff --git a/tokio/src/net/tcp/socket.rs b/tokio/src/net/tcp/socket.rs
index 33b71485473..762546ee309 100644
--- a/tokio/src/net/tcp/socket.rs
+++ b/tokio/src/net/tcp/socket.rs
@@ -469,6 +469,7 @@ impl TcpSocket {
         target_os = "redox",
         target_os = "solaris",
         target_os = "illumos",
+        target_os = "haiku"
     )))]
     #[cfg_attr(
         docsrs,
@@ -477,6 +478,7 @@ impl TcpSocket {
             target_os = "redox",
             target_os = "solaris",
             target_os = "illumos",
+            target_os = "haiku"
         ))))
     )]
     pub fn tos(&self) -> io::Result<u32> {
@@ -496,6 +498,7 @@ impl TcpSocket {
         target_os = "redox",
         target_os = "solaris",
         target_os = "illumos",
+        target_os = "haiku"
     )))]
     #[cfg_attr(
         docsrs,
@@ -504,6 +507,7 @@ impl TcpSocket {
             target_os = "redox",
             target_os = "solaris",
             target_os = "illumos",
+            target_os = "haiku"
         ))))
     )]
     pub fn set_tos(&self, tos: u32) -> io::Result<()> {
diff --git a/tokio/src/net/udp.rs b/tokio/src/net/udp.rs
index a34f7b9225b..58bf566a728 100644
--- a/tokio/src/net/udp.rs
+++ b/tokio/src/net/udp.rs
@@ -1864,6 +1864,7 @@ impl UdpSocket {
         target_os = "redox",
         target_os = "solaris",
         target_os = "illumos",
+        target_os = "haiku"
     )))]
     #[cfg_attr(
         docsrs,
@@ -1872,6 +1873,7 @@ impl UdpSocket {
             target_os = "redox",
             target_os = "solaris",
             target_os = "illumos",
+            target_os = "haiku"
         ))))
     )]
     pub fn tos(&self) -> io::Result<u32> {
@@ -1891,6 +1893,7 @@ impl UdpSocket {
         target_os = "redox",
         target_os = "solaris",
         target_os = "illumos",
+        target_os = "haiku"
     )))]
     #[cfg_attr(
         docsrs,
@@ -1899,6 +1902,7 @@ impl UdpSocket {
             target_os = "redox",
             target_os = "solaris",
             target_os = "illumos",
+            target_os = "haiku"
         ))))
     )]
     pub fn set_tos(&self, tos: u32) -> io::Result<()> {
diff --git a/tokio/src/net/unix/ucred.rs b/tokio/src/net/unix/ucred.rs
index bcd1c755f6a..74e596bc9b6 100644
--- a/tokio/src/net/unix/ucred.rs
+++ b/tokio/src/net/unix/ucred.rs
@@ -35,7 +35,8 @@ impl UCred {
     target_os = "linux",
     target_os = "redox",
     target_os = "android",
-    target_os = "openbsd"
+    target_os = "openbsd",
+    target_os = "haiku"
 ))]
 pub(crate) use self::impl_linux::get_peer_cred;
 
@@ -67,7 +68,8 @@ pub(crate) use self::impl_noproc::get_peer_cred;
     target_os = "linux",
     target_os = "redox",
     target_os = "android",
-    target_os = "openbsd"
+    target_os = "openbsd",
+    target_os = "haiku"
 ))]
 pub(crate) mod impl_linux {
     use crate::net::unix::{self, UnixStream};
@@ -77,7 +79,12 @@ pub(crate) mod impl_linux {
 
     #[cfg(target_os = "openbsd")]
     use libc::sockpeercred as ucred;
-    #[cfg(any(target_os = "linux", target_os = "redox", target_os = "android"))]
+    #[cfg(any(
+        target_os = "linux",
+        target_os = "redox",
+        target_os = "android",
+        target_os = "haiku"
+    ))]
     use libc::ucred;
 
     pub(crate) fn get_peer_cred(sock: &UnixStream) -> io::Result<super::UCred> {
diff --git a/tokio/src/signal/unix.rs b/tokio/src/signal/unix.rs
index 31e2905c02d..e70863b54b7 100644
--- a/tokio/src/signal/unix.rs
+++ b/tokio/src/signal/unix.rs
@@ -147,6 +147,15 @@ impl SignalKind {
         Self(libc::SIGINT)
     }
 
+    #[cfg(target_os = "haiku")]
+    /// Represents the `SIGPOLL` signal.
+    ///
+    /// On POSIX systems this signal is sent when I/O operations are possible
+    /// on some file descriptor. By default, this signal is ignored.
+    pub const fn io() -> Self {
+        Self(libc::SIGPOLL)
+    }
+    #[cfg(not(target_os = "haiku"))]
     /// Represents the `SIGIO` signal.
     ///
     /// On Unix systems this signal is sent when I/O operations are possible


Test patch: