Skip to content

Commit

Permalink
Merge branch 'main' into update-linux-raw
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode authored Sep 7, 2024
2 parents 7f97b69 + ba0947f commit 1c78434
Show file tree
Hide file tree
Showing 180 changed files with 4,265 additions and 1,934 deletions.
55 changes: 24 additions & 31 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ jobs:
os: ubuntu-latest
rust: 1.63

# TODO: Reenable this once we can remove the redundant `Vec` imports.
#env:
# # -D warnings is commented out in our install-rust action; re-add it here.
# RUSTFLAGS: -D warnings -D elided-lifetimes-in-paths --cfg criterion
env:
# -D warnings is commented out in our install-rust action; re-add it here.
RUSTFLAGS: -D warnings -D elided-lifetimes-in-paths --cfg criterion
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -135,10 +134,9 @@ jobs:
os: ubuntu-latest
rust: nightly

# TODO: Reenable this once we can remove the redundant `Vec` imports.
#env:
# # -D warnings is commented out in our install-rust action; re-add it here.
# RUSTFLAGS: -D warnings -D elided-lifetimes-in-paths
env:
# -D warnings is commented out in our install-rust action; re-add it here.
RUSTFLAGS: -D warnings -D elided-lifetimes-in-paths
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -208,33 +206,25 @@ jobs:
- run: rustup component add rust-src
- run: cargo check -Z build-std --target x86_64-unknown-openbsd --all-targets --features=all-apis
- run: cargo check -Z build-std --target mips64-openwrt-linux-musl --all-targets --features=all-apis
# Temporarily disable this because the target appears to have breakage on nightly.
# - run: cargo check -Z build-std --target x86_64-unknown-dragonfly --all-targets --features=all-apis
- run: cargo check -Z build-std --target x86_64-unknown-dragonfly --all-targets --features=all-apis
- run: cargo check -Z build-std --target sparc-unknown-linux-gnu --all-targets --features=all-apis
# Temporarily disable this because the target appears to have changed and needs
# fixes and we transitively dev-depend on what can be an older version of rustix.
#- run: cargo check -Z build-std --target armv7-unknown-freebsd --all-targets --features=all-apis
# Omit --all-targets on gnu_ilp32 because dev-dependency tempfile depends on an older rustix
- run: cargo check -Z build-std --target aarch64-unknown-linux-gnu_ilp32 --features=all-apis
- run: cargo check -Z build-std --target armv7-unknown-freebsd --all-targets --features=all-apis
- run: cargo check -Z build-std --target aarch64-unknown-linux-gnu_ilp32 --all-targets --features=all-apis
# Omit --all-targets on haiku because not all the tests build yet.
# Temporarily disable this because the target appears to have breakage on nightly.
#- run: cargo check -Z build-std --target x86_64-unknown-haiku --features=all-apis
- run: cargo check -Z build-std --target x86_64-unknown-haiku --features=all-apis
- run: cargo check -Z build-std --target x86_64-uwp-windows-msvc --all-targets --features=all-apis
# Temporarily disable riscv32imc-esp-espidf due to std using SOMAXCONN.
#- run: cargo check -Z build-std --target=riscv32imc-esp-espidf --features=all-apis
- run: cargo check -Z build-std --target=aarch64-unknown-nto-qnx710 --features=all-apis
- run: cargo check -Z build-std --target=x86_64-pc-nto-qnx710 --features=all-apis
# Temporarily disable --features=all-apis, which doesn't build yet.
# Temporarily disable this because the target appears to have breakage on nightly.
#- run: cargo check -Z build-std --target=armv6k-nintendo-3ds
- run: cargo check -Z build-std --target=armv6k-nintendo-3ds
# Temporarily disable armv7-sony-vita-newlibeabihf due to std using SOMAXCONN.
#- run: cargo check -Z build-std --target=armv7-sony-vita-newlibeabihf --features=all-apis
# `std` doesn't appear to build on AIX yet, so test in `no_std` mode.
- run: cargo check -Zbuild-std=core,alloc --target=powerpc64-ibm-aix --features=all-apis --no-default-features
# Disable MIPS entirely for now as it fails with errors like
# "Undefined temporary symbol $BB342_17".
#- run: cargo check -Z build-std --target=mipsel-unknown-linux-gnu --features=all-apis
#- run: cargo check -Z build-std --target=mips64el-unknown-linux-gnuabi64 --features=all-apis
- run: cargo check -Z build-std --target=mipsel-unknown-linux-gnu --features=all-apis
- run: cargo check -Z build-std --target=mips64el-unknown-linux-gnuabi64 --features=all-apis


