Skip to content

Commit 3ec91c2

Browse files
gurchetansinghgsingh408
authored andcommitted
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: #1095 #1478 rust-vsock/vsock-rs#60 Android app developers seem to want to use linux-raw-sys though: #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 and arguably the favorite among Linux-distro maintainers. Right now, meson currently does not use Cargo.toml as a source of truth for dependency, since a dependency's build.rs file can basically do anything, and there's no way for an external build system to determine a build.rs file is doing [1]. As such, the standard way to include dependencies is are meson subprojects, for each dependency. There are various proposals to improve the situation [2], but those would require a bleeding edge meson not in CI/CD bots yet. That said, there's an easy way to test from the root of the directory: sudo apt install meson ninja-build meson setup rustix-build ninja -C rustix-build Meson closely mirrors what Android does. By adding it here, we ensure the continue use of Rustix in core Android platform code. [1] mesonbuild/meson#2173 [2] mesonbuild/meson#15223
1 parent d6a5893 commit 3ec91c2

File tree

8 files changed

+227
-0
lines changed

8 files changed

+227
-0
lines changed

.github/workflows/main.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,3 +887,75 @@ jobs:
887887
cargo test --verbose --features=all-apis --release --workspace -- --nocapture
888888
env:
889889
RUST_BACKTRACE: full
890+
891+
meson-musl:
892+
name: Meson Musl
893+
runs-on: ubuntu-latest
894+
steps:
895+
- uses: actions/checkout@v4
896+
with:
897+
submodules: true
898+
- uses: ./.github/actions/install-rust
899+
with:
900+
toolchain: stable
901+
- name: Install target
902+
run: rustup target add x86_64-unknown-linux-musl
903+
- name: Install Meson and Ninja
904+
run: sudo apt-get update && sudo apt-get install -y meson ninja-build musl-tools
905+
- name: Create cross file
906+
run: |
907+
cat <<EOF > cross_file_musl_ci.txt
908+
[binaries]
909+
c = 'gcc'
910+
rust = ['rustc', '--target', 'x86_64-unknown-linux-musl']
911+
912+
[host_machine]
913+
system = 'linux'
914+
cpu_family = 'x86_64'
915+
cpu = 'x86_64'
916+
endian = 'little'
917+
EOF
918+
- name: Meson setup
919+
run: meson setup build-musl --cross-file cross_file_musl_ci.txt
920+
- name: Meson compile
921+
run: meson compile -C build-musl
922+
923+
meson-android:
924+
name: Meson Android
925+
runs-on: ubuntu-latest
926+
steps:
927+
- uses: actions/checkout@v4
928+
with:
929+
submodules: true
930+
- uses: ./.github/actions/install-rust
931+
with:
932+
toolchain: stable
933+
- name: Install target
934+
run: rustup target add x86_64-linux-android
935+
- name: Install Meson and Ninja
936+
run: sudo apt-get update && sudo apt-get install -y meson ninja-build
937+
- name: Setup NDK
938+
uses: nttld/setup-ndk@v1
939+
id: setup-ndk
940+
with:
941+
ndk-version: r27b
942+
- name: Create cross file
943+
run: |
944+
cat <<EOF > cross_file_android_ci.txt
945+
[binaries]
946+
c = '${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android30-clang'
947+
cpp = '${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android30-clang++'
948+
ar = '${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar'
949+
strip = '${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip'
950+
rust = ['rustc', '--target', 'x86_64-linux-android']
951+
952+
[host_machine]
953+
system = 'android'
954+
cpu_family = 'x86_64'
955+
cpu = 'x86_64'
956+
endian = 'little'
957+
EOF
958+
- name: Meson setup
959+
run: meson setup build-android --cross-file cross_file_android_ci.txt
960+
- name: Meson compile
961+
run: meson compile -C build-android

meson.build

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright © 2026 Google
2+
# SPDX-License-Identifier: MIT
3+
4+
project(
5+
'rustix',
6+
'rust',
7+
version : '1.1.4',
8+
license : 'Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT',
9+
)
10+
11+
dep_errno = dependency('errno-0.3-rs', fallback: ['errno-0.3-rs', 'dep_errno'])
12+
dep_libc = dependency('libc-0.2-rs', fallback: ['libc-0.2-rs', 'dep_libc'])
13+
dep_bitflags = dependency('bitflags-2-rs', fallback: ['bitflags-2-rs', 'dep_bitflags'])
14+
15+
rustix_args = [
16+
'--cfg', 'libc',
17+
'--cfg', 'feature="use-libc"',
18+
]
19+
20+
os_deps = []
21+
if host_machine.system() == 'linux' or host_machine.system() == 'android'
22+
rustix_args += [
23+
'--cfg', 'linux_like',
24+
'--cfg', 'linux_kernel',
25+
'--cfg', 'feature="std"',
26+
'--cfg', 'feature="alloc"',
27+
'--cfg', 'feature="event"',
28+
'--cfg', 'feature="fs"',
29+
'--cfg', 'feature="mm"',
30+
'--cfg', 'feature="net"',
31+
'--cfg', 'feature="param"',
32+
'--cfg', 'feature="pipe"',
33+
'--cfg', 'feature="thread"',
34+
]
35+
elif host_machine.system() == 'windows'
36+
os_deps += [dependency('windows-sys-0.6-rs', fallback: ['windows-sys-0.6-rs', 'dep_windows_sys'])]
37+
endif
38+
39+
lib = static_library(
40+
'rustix',
41+
'src/lib.rs',
42+
override_options : ['rust_std=2021', 'build.rust_std=2021'],
43+
dependencies : [dep_errno, dep_libc, dep_bitflags] + os_deps,
44+
rust_abi : 'rust',
45+
rust_args: rustix_args,
46+
)

