Skip to content

Commit

Permalink
fix musl build
Browse files Browse the repository at this point in the history
  • Loading branch information
warthog618 committed May 18, 2024
1 parent 3b328d9 commit b190b94
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
9 changes: 9 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ runner = 'sudo -E'

[target.aarch64-unknown-linux-gnu]
runner = 'sudo -E'

[target.x86_64-unknown-linux-musl]
runner = 'sudo -E'

[target.aarch64-unknown-linux-musl]
runner = 'sudo -E'

[target.arm-unknown-linux-musl]
runner = 'sudo -E'
1 change: 1 addition & 0 deletions uapi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- add methods to add attributes to v2::LineConfig.
- fix musl build errors and warnings

<a name="v0.6.1"></a>

Expand Down
28 changes: 20 additions & 8 deletions uapi/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

use libc::{c_long, pollfd, time_t, timespec, POLLIN};
use std::ffi::OsStr;
use std::fs::File;
use std::os::unix::prelude::{AsRawFd, OsStrExt};
Expand All @@ -19,15 +18,21 @@ pub fn has_event(f: &File) -> Result<bool> {
wait_event(f, Duration::ZERO)
}

// workaround musl libc::ioctl() having a different signature
#[cfg(target_env = "musl")]
pub(crate) type IoctlRequestType = ::libc::c_int;
#[cfg(not(target_env = "musl"))]
pub(crate) type IoctlRequestType = ::libc::c_ulong;

macro_rules! ior {
($nr:expr, $dty:ty) => {
ioctl_sys::ior!(IOCTL_MAGIC, $nr, std::mem::size_of::<$dty>()) as ::std::os::raw::c_ulong
ioctl_sys::ior!(IOCTL_MAGIC, $nr, std::mem::size_of::<$dty>()) as IoctlRequestType
};
}

macro_rules! iorw {
($nr:expr, $dty:ty) => {
ioctl_sys::iorw!(IOCTL_MAGIC, $nr, std::mem::size_of::<$dty>()) as ::std::os::raw::c_ulong
ioctl_sys::iorw!(IOCTL_MAGIC, $nr, std::mem::size_of::<$dty>()) as IoctlRequestType
};
}
pub(crate) use iorw;
Expand Down Expand Up @@ -59,14 +64,21 @@ pub fn read_event(f: &File, buf: &mut [u64]) -> Result<usize> {

/// Wait for the file to have an event available to read.
pub fn wait_event(f: &File, d: Duration) -> Result<bool> {
let mut pfd = pollfd {
let mut pfd = libc::pollfd {
fd: f.as_raw_fd(),
events: POLLIN,
events: libc::POLLIN,
revents: 0,
};
let timeout = timespec {
tv_sec: d.as_secs() as time_t,
tv_nsec: d.subsec_nanos() as c_long,
// prevent musl builds complaining about use of deprecated time_t
#[cfg(not(target_env = "musl"))]
use libc::time_t as TimeT;
#[cfg(all(target_env = "musl", target_pointer_width = "32"))]
use std::primitive::i32 as TimeT;
#[cfg(all(target_env = "musl", target_pointer_width = "64"))]
use std::primitive::i64 as TimeT;
let timeout = libc::timespec {
tv_sec: d.as_secs() as TimeT,
tv_nsec: d.subsec_nanos() as libc::c_long,
};
unsafe {
match libc::ppoll(
Expand Down

0 comments on commit b190b94

Please sign in to comment.