Skip to content

Rustix for android, part deux - #1577

Open
gurchetansingh wants to merge 4 commits into
bytecodealliance:mainfrom
gurchetansingh:rustix-for-android-part-deux
Open

gurchetansingh wants to merge 4 commits into
bytecodealliance:mainfrom
gurchetansingh:rustix-for-android-part-deux

Conversation

@gurchetansingh

Copy link
Copy Markdown
Contributor
rustix: add Meson build to CI to guard Android use cases

Rustix has gone back-and-forth on it's policy on Android.
Android platform developers don't want a dependency on
linux-raw-sys.  This is documented here:

  https://github.com/bytecodealliance/rustix/issues/1095
  https://github.com/bytecodealliance/rustix/pull/1478
  https://github.com/rust-vsock/vsock-rs/pull/60

Android app developers seem to want to use linux-raw-sys though:

https://github.com/bytecodealliance/rustix/pull/1528

The Android platform developers don't REALLY care about
the cargo build though.

CI/CD testing on the particular build options Android likes
is useful.

This MR adds another non-cargo build system (Meson) to the
CI/CD, that mirrors the options Android likes.

Meson is renowned for being a easy-to-maintain build system.

By adding it here, we ensure the continue use of Rustix in
core Android platform code.

@gurchetansingh
gurchetansingh force-pushed the rustix-for-android-part-deux branch from e97ec4e to f5b00ae Compare February 2, 2026 22:28
@gurchetansingh gurchetansingh changed the title [WIP] Rustix for android part deux [WIP] Rustix for android, part deux Feb 3, 2026
@gurchetansingh

Copy link
Copy Markdown
Contributor Author

CC: @sunfishcode @qwandor @HemantKArya

@gurchetansingh

Copy link
Copy Markdown
Contributor Author

Also, getting a new release for this would be most terrific for downstream integrators.

Comment thread src/ioctl/mod.rs