subprojects/bitflags-2-rs.wrap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[wrap-file]
2+
directory = bitflags-2.9.1
3+
source_url = https://crates.io/api/v1/crates/bitflags/2.9.1/download
4+
source_filename = bitflags-2.9.1.tar.gz
5+
source_hash = 1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967
6+
patch_directory = bitflags-2-rs

subprojects/errno-0.3-rs.wrap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[wrap-file]
2+
directory = errno-0.3.12
3+
source_url = https://crates.io/api/v1/crates/errno/0.3.12/download
4+
source_filename = errno-0.3.12.tar.gz
5+
source_hash = cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18
6+
patch_directory = errno-0.3-rs

subprojects/libc-0.2-rs.wrap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[wrap-file]
2+
directory = libc-0.2.177
3+
source_url = https://crates.io/api/v1/crates/libc/0.2.177/download
4+
source_filename = libc-0.2.177.tar.gz
5+
source_hash = 2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976
6+
patch_directory = libc-0.2-rs
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright © 2026 Google
2+
# SPDX-License-Identifier: MIT
3+
4+
project(
5+
'bitflags',
6+
'rust',
7+
version : '2.9.1',
8+
license : 'MIT OR Apache-2.0',
9+
meson_version : '>= 1.3.0',
10+
)
11+
12+
lib = static_library(
13+
'bitflags',
14+
'src/lib.rs',
15+
override_options : ['rust_std=2021', 'build.rust_std=2021', 'warning_level=0'],
16+
rust_abi : 'rust',
17+
)
18+
19+
dep_bitflags = declare_dependency(
20+
link_with : [lib]
21+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright © 2026 Google
2+
# SPDX-License-Identifier: MIT
3+
4+
project(
5+
'errno',
6+
'rust',
7+
version : '0.3.12',
8+
license : 'MIT OR Apache-2.0',
9+
meson_version : '>= 1.3.0',
10+
)
11+
12+
os_deps = []
13+
libc = subproject('libc-0.2-rs').get_variable('lib')
14+
if host_machine.system() == 'windows'
15+
os_deps += subproject('windows-sys-0.6-rs').get_variable('lib')
16+
endif
17+
18+
lib = static_library(
19+
'libc_errno',
20+
'src/lib.rs',
21+
override_options : ['rust_std=2018', 'build.rust_std=2018', 'warning_level=0'],
22+
link_with: [libc] + os_deps,
23+
rust_abi : 'rust',
24+
)
25+
26+
dep_errno = declare_dependency(
27+
link_with : [lib]
28+
)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright © 2026 Google
2+
# SPDX-License-Identifier: MIT
3+
4+
project(
5+
'libc',
6+
'rust',
7+
version : '0.2.177',
8+
license : 'MIT OR Apache-2.0',
9+
meson_version : '>= 1.3.0',
10+
)
11+
12+
libc_args = [
13+
'--cfg', 'feature="default"',
14+
'--cfg', 'feature="extra_traits"',
15+
'--cfg', 'feature="std"',
16+
'--cfg', 'freebsd11',
17+
'--cfg', 'libc_align',
18+
'--cfg', 'libc_cfg_target_vendor',
19+
'--cfg', 'libc_const_extern_fn',
20+
'--cfg', 'libc_const_size_of',
21+
'--cfg', 'libc_core_cvoid',
22+
'--cfg', 'libc_int128',
23+
'--cfg', 'libc_long_array',
24+
'--cfg', 'libc_non_exhaustive',
25+
'--cfg', 'libc_packedN',
26+
'--cfg', 'libc_priv_mod_use',
27+
'--cfg', 'libc_ptr_addr_of',
28+
'--cfg', 'libc_underscore_const_names',
29+
'--cfg', 'libc_union',
30+
]
31+
32+
lib = static_library(
33+
'libc',
34+
'src/lib.rs',
35+
rust_abi : 'rust',
36+
override_options : ['rust_std=2021', 'build.rust_std=2021', 'warning_level=0'],
37+
rust_args: libc_args,
38+
)
39+
40+
dep_libc = declare_dependency(
41+
link_with : [lib]
42+
)

0 commit comments

Comments
 (0)