test:
Expand All @@ -246,7 +236,7 @@ jobs:
RUSTFLAGS: --cfg rustix_use_experimental_features
strategy:
matrix:
build: [ubuntu, ubuntu-20.04, i686-linux, aarch64-linux, powerpc64le-linux, riscv64-linux, s390x-linux, arm-linux, ubuntu-stable, i686-linux-stable, aarch64-linux-stable, riscv64-linux-stable, s390x-linux-stable, powerpc64le-linux-stable, arm-linux-stable, ubuntu-1.63, i686-linux-1.63, aarch64-linux-1.63, riscv64-linux-1.63, s390x-linux-1.63, powerpc64le-linux-1.63, arm-linux-1.63, macos-latest, macos-11, windows, windows-2019, musl]
build: [ubuntu, ubuntu-20.04, i686-linux, aarch64-linux, powerpc64le-linux, riscv64-linux, s390x-linux, arm-linux, ubuntu-stable, i686-linux-stable, aarch64-linux-stable, riscv64-linux-stable, s390x-linux-stable, powerpc64le-linux-stable, arm-linux-stable, ubuntu-1.63, i686-linux-1.63, aarch64-linux-1.63, riscv64-linux-1.63, s390x-linux-1.63, powerpc64le-linux-1.63, arm-linux-1.63, macos-latest, macos-12, windows, windows-2019, musl]
include:
- build: ubuntu
os: ubuntu-latest
Expand Down Expand Up @@ -419,8 +409,8 @@ jobs:
- build: macos-latest
os: macos-latest
rust: stable
- build: macos-11
os: macos-11
- build: macos-12
os: macos-12
rust: stable
- build: windows
os: windows-latest
Expand Down Expand Up @@ -492,7 +482,9 @@ jobs:
patch -p1 < $GITHUB_WORKSPACE/ci/s390x-stat-have-nsec.patch
patch -p1 < $GITHUB_WORKSPACE/ci/aarch64-o-largefile.patch
patch -p1 < $GITHUB_WORKSPACE/ci/tcgets2-tcsets2.patch
patch -p1 < $GITHUB_WORKSPACE/ci/tiocgsid.patch
patch -p1 < $GITHUB_WORKSPACE/ci/more-sockopts.patch
patch -p1 < $GITHUB_WORKSPACE/ci/pidfd-open.patch
./configure --target-list=${{ matrix.qemu_target }} --prefix=${{ runner.tool_cache }}/qemu --disable-tools --disable-slirp --disable-fdt --disable-capstone --disable-docs
ninja -C build install
if: matrix.qemu != '' && matrix.os == 'ubuntu-latest'
Expand Down Expand Up @@ -566,8 +558,7 @@ jobs:
qemu_target: arm-linux-user
env:
# -D warnings is commented out in our install-rust action; re-add it here.
# TODO: Reenable this once we can remove the redundant `Vec` imports.
#RUSTFLAGS: -D warnings -D elided-lifetimes-in-paths
RUSTFLAGS: -D warnings -D elided-lifetimes-in-paths
QEMU_BUILD_VERSION: 8.1.2
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -629,7 +620,9 @@ jobs:
patch -p1 < $GITHUB_WORKSPACE/ci/s390x-stat-have-nsec.patch
patch -p1 < $GITHUB_WORKSPACE/ci/aarch64-o-largefile.patch
patch -p1 < $GITHUB_WORKSPACE/ci/tcgets2-tcsets2.patch
patch -p1 < $GITHUB_WORKSPACE/ci/tiocgsid.patch
patch -p1 < $GITHUB_WORKSPACE/ci/more-sockopts.patch
patch -p1 < $GITHUB_WORKSPACE/ci/pidfd-open.patch
./configure --target-list=${{ matrix.qemu_target }} --prefix=${{ runner.tool_cache }}/qemu --disable-tools --disable-slirp --disable-fdt --disable-capstone --disable-docs
ninja -C build install
if: matrix.qemu != '' && matrix.os == 'ubuntu-latest'
Expand Down Expand Up @@ -657,9 +650,7 @@ jobs:
qemu_target: ppc64le-linux-user
env:
# -D warnings is commented out in our install-rust action; re-add it here.
# TODO: Reenable this once we can remove the redundant `Vec` imports.
#RUSTFLAGS: --cfg rustix_use_experimental_asm -D warnings -D elided-lifetimes-in-paths
RUSTFLAGS: --cfg rustix_use_experimental_asm
RUSTFLAGS: --cfg rustix_use_experimental_asm -D warnings -D elided-lifetimes-in-paths
RUSTDOCFLAGS: --cfg rustix_use_experimental_asm
CARGO_TARGET_POWERPC64LE_UNKNOWN_LINUX_GNU_RUSTFLAGS: --cfg rustix_use_experimental_asm
QEMU_BUILD_VERSION: 8.1.2
Expand Down Expand Up @@ -723,7 +714,9 @@ jobs:
patch -p1 < $GITHUB_WORKSPACE/ci/s390x-stat-have-nsec.patch
patch -p1 < $GITHUB_WORKSPACE/ci/aarch64-o-largefile.patch
patch -p1 < $GITHUB_WORKSPACE/ci/tcgets2-tcsets2.patch
patch -p1 < $GITHUB_WORKSPACE/ci/tiocgsid.patch
patch -p1 < $GITHUB_WORKSPACE/ci/more-sockopts.patch
patch -p1 < $GITHUB_WORKSPACE/ci/pidfd-open.patch
./configure --target-list=${{ matrix.qemu_target }} --prefix=${{ runner.tool_cache }}/qemu --disable-tools --disable-slirp --disable-fdt --disable-capstone --disable-docs
ninja -C build install
if: matrix.qemu != '' && matrix.os == 'ubuntu-latest'
Expand Down
62 changes: 46 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustix"
version = "0.38.34"
version = "0.38.35"
authors = [
"Dan Gohman <[email protected]>",
"Jakub Konka <[email protected]>",
Expand All @@ -21,7 +21,7 @@ itoa = { version = "1.0.1", default-features = false, optional = true }

# Special dependencies used in rustc-dep-of-std mode.
core = { version = "1.0.0", optional = true, package = "rustc-std-workspace-core" }
alloc = { version = "1.0.0", optional = true, package = "rustc-std-workspace-alloc" }
rustc-std-workspace-alloc = { version = "1.0.0", optional = true } # not aliased here but in lib.rs casuse of name collision with the alloc feature
compiler_builtins = { version = '0.1.49', optional = true }

# The procfs feature needs once_cell.
Expand All @@ -36,24 +36,24 @@ once_cell = { version = "1.5.2", optional = true }
# libc backend can be selected via adding `--cfg=rustix_use_libc` to
# `RUSTFLAGS` or enabling the `use-libc` cargo feature.
[target.'cfg(all(not(rustix_use_libc), not(miri), target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))'.dependencies]
linux-raw-sys = { version = "0.6", default-features = false, features = ["general", "errno", "ioctl", "no_std", "elf"] }
linux-raw-sys = { version = "0.6.5", default-features = false, features = ["general", "errno", "ioctl", "no_std", "elf"] }
libc_errno = { package = "errno", version = "0.3.8", default-features = false, optional = true }
libc = { version = "0.2.153", default-features = false, optional = true }
libc = { version = "0.2.156", default-features = false, optional = true }

# Dependencies for platforms where only libc is supported:
#
# On all other Unix-family platforms, and under Miri, we always use the libc
# backend, so enable its dependencies unconditionally.
[target.'cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64")))))))'.dependencies]
libc_errno = { package = "errno", version = "0.3.8", default-features = false }
libc = { version = "0.2.153", default-features = false }
libc = { version = "0.2.156", default-features = false }

# Additional dependencies for Linux with the libc backend:
#
# Some syscalls do not have libc wrappers, such as in `io_uring`. For these,
# the libc backend uses the linux-raw-sys ABI and `libc::syscall`.
[target.'cfg(all(any(target_os = "android", target_os = "linux"), any(rustix_use_libc, miri, not(all(target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64")))))))'.dependencies]
linux-raw-sys = { version = "0.6", default-features = false, features = ["general", "ioctl", "no_std"] }
linux-raw-sys = { version = "0.6.5", default-features = false, features = ["general", "ioctl", "no_std"] }

# For the libc backend on Windows, use the Winsock API in windows-sys.
[target.'cfg(windows)'.dependencies.windows-sys]
Expand All @@ -74,7 +74,7 @@ default-features = false

[dev-dependencies]
tempfile = "3.5.0"
libc = "0.2.153"
libc = "0.2.156"
libc_errno = { package = "errno", version = "0.3.8", default-features = false }
serial_test = "2.0.0"
memoffset = "0.9.0"
Expand All @@ -84,9 +84,6 @@ static_assertions = "1.1.0"
[target.'cfg(all(criterion, not(any(target_os = "emscripten", target_os = "wasi"))))'.dev-dependencies]
criterion = "0.4"

[target.'cfg(windows)'.dev-dependencies]
ctor = "0.2.0"

# Add Criterion configuration, as described here:
# <https://bheisler.github.io/criterion.rs/book/getting_started.html#step-1---add-dependency-to-cargotoml>
[[bench]]
Expand All @@ -95,7 +92,6 @@ harness = false

[package.metadata.docs.rs]
features = ["all-apis"]
rustdoc-args = ["--cfg", "doc_cfg"]
targets = [
"x86_64-unknown-linux-gnu",
"i686-unknown-linux-gnu",
Expand Down Expand Up @@ -186,8 +182,8 @@ stdio = []
# Enable `rustix::system::*`.
system = ["linux-raw-sys/system"]

# Enable `rustix::runtime::*`. This API is undocumented and unstable and
# experimental and not intended for general-purpose use.
# Enable `rustix::runtime::*`. This API is undocumented and unstable and
# experimental and not intended for general-purpose use.
runtime = ["linux-raw-sys/prctl"]

# Enable all API features.
Expand Down Expand Up @@ -238,13 +234,47 @@ alloc = []
# This is used in the port of std to rustix. This is experimental and not meant
# for regular use.
rustc-dep-of-std = [
"dep:core",
"dep:alloc",
"dep:compiler_builtins",
"core",
"rustc-std-workspace-alloc",
"compiler_builtins",
"linux-raw-sys/rustc-dep-of-std",
"bitflags/rustc-dep-of-std",
"compiler_builtins?/rustc-dep-of-std",
]

# Obsolete and deprecated.
cc = []

# Enable `rustix::io::try_close`. The rustix developers do not intend the
# existence of this feature to imply that anyone should use it.
try_close = []

[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = [
'cfg(alloc_c_string)',
'cfg(alloc_ffi)',
'cfg(apple)',
'cfg(asm_experimental_arch)',
'cfg(bsd)',
'cfg(core_c_str)',
'cfg(core_ffi_c)',
'cfg(core_intrinsics)',
'cfg(criterion)',
'cfg(document_experimental_runtime_api)',
'cfg(fix_y2038)',
'cfg(freebsdlike)',
'cfg(libc)',
'cfg(linux_kernel)',
'cfg(linux_like)',
'cfg(linux_raw)',
'cfg(netbsdlike)',
'cfg(rustc_attrs)',
'cfg(solarish)',
'cfg(staged_api)',
'cfg(static_assertions)',
'cfg(thumb_mode)',
'cfg(wasi)',
'cfg(wasi_ext)',
'cfg(target_arch, values("xtensa"))',
]
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
</div>

`rustix` provides efficient memory-safe and [I/O-safe] wrappers to POSIX-like,
Unix-like, Linux, and Winsock syscall-like APIs, with configurable backends.
It uses Rust references, slices, and return values instead of raw pointers, and
Unix-like, Linux, and Winsock syscall-like APIs, with configurable backends. It
uses Rust references, slices, and return values instead of raw pointers, and
[I/O safety types] instead of raw file descriptors, providing memory safety,
[I/O safety], and [provenance]. It uses `Result`s for reporting errors,
[`bitflags`] instead of bare integer flags, an [`Arg`] trait with optimizations
Expand Down Expand Up @@ -46,14 +46,14 @@ more portable APIs built on this functionality, see the [`cap-std`], [`memfd`],
Windows, and is portable to many OS's.

The linux_raw backend is enabled by default on platforms which support it. To
enable the libc backend instead, either enable the "use-libc" cargo feature,
or set the `RUSTFLAGS` environment variable to `--cfg=rustix_use_libc` when
enable the libc backend instead, either enable the "use-libc" cargo feature, or
set the `RUSTFLAGS` environment variable to `--cfg=rustix_use_libc` when
building.

## Cargo features

The modules [`rustix::io`], [`rustix::fd`], and [`rustix::ffi`] are enabled
by default. The rest of the API is conditional with cargo feature flags:
The modules [`rustix::io`], [`rustix::fd`], and [`rustix::ffi`] are enabled by
default. The rest of the API is conditional with cargo feature flags:

| Name | Description |
| ---------- | -------------------------------------------------------------- |
Expand Down
7 changes: 5 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fn main() {
// Gather target information.
let arch = var("CARGO_CFG_TARGET_ARCH").unwrap();
let env = var("CARGO_CFG_TARGET_ENV").unwrap();
let abi = var("CARGO_CFG_TARGET_ABI");
let inline_asm_name = format!("{}/{}.rs", ASM_PATH, arch);
let inline_asm_name_present = std::fs::metadata(inline_asm_name).is_ok();
let os = var("CARGO_CFG_TARGET_OS").unwrap();
Expand Down Expand Up @@ -148,13 +149,15 @@ fn main() {
|| arch == "mips"
|| arch == "sparc"
|| arch == "x86"
|| (arch == "wasm32" && os == "emscripten"))
|| (arch == "wasm32" && os == "emscripten")
|| (arch == "aarch64" && os == "linux" && abi == Ok("ilp32".to_string())))
&& (apple
|| os == "android"
|| os == "emscripten"
|| os == "haiku"
|| env == "gnu"
|| (env == "musl" && arch == "x86"))
|| (env == "musl" && arch == "x86")
|| (arch == "aarch64" && os == "linux" && abi == Ok("ilp32".to_string())))
{
use_feature("fix_y2038");
}
Expand Down
13 changes: 13 additions & 0 deletions ci/more-sockopts.patch
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ diff -ur -x roms -x build a/linux-user/generic/sockbits.h b/linux-user/generic/s
+#define TARGET_SO_COOKIE 57
+#endif
#endif
diff -ur -x roms -x build a/linux-user/mips/sockbits.h b/linux-user/mips/sockbits.h
--- a/linux-user/mips/sockbits.h
+++ b/linux-user/mips/sockbits.h
@@ -73,6 +73,9 @@
#define TARGET_SO_RCVBUFFORCE 33
#define TARGET_SO_PASSSEC 34

+#define TARGET_SO_INCOMING_CPU 49
+#define TARGET_SO_COOKIE 57
+
/** sock_type - Socket types
*
* Please notice that for binary compat reasons MIPS has to
diff -ur -x roms -x build a/linux-user/syscall.c b/linux-user/syscall.c
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
Expand Down
19 changes: 19 additions & 0 deletions ci/pidfd-open.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
From Dan Gohman <[email protected]>
Subject: [PATCH] Fix the flags argument of `pidfd_open`.

This corrects the flags value of `pidfd_open` to avoid passing
target flags to the host. Currently the only flag is `PIDFD_NONBLOCK`
so we use the `fcntl_flags_tbl` to translate it.

--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -9477,7 +9477,8 @@
#endif
#if defined(__NR_pidfd_open) && defined(TARGET_NR_pidfd_open)
case TARGET_NR_pidfd_open:
- return get_errno(pidfd_open(arg1, arg2));
+ return get_errno(pidfd_open(arg1,
+ target_to_host_bitmask(arg2, fcntl_flags_tbl)));
#endif
#if defined(__NR_pidfd_send_signal) && defined(TARGET_NR_pidfd_send_signal)
case TARGET_NR_pidfd_send_signal:
Loading

0 comments on commit 1c78434

Please sign in to comment.