/// Convenience macro for Rustix's ioctl read
#[macro_export]
macro_rules! ioctl_readwrite {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seem like weird inclusions for the public API.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so nix has them too:

https://github.com/nix-rust/nix/blob/master/src/sys/ioctl/mod.rs#L652

I know of two places that are duplicating this logic:

https://github.com/Smithay/drm-rs/blob/develop/drm-ffi/src/ioctl.rs#L6
https://github.com/magma-gpu/rutabaga_gfx/blob/main/third_party/mesa3d/src/magma/sys/linux/amdgpu.rs#L43 (the project I work on)

Anything particularly wrong with these APIs? Otherwise, people have to excessively define things like ioctl::Updater and ioctl::opcode::read_write.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@notgull Do you have any further thoughts here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you write down what these new macros do that can't be done with rustix's existing ioctl API?

gurchetansingh pushed a commit to magma-gpu/rutabaga_gfx that referenced this pull request Feb 18, 2026
We would like to land:

#36

But that'll break Android until the following rustix change lands:

bytecodealliance/rustix#1577

and it can take a few months to get something through rustix due
to limited maintainer bandwidth.

Stopgap solution: cut releases and branches for libkrun until
Rustix change is merged.  Unlike the "chromeos" branch, the libkrun
branch will eventually be merged with main.
gurchetansingh pushed a commit to magma-gpu/rutabaga_gfx that referenced this pull request Feb 19, 2026
We would like to land:

#36

But that'll break Android until the following rustix change lands:

bytecodealliance/rustix#1577

and it can take a few months to get something through rustix due
to limited maintainer bandwidth.

Stopgap solution: cut releases and branches for libkrun until
Rustix change is merged.  Unlike the "chromeos" branch, the libkrun
branch will eventually be merged with main.
@gurchetansingh

Copy link
Copy Markdown
Contributor Author

gentle ping. Perhaps added more reviewers/maintainers could help with the backlog?

@sunfishcode sunfishcode left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your help!

Comment thread src/backend/libc/fs/syscalls.rs Resolved
Comment thread src/fs/statx.rs Resolved
Comment thread src/ioctl/mod.rs

/// Convenience macro for Rustix's ioctl read
#[macro_export]
macro_rules! ioctl_readwrite {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@notgull Do you have any further thoughts here?

@gurchetansingh

Copy link
Copy Markdown
Contributor Author

@sunfishcode ping

@gurchetansingh
gurchetansingh force-pushed the rustix-for-android-part-deux branch from 3ec91c2 to 31c894e Compare April 24, 2026 14:07
@gurchetansingh

Copy link
Copy Markdown
Contributor Author

CI/CD failures look related to #1606, it passed last time I tried.

gurchetansingh added a commit to gurchetansingh/rutabaga_gfx that referenced this pull request May 1, 2026
This contains downstream patches for Rustix, from:

bytecodealliance/rustix#1577

I think the people are cool with the changes generally,
but we're essentially running into https://xkcd.com/2347/
right now.

The cost of local patches in Rustix now is lower than
forking mesa3d_util and friends indefinitely.
@gurchetansingh
gurchetansingh force-pushed the rustix-for-android-part-deux branch from 31c894e to 5fa428d Compare May 1, 2026 22:52
gurchetansingh added a commit to magma-gpu/rutabaga_gfx that referenced this pull request May 4, 2026
This contains downstream patches for Rustix, from:

bytecodealliance/rustix#1577

I think the people are cool with the changes generally,
but we're essentially running into https://xkcd.com/2347/
right now.

The cost of local patches in Rustix now is lower than
forking mesa3d_util and friends indefinitely.
temeraire-cx pushed a commit to chaotic-cx/mesa-mirror that referenced this pull request May 5, 2026
This contains downstream patches for Rustix, from:

 bytecodealliance/rustix#1577

I think the people are cool with the changes generally,
but we're essentially running into https://xkcd.com/2347/
right now and the maintainer doesn't have time to even
look at it.

To ease in the development of mesa3d_util, it's better
to keep 3 downstream patches here, than potentially
diverging mesa3d_util for actual consumers.

Reviewed-by: LingMan
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41321>
joshuaswarren pushed a commit to joshuaswarren/mesa-1 that referenced this pull request Sep 21, 2026
This contains downstream patches for Rustix, from:

 bytecodealliance/rustix#1577

I think the people are cool with the changes generally,
but we're essentially running into https://xkcd.com/2347/
right now and the maintainer doesn't have time to even
look at it.

To ease in the development of mesa3d_util, it's better
to keep 3 downstream patches here, than potentially
diverging mesa3d_util for actual consumers.

Reviewed-by: LingMan
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41321>
@xtqqczze

This comment was marked as resolved.

@gurchetansingh
gurchetansingh force-pushed the rustix-for-android-part-deux branch from 5fa428d to d37956f Compare October 29, 2026 18:29
@gurchetansingh

Copy link
Copy Markdown
Contributor Author

@gurchetansingh needs a rebase for CI

@xtqqczze @sunfishcode

Rebased! Good to see the project is accepting patches again. PTAL!

@sunfishcode sunfishcode left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The meson build seems to require embedding a lot of version strings, hash codes, and build metadata in the rustix repository which will be a chore to maintain.

If the goal is to test rustix with the set of cfgs that Android developers would use, would that be possible to acheve using cargo? Even if cargo isn't how Android developers themselves would actually use it, could we test the needed cfgs that way?

Comment thread meson.build Resolved
Comment thread meson.build Resolved
Comment thread meson.build Resolved
Comment thread subprojects/libc-0.2-rs.wrap Resolved
Comment thread src/ioctl/mod.rs

/// Convenience macro for Rustix's ioctl read
#[macro_export]
macro_rules! ioctl_readwrite {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you write down what these new macros do that can't be done with rustix's existing ioctl API?

These ioctl wrappers are used by rustix users.  For example:

https://github.com/Smithay/drm-rs/blob/develop/drm-ffi/src/ioctl.rs#L6

Roughly, they match the ones provided by nix.  I'm upstreaming the
portion I have personally tested.
Android likes to build host tools (adb, Cuttlefish, ..)
via musl, using the same hermetic tree as for Bionic
build.

And linux-raw-sys isn't in that hermetic tree, so add support
for the libc-backend.
It's desirable to enable futex for some cases that will be
run on Android.  The strategy is just to define the constants
needed by the libc ourselves, if libc doesn't provide the
necessary constant.  Long-term, that could make the libc
backend only depend on libc.
Android platform developers (AOSP) and external build systems like Meson
build rustix with the libc backend and without linux-raw-sys
(--cfg=rustix_no_linux_raw):

  bytecodealliance#1095
  bytecodealliance#1478
  rust-vsock/vsock-rs#60

Meanwhile, Android app developers using Cargo may want linux-raw-sys
enabled by default:

  bytecodealliance#1528

Gate the linux-raw-sys target dependencies in Cargo.toml on
not(rustix_no_linux_raw), ensure --cfg=rustix_no_linux_raw implies the
libc backend in build.rs, and test both configurations (with and without
rustix_no_linux_raw) on Android and musl targets in CI.

To locally test the no-linux-raw-sys path on Android:

  rustup target add aarch64-linux-android
  RUSTFLAGS="--cfg rustix_no_linux_raw" cargo check \
    --target=aarch64-linux-android \
    -F use-libc,net,std,alloc,event,fs,mm,param,pipe,thread \
    -F use-libc-auxv,libc_errno \
    --all-targets

And to verify linux-raw-sys is excluded from the dependency graph:

  RUSTFLAGS="--cfg rustix_no_linux_raw" cargo tree --edges normal \
    --target=aarch64-linux-android \
    -F use-libc,net,std,alloc,event,fs,mm,param,pipe,thread \
    -F use-libc-auxv,libc_errno
@gurchetansingh
gurchetansingh force-pushed the rustix-for-android-part-deux branch from d37956f to 34e00d3 Compare November 13, 2026 22:26
@gurchetansingh

Copy link
Copy Markdown
Contributor Author

If the goal is to test rustix with the set of cfgs that Android developers would use, would that be possible to acheve using cargo? Even if cargo isn't how Android developers themselves would actually use it, could we test the needed cfgs that way?

It's important to make the distinction between:

  • Android platform developers -- i.e, the official Android Rust team
  • Android app developers

My original CL fixed the issue for Android platform developers:

#1478

But Android app developers undid that change:

#1528

I didn't think it was possible for cargo to test two Android configurations (one with linux-raw-sys and one without linux-raw-sys), so I added the meson build system. I had Gemini double check this, and it found a way to make tests both using cargo, and it seems to work. So removed meson.build in the latest MR version.

Could you write down what these new macros do that can't be done with rustix's existing ioctl API?

While they expand to rustix’s existing API, these macros solve three issues:

  1. Ergonomics: Eliminates repetitive const OPCODE declarations (required because Setter/Updater take OPCODE as a const generic) across dozens of driver ioctls.
  2. Ecosystem compatibility: Matches nix’s macro API; at least 3 Rustix-based projects already duplicate this exact wrapper.
  3. Type safety: Opcode is an untyped integer, forcing callers to specify T twice (opcode::read_write::<T> and Updater::<OPCODE, T>). Taking T once prevents UB from type/opcode mismatches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants