Skip to content

Commit e97ec4e

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: bytecodealliance#1095 bytecodealliance#1478 rust-vsock/vsock-rs#60 Android app developers seem to want to use linux-raw-sys though: bytecodealliance#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.
1 parent e908b0f commit e97ec4e

File tree

8 files changed

+229
-0
lines changed

8 files changed

+229
-0
lines changed

.github/workflows/main.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,3 +865,75 @@ jobs:
865865
cargo test --verbose --features=all-apis --release --workspace -- --nocapture
866866
env:
867867
RUST_BACKTRACE: full
868+
869+
meson-musl:
870+
name: Meson Musl
871+
runs-on: ubuntu-latest
872+
steps:
873+
- uses: actions/checkout@v4
874+
with:
875+
submodules: true
876+
- uses: ./.github/actions/install-rust
877+
with:
878+
toolchain: stable
879+
- name: Install target
880+
run: rustup target add x86_64-unknown-linux-musl
881+
- name: Install Meson and Ninja
882+
run: sudo apt-get update && sudo apt-get install -y meson ninja-build musl-tools
883+
- name: Create cross file
884+
run: |
885+
cat <<EOF > cross_file_musl_ci.txt
886+
[binaries]
887+
c = 'gcc'
888+
rust = ['rustc', '--target', 'x86_64-unknown-linux-musl']
889+
890+
[host_machine]
891+
system = 'linux'
892+
cpu_family = 'x86_64'
893+
cpu = 'x86_64'
894+
endian = 'little'
895+
EOF
896+
- name: Meson setup
897+
run: meson setup build-musl --cross-file cross_file_musl_ci.txt
898+
- name: Meson compile
899+
run: meson compile -C build-musl
900+
901+
meson-android:
902+
name: Meson Android
903+
runs-on: ubuntu-latest
904+
steps:
905+
- uses: actions/checkout@v4
906+
with:
907+
submodules: true
908+
- uses: ./.github/actions/install-rust
909+
with:
910+
toolchain: stable
911+
- name: Install target
912+
run: rustup target add x86_64-linux-android
913+
- name: Install Meson and Ninja
914+
run: sudo apt-get update && sudo apt-get install -y meson ninja-build
915+
- name: Setup NDK
916+
uses: nttld/setup-ndk@v1
917+
id: setup-ndk
918+
with:
919+
ndk-version: r27b
920+
- name: Create cross file
921+
run: |
922+
cat <<EOF > cross_file_android_ci.txt
923+
[binaries]
924+
c = '${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android30-clang'
925+
cpp = '${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android30-clang++'
926+
ar = '${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar'
927+
strip = '${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip'
928+
rust = ['rustc', '--target', 'x86_64-linux-android']
929+
930+
[host_machine]
931+
system = 'android'
932+
cpu_family = 'x86_64'
933+
cpu = 'x86_64'
934+
endian = 'little'
935+
EOF
936+
- name: Meson setup
937+
run: meson setup build-android --cross-file cross_file_android_ci.txt
938+
- name: Meson compile
939+
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.3',
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.7.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.7.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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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.7.0',
10+
)
11+
12+
libc_args = [
13+
'--cfg', 'feature="default"',
14+
'--cfg', 'feature="extra_traits"',
15+
'--cfg', 'feature="std"',
16+
'--cfg', 'freebsd11',
17+
'--cfg', 'freebsd11',
18+
'--cfg', 'freebsd11',
19+
'--cfg', 'libc_align',
20+
'--cfg', 'libc_cfg_target_vendor',
21+
'--cfg', 'libc_const_extern_fn',
22+
'--cfg', 'libc_const_size_of',
23+
'--cfg', 'libc_core_cvoid',
24+
'--cfg', 'libc_int128',
25+
'--cfg', 'libc_long_array',
26+
'--cfg', 'libc_non_exhaustive',
27+
'--cfg', 'libc_packedN',
28+
'--cfg', 'libc_priv_mod_use',
29+
'--cfg', 'libc_ptr_addr_of',
30+
'--cfg', 'libc_underscore_const_names',
31+
'--cfg', 'libc_union',
32+
]
33+
34+
lib = static_library(
35+
'libc',
36+
'src/lib.rs',
37+
rust_abi : 'rust',
38+
override_options : ['rust_std=2021', 'build.rust_std=2021', 'warning_level=0'],
39+
rust_args: libc_args,
40+
)
41+
42+
dep_libc = declare_dependency(
43+
link_with : [lib]
44+
)

0 commit comments

Comments
 (0)