From 99a32b760708204484c151a77c7caba66846327e Mon Sep 17 00:00:00 2001 From: Al Hoang <13622+hoanga@users.noreply.github.com> Date: Sun, 1 Oct 2023 20:57:41 -0700 Subject: [PATCH] feat: Add support for Haiku OS Haiku does not support pipe_with at all, so just fall back to pipe(). --- .github/workflows/ci.yml | 3 +++ src/poll.rs | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index debef47..713f346 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,6 +68,9 @@ jobs: - name: Check selected Tier 3 targets if: startsWith(matrix.rust, 'nightly') && matrix.os == 'ubuntu-latest' run: cargo check -Z build-std --target=riscv32imc-esp-espidf + - name: Check haiku + if: startsWith(matrix.rust, 'nightly') && matrix.os == 'ubuntu-latest' + run: cargo check -Z build-std --target x86_64-unknown-haiku cross: runs-on: ${{ matrix.os }} diff --git a/src/poll.rs b/src/poll.rs index 3f94e70..950a8e6 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -447,7 +447,9 @@ mod notify { use rustix::fd::{AsFd, AsRawFd, BorrowedFd, OwnedFd, RawFd}; use rustix::fs::{fcntl_getfl, fcntl_setfl, OFlags}; use rustix::io::{fcntl_getfd, fcntl_setfd, read, write, FdFlags}; - use rustix::pipe::{pipe, pipe_with, PipeFlags}; + #[cfg(not(target_os = "haiku"))] + use rustix::pipe::pipe_with; + use rustix::pipe::{pipe, PipeFlags}; /// A notification pipe. /// @@ -468,12 +470,18 @@ mod notify { impl Notify { /// Creates a new notification pipe. pub(super) fn new() -> io::Result { - let (read_pipe, write_pipe) = pipe_with(PipeFlags::CLOEXEC).or_else(|_| { + let fallback_pipe = |_| { let (read_pipe, write_pipe) = pipe()?; fcntl_setfd(&read_pipe, fcntl_getfd(&read_pipe)? | FdFlags::CLOEXEC)?; fcntl_setfd(&write_pipe, fcntl_getfd(&write_pipe)? | FdFlags::CLOEXEC)?; io::Result::Ok((read_pipe, write_pipe)) - })?; + }; + + #[cfg(not(target_os = "haiku"))] + let (read_pipe, write_pipe) = pipe_with(PipeFlags::CLOEXEC).or_else(fallback_pipe)?; + + #[cfg(target_os = "haiku")] + let (read_pipe, write_pipe) = fallback_pipe(PipeFlags::CLOEXEC)?; // Put the reading side into non-blocking mode. fcntl_setfl(&read_pipe, fcntl_getfl(&read_pipe)? | OFlags::NONBLOCK)?;