Skip to content

Commit

Permalink
Fix compilation on Hermit
Browse files Browse the repository at this point in the history
For some reason the `std::os::fd` module is not available on Hermit. It
seems like an oversight and I've opened
rust-lang/rust#126198 to track a fix.
  • Loading branch information
Thomasdezeeuw committed Jun 14, 2024
1 parent c9aee3b commit 1b7bac9
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/io_source.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use std::ops::{Deref, DerefMut};
#[cfg(any(unix, target_os = "hermit", target_os = "wasi"))]
#[cfg(any(unix, target_os = "wasi"))]
use std::os::fd::AsRawFd;
// TODO: once <https://github.com/rust-lang/rust/issues/126198> is fixed this
// can use `std::os::fd` and be merged with the above.
#[cfg(target_os = "hermit")]
use std::os::hermit::io::AsRawFd;
#[cfg(windows)]
use std::os::windows::io::AsRawSocket;
#[cfg(debug_assertions)]
Expand Down
6 changes: 5 additions & 1 deletion src/net/tcp/listener.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use std::net::{self, SocketAddr};
#[cfg(any(unix, target_os = "hermit", target_os = "wasi"))]
#[cfg(any(unix, target_os = "wasi"))]
use std::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
// TODO: once <https://github.com/rust-lang/rust/issues/126198> is fixed this
// can use `std::os::fd` and be merged with the above.
#[cfg(target_os = "hermit")]
use std::os::hermit::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
#[cfg(windows)]
use std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket};
use std::{fmt, io};
Expand Down
6 changes: 5 additions & 1 deletion src/net/tcp/stream.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use std::fmt;
use std::io::{self, IoSlice, IoSliceMut, Read, Write};
use std::net::{self, Shutdown, SocketAddr};
#[cfg(any(unix, target_os = "hermit", target_os = "wasi"))]
#[cfg(any(unix, target_os = "wasi"))]
use std::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
// TODO: once <https://github.com/rust-lang/rust/issues/126198> is fixed this
// can use `std::os::fd` and be merged with the above.
#[cfg(target_os = "hermit")]
use std::os::hermit::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
#[cfg(windows)]
use std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket};

Expand Down
6 changes: 5 additions & 1 deletion src/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
//! [portability guidelines]: ../struct.Poll.html#portability
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr};
#[cfg(any(unix, target_os = "hermit", target_os = "wasi"))]
#[cfg(any(unix, target_os = "wasi"))]
use std::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
// TODO: once <https://github.com/rust-lang/rust/issues/126198> is fixed this
// can use `std::os::fd` and be merged with the above.
#[cfg(target_os = "hermit")]
use std::os::hermit::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
#[cfg(windows)]
use std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket};
use std::{fmt, io, net};
Expand Down
12 changes: 8 additions & 4 deletions src/sys/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ cfg_net! {

cfg_io_source! {
use std::io;
#[cfg(any(unix))]
use std::os::fd::RawFd;
// TODO: once <https://github.com/rust-lang/rust/issues/126198> is fixed this
// can use `std::os::fd` and be merged with the above.
#[cfg(target_os = "hermit")]
use std::os::hermit::io::RawFd;
#[cfg(windows)]
use std::os::windows::io::RawSocket;
#[cfg(unix)]
use std::os::fd::RawFd;

#[cfg(any(windows, unix))]
#[cfg(any(windows, unix, target_os = "hermit"))]
use crate::{Registry, Token, Interest};

pub(crate) struct IoSourceState;
Expand All @@ -46,7 +50,7 @@ cfg_io_source! {
}
}

#[cfg(unix)]
#[cfg(any(unix, target_os = "hermit"))]
impl IoSourceState {
pub fn register(
&mut self,
Expand Down
5 changes: 5 additions & 0 deletions src/sys/unix/selector/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

use std::collections::HashMap;
use std::fmt::{Debug, Formatter};
#[cfg(not(target_os = "hermit"))]
use std::os::fd::{AsRawFd, RawFd};
// TODO: once <https://github.com/rust-lang/rust/issues/126198> is fixed this
// can use `std::os::fd` and be merged with the above.
#[cfg(target_os = "hermit")]
use std::os::hermit::io::{AsRawFd, RawFd};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::{Arc, Condvar, Mutex};
use std::time::Duration;
Expand Down
5 changes: 5 additions & 0 deletions src/sys/unix/sourcefd.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use std::io;
#[cfg(not(target_os = "hermit"))]
use std::os::fd::RawFd;
// TODO: once <https://github.com/rust-lang/rust/issues/126198> is fixed this
// can use `std::os::fd` and be merged with the above.
#[cfg(target_os = "hermit")]
use std::os::hermit::io::RawFd;

use crate::{event, Interest, Registry, Token};

Expand Down
5 changes: 5 additions & 0 deletions src/sys/unix/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ use std::convert::TryInto;
use std::io;
use std::mem::{size_of, MaybeUninit};
use std::net::{self, SocketAddr};
#[cfg(not(target_os = "hermit"))]
use std::os::fd::{AsRawFd, FromRawFd};
// TODO: once <https://github.com/rust-lang/rust/issues/126198> is fixed this
// can use `std::os::fd` and be merged with the above.
#[cfg(target_os = "hermit")]
use std::os::hermit::io::{AsRawFd, FromRawFd};

use crate::sys::unix::net::{new_socket, socket_addr, to_socket_addr};

Expand Down
5 changes: 5 additions & 0 deletions src/sys/unix/udp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use std::io;
use std::mem;
use std::net::{self, SocketAddr};
#[cfg(not(target_os = "hermit"))]
use std::os::fd::{AsRawFd, FromRawFd};
// TODO: once <https://github.com/rust-lang/rust/issues/126198> is fixed this
// can use `std::os::fd` and be merged with the above.
#[cfg(target_os = "hermit")]
use std::os::hermit::io::{AsRawFd, FromRawFd};

use crate::sys::unix::net::{new_ip_socket, socket_addr};

Expand Down
5 changes: 5 additions & 0 deletions src/sys/unix/waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ pub use self::fdbased::Waker;
mod eventfd {
use std::fs::File;
use std::io::{self, Read, Write};
#[cfg(not(target_os = "hermit"))]
use std::os::fd::{AsRawFd, FromRawFd, RawFd};
// TODO: once <https://github.com/rust-lang/rust/issues/126198> is fixed this
// can use `std::os::fd` and be merged with the above.
#[cfg(target_os = "hermit")]
use std::os::hermit::io::{AsRawFd, FromRawFd, RawFd};

/// Waker backed by `eventfd`.
///
Expand Down

0 comments on commit 1b7bac9

Please sign in to comment.