Skip to content

Commit 26ece58

Browse files
authored
Fix no_std compilation on AIX. (#841)
`std` doesn't appear to build on AIX currently, but `-Z build-std=core,alloc` does, so add that as a CI check, and fix the errors it turns up. AIX has `stat64xat` and others which we could use, but they're not in the upstream `libc` crate bindings yet, so disable `statat` on AIX for now.
1 parent 5d6b687 commit 26ece58

File tree

10 files changed

+21
-10
lines changed

10 files changed

+21
-10
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,14 @@ jobs:
213213
- run: cargo check -Z build-std --target=riscv32imc-esp-espidf --features=all-apis
214214
- run: cargo check -Z build-std --target=aarch64-unknown-nto-qnx710 --features=all-apis
215215
- run: cargo check -Z build-std --target=x86_64-pc-nto-qnx710 --features=all-apis
216+
# `std` doesn't appear to build on AIX yet, so test in `no_std` mode.
217+
- run: cargo check -Zbuild-std=core,alloc --target=powerpc64-ibm-aix --features=all-apis --no-default-features
216218
# Disable MIPS entirely for now as it fails with errors like
217219
# "Undefined temporary symbol $BB342_17".
218220
#- run: cargo check -Z build-std --target=mipsel-unknown-linux-gnu --features=all-apis
219221
#- run: cargo check -Z build-std --target=mips64el-unknown-linux-gnuabi64 --features=all-apis
220222

223+
221224
test:
222225
name: Test
223226
runs-on: ${{ matrix.os }}

src/backend/libc/c.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,15 @@ pub(super) use libc::open64 as open;
113113
pub(super) use libc::posix_fallocate64 as posix_fallocate;
114114
#[cfg(any(all(linux_like, not(target_os = "android")), target_os = "aix"))]
115115
pub(super) use libc::{blkcnt64_t as blkcnt_t, rlim64_t as rlim_t};
116+
// TODO: AIX has `stat64x`, `fstat64x`, `lstat64x`, and `stat64xat`; add them
117+
// to the upstream libc crate and implement rustix's `statat` etc. with them.
116118
#[cfg(target_os = "aix")]
117119
pub(super) use libc::{
118120
blksize64_t as blksize_t, fstat64 as fstat, fstatfs64 as fstatfs, fstatvfs64 as fstatvfs,
119121
ftruncate64 as ftruncate, getrlimit64 as getrlimit, ino_t, lseek64 as lseek, mmap,
120122
off64_t as off_t, openat, posix_fadvise64 as posix_fadvise, preadv, pwritev,
121-
rlimit64 as rlimit, setrlimit64 as setrlimit, stat64at as fstatat, statfs64 as statfs,
122-
statvfs64 as statvfs, RLIM_INFINITY,
123+
rlimit64 as rlimit, setrlimit64 as setrlimit, statfs64 as statfs, statvfs64 as statvfs,
124+
RLIM_INFINITY,
123125
};
124126
#[cfg(linux_like)]
125127
pub(super) use libc::{

src/backend/libc/fs/syscalls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> {
618618
}
619619
}
620620

621-
#[cfg(not(any(target_os = "espidf", target_os = "redox")))]
621+
#[cfg(not(any(target_os = "aix", target_os = "espidf", target_os = "redox")))]
622622
pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result<Stat> {
623623
// See the comments in `fstat` about using `crate::fs::statx` here.
624624
#[cfg(all(

src/backend/libc/fs/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ impl FileType {
523523
/// Construct a `FileType` from the `d_type` field of a `c::dirent`.
524524
#[cfg(not(any(
525525
solarish,
526+
target_os = "aix",
526527
target_os = "espidf",
527528
target_os = "haiku",
528529
target_os = "nto",

src/backend/libc/net/syscalls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ pub(crate) mod sockopt {
525525
apple,
526526
solarish,
527527
windows,
528+
target_os = "aix",
528529
target_os = "dragonfly",
529530
target_os = "emscripten",
530531
target_os = "espidf",

src/clockid.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ use crate::fd::BorrowedFd;
1111
/// [`clock_gettime`]: crate::time::clock_gettime
1212
#[cfg(not(any(apple, target_os = "wasi")))]
1313
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
14-
#[cfg_attr(not(any(target_os = "aix", target_os = "dragonfly")), repr(i32))]
14+
#[cfg_attr(not(target_os = "dragonfly"), repr(i32))]
1515
#[cfg_attr(target_os = "dragonfly", repr(u64))]
16-
#[cfg_attr(target_os = "aix", repr(i64))]
1716
#[non_exhaustive]
1817
pub enum ClockId {
1918
/// `CLOCK_REALTIME`

src/fs/at.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use crate::fs::CloneFlags;
1212
use crate::fs::FileType;
1313
#[cfg(linux_kernel)]
1414
use crate::fs::RenameFlags;
15+
#[cfg(not(any(target_os = "aix", target_os = "espidf")))]
16+
use crate::fs::Stat;
1517
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))]
1618
use crate::fs::{Gid, Uid};
1719
use crate::fs::{Mode, OFlags};
@@ -26,7 +28,7 @@ use {
2628
};
2729
#[cfg(not(target_os = "espidf"))]
2830
use {
29-
crate::fs::{Access, AtFlags, Stat, Timestamps},
31+
crate::fs::{Access, AtFlags, Timestamps},
3032
crate::timespec::Nsecs,
3133
};
3234

@@ -288,7 +290,8 @@ pub fn symlinkat<P: path::Arg, Q: path::Arg, Fd: AsFd>(
288290
/// [Linux]: https://man7.org/linux/man-pages/man2/fstatat.2.html
289291
/// [`Mode::from_raw_mode`]: crate::fs::Mode::from_raw_mode
290292
/// [`FileType::from_raw_mode`]: crate::fs::FileType::from_raw_mode
291-
#[cfg(not(target_os = "espidf"))]
293+
// TODO: Add `stat64xat` to upstream libc bindings and reenable this for AIX.
294+
#[cfg(not(any(target_os = "aix", target_os = "espidf")))]
292295
#[inline]
293296
#[doc(alias = "fstatat")]
294297
pub fn statat<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, flags: AtFlags) -> io::Result<Stat> {

src/ioctl/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,9 @@ type _RawOpcode = c::c_int;
318318
#[cfg(any(apple, bsd, target_os = "redox", target_os = "haiku"))]
319319
type _RawOpcode = c::c_ulong;
320320

321-
// Solaris, Fuchsia, Emscripten and WASI use an int
321+
// AIX, Solaris, Fuchsia, Emscripten and WASI use an int
322322
#[cfg(any(
323+
target_os = "aix",
323324
target_os = "solaris",
324325
target_os = "illumos",
325326
target_os = "fuchsia",

src/net/sockopt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
apple,
1111
solarish,
1212
windows,
13+
target_os = "aix",
1314
target_os = "dragonfly",
1415
target_os = "emscripten",
1516
target_os = "espidf",

src/process/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod chroot;
77
mod exit;
88
#[cfg(not(target_os = "wasi"))] // WASI doesn't have get[gpu]id.
99
mod id;
10-
#[cfg(not(target_os = "espidf"))]
10+
#[cfg(not(any(target_os = "aix", target_os = "espidf")))]
1111
mod ioctl;
1212
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))]
1313
mod kill;
@@ -45,7 +45,7 @@ pub use chroot::*;
4545
pub use exit::*;
4646
#[cfg(not(target_os = "wasi"))]
4747
pub use id::*;
48-
#[cfg(not(target_os = "espidf"))]
48+
#[cfg(not(any(target_os = "aix", target_os = "espidf")))]
4949
pub use ioctl::*;
5050
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))]
5151
pub use kill::*;

0 commit comments

Comments
 (0)