Repository navigation
fs::openat2 is unavailable when building with --cfg=rustix_no_linux_raw (e.g., in AOSP) - #1713
Open
tylersaunders wants to merge 1 commit into
Open
tylersaunders wants to merge 1 commit into
tylersaunders wants to merge 1 commit into
Conversation
`rustix::fs::openat2` and its libc backend implementation were gated on `#[cfg(linux_raw_dep)]` in commit fda7cbe ("rustix: on Linux, support a build without linux-raw-sys (bytecodealliance#1478)") because `backend::fs::syscalls::openat2` imported `linux_raw_sys::general::open_how`. Meanwhile, the supporting `ResolveFlags` bitflags and `SYS_OPENAT2` constant in the libc backend remained gated on `#[cfg(linux_kernel)]`. Because `libc::open_how` is not defined for `target_os = "android"` and is marked `#[non_exhaustive]` on `target_os = "linux"`, define `#[repr(C)] struct open_how` locally in `backend::fs::syscalls::openat2` when `#[cfg(not(linux_raw_dep))]` and gate `openat2` on `#[cfg(linux_kernel)]`. This makes `rustix::fs::openat2` usable on Android and Linux when building with `--cfg=rustix_no_linux_raw`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello, while moving some cpp code over to rust inside of AOSP, I encounted openat2 not being useable on android linux due to some configuration, and a minor issue with the
open_howstruct not being available outside oflinux_raw_sysrustix::fs::openat2is currently gated on#[cfg(linux_raw_dep)]insrc/fs/mod.rs,src/backend/libc/fs/syscalls.rs, andtests/fs/main.rs, making it unavailable on Linux and Android when building with--cfg=rustix_no_linux_raw(such as in AOSP, which buildsrustixwith thelibcbackend and withoutlinux-raw-sys).Background Context
In #1478 (
fda7cbe6),--cfg=rustix_no_linux_rawwas introduced so projects like AOSP and Mesa3D can buildrustixon Linux and Android using thelibcbackend without depending onlinux-raw-sys.In that change,
openat2was switched from#[cfg(linux_kernel)]to#[cfg(linux_raw_dep)]in:src/fs/mod.rs(mod openat2;andpub use openat2::openat2;)src/backend/libc/fs/syscalls.rs(pub(crate) fn openat2)However, all other
openat2support in thelibcbackend is already independent oflinux-raw-sysand gated on#[cfg(linux_kernel)]:rustix::fs::ResolveFlagsinsrc/backend/libc/fs/types.rsis gated on#[cfg(linux_kernel)](and its rustdoc links to[openat2]: crate::fs::openat2, which is broken whennot(linux_raw_dep)).use crate::fs::ResolveFlagsandconst SYS_OPENAT2 = 437insrc/backend/libc/fs/syscalls.rsare already gated on#[cfg(linux_kernel)].The only dependency on
linux-raw-sysinsidesrc/backend/libc/fs/syscalls.rs::openat2isuse linux_raw_sys::general::open_how;for the 24-byte kernel ABI struct (struct open_how { flags: u64, mode: u64, resolve: u64 }). Note thatlibc::open_howcannot be used directly because it is not defined fortarget_os = "android"inlibcand is marked#[non_exhaustive]ontarget_os = "linux".Proposed Solution (see attached commit)
src/backend/libc/fs/syscalls.rs::openat2, define#[repr(C)] struct open_how { flags: u64, mode: u64, resolve: u64 }when#[cfg(not(linux_raw_dep))](retaininguse linux_raw_sys::general::open_how;when#[cfg(linux_raw_dep)]).cfggate onopenat2insrc/fs/mod.rs,src/backend/libc/fs/syscalls.rs, andtests/fs/main.rsfrom#[cfg(linux_raw_dep)]back to#[cfg(linux_kernel)].I've tested & verified the behavior of this patch in one of our cpp -> rust migrations inside of AOSP. Ideally I'd like to land this upstream rather than maintaining our own AOSP patch downstream.