Stream: general

Topic: Rustix on android without linux-raw-sys


view this post on Zulip Marcin Radomski (Mar 15 2024 at 21:30):

Hello folks!

I'd like to make rustix build with for android with libc backend, but without any dependency on linux-raw-sys. Right now it seems linux-raw-sys is always a dependency on Linux, and there are quite a few cases where linux-raw-sys is used outside backend/linux-raw-sys - as long as it's under cfg(linux_kernel).

Where should I look to understand how to do this in a way that makes sense for rustix architecture, and also doesn't break stuff?

Would a patch like this be welcome upstream?

view this post on Zulip Dan Gohman (Mar 15 2024 at 21:32):

Rustix on Android uses rustix's libc backend, however it also uses linux-raw-sys in order to expose Linux-specific features that aren't available through the libc crate.

view this post on Zulip Dan Gohman (Mar 15 2024 at 21:35):

Is there a problem with linux-raw-sys on Android, or are you looking to ensure that everything goes through libc that can?

view this post on Zulip Marcin Radomski (Mar 15 2024 at 21:37):

I'm looking to use libc parts exclusively, even at the cost of losing some functionality that's not available via libc.

What I'm aiming for is to use it in AOSP (Android platform). The feedback I got from Android maintainers was to avoid the linux-raw-sys dependency because of the linux-raw-sys bindings being statically generated not specifically out of Android kernel. I'm trying to figure out if that could work and make sense.

view this post on Zulip Dan Gohman (Mar 15 2024 at 21:43):

There are several uses of linux_raw_sys in the src/backend/libc directory, but it's probably manageable.

view this post on Zulip Dan Gohman (Mar 15 2024 at 21:43):

Some of those might be able to be upstreamed to the libc crate.

view this post on Zulip Marcin Radomski (Mar 15 2024 at 21:50):

There's also a bunch outside src/backend. What would be the right approach for those, disabling by some kind of absolutely_no_linux_raw_sys_please-like cfg?

view this post on Zulip Dan Gohman (Mar 15 2024 at 21:54):

Ah, yes. Some of those should be able to be disabled in bulk, by disabling eg. the prctl module in the thread directory.

view this post on Zulip Marcin Radomski (Mar 15 2024 at 21:56):

OK, I'll go poke around a little. Thank you for the hints!

view this post on Zulip Dan Gohman (Mar 15 2024 at 21:56):

For the cfg, the best way might be to make the linux-raw-sys dependency optional

view this post on Zulip Dan Gohman (Mar 15 2024 at 21:56):

And then you can use cfg(feature = "linux-raw-sys")

view this post on Zulip Marcin Radomski (Mar 15 2024 at 21:57):

Does each optional dependency implicitly declare a feature with its name?

view this post on Zulip Dan Gohman (Mar 15 2024 at 21:57):

Yes

view this post on Zulip Marcin Radomski (Mar 15 2024 at 21:58):

That's awesome, TIL. Thank you :D

view this post on Zulip Dan Gohman (Mar 15 2024 at 22:03):

If you run into problems, let me know, and I'll see if I can help!


Last updated: Nov 22 2024 at 16:03 UTC