Skip to content

Commit a8079ee

Browse files
authored
Add android CI and fix android (servo#331)
* Add android testing to CI Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Make EGL ctx current Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Update `test_newly_created_contexts_are_current` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Android/OHOS does not support OpenGL compatibility profile Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
1 parent b3a4060 commit a8079ee

File tree

8 files changed

+78
-18
lines changed

8 files changed

+78
-18
lines changed

.github/workflows/main.yml

+48-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ on:
1010

1111
env:
1212
CARGO_TERM_COLOR: always
13+
RUST_BACKTRACE: full
1314

1415
jobs:
1516
Build:
1617
name: ${{ format('{0} {1}', matrix.platform.target, matrix.features)}}
1718
runs-on: ${{ matrix.platform.os }}
18-
env:
19-
RUST_BACKTRACE: 1
2019
strategy:
2120
fail-fast: false
2221
matrix:
@@ -58,12 +57,11 @@ jobs:
5857
sudo apt install gcc libxxf86vm-dev libosmesa6-dev libgles2-mesa-dev xvfb weston -y
5958
- name: Install rust
6059
id: toolchain
61-
uses: dtolnay/rust-toolchain@stable
60+
uses: dtolnay/rust-toolchain@1.81.0
6261
with:
6362
targets: ${{ matrix.platform.target }}
6463
- name: Build
6564
run: |
66-
rustup target add ${{ matrix.platform.target }}
6765
cargo build --features "${{ matrix.features }}" --target ${{ matrix.platform.target }}
6866
- name: Test
6967
if: ${{ matrix.platform.test && startsWith(matrix.platform.os, 'ubuntu') }}
@@ -74,6 +72,51 @@ jobs:
7472
if: ${{ matrix.platform.test && !startsWith(matrix.platform.os, 'ubuntu') }}
7573
run: |
7674
cargo test --features "${{ matrix.features }}" --target ${{ matrix.platform.target }}
75+
76+
android-test:
77+
name: ${{ format('x86_64-linux-android {0}', matrix.features)}}
78+
runs-on: ubuntu-24.04
79+
strategy:
80+
fail-fast: false
81+
matrix:
82+
features:
83+
[
84+
"",
85+
"chains sm-raw-window-handle-06",
86+
"chains sm-raw-window-handle-05",
87+
]
88+
steps:
89+
- uses: actions/checkout@v4
90+
- name: Install rust
91+
id: toolchain
92+
uses: dtolnay/rust-toolchain@1.81.0
93+
with:
94+
targets: x86_64-linux-android
95+
96+
- uses: taiki-e/install-action@v2
97+
with:
98+
tool: cargo-dinghy
99+
100+
- name: Enable KVM
101+
run: |
102+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
103+
sudo udevadm control --reload-rules
104+
sudo udevadm trigger --name-match=kvm
105+
106+
- name: Run tests in android emulator
107+
uses: reactivecircus/android-emulator-runner@v2
108+
env:
109+
RANLIB: "${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib"
110+
with:
111+
api-level: 30
112+
arch: x86_64
113+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
114+
disable-animations: true
115+
script: |
116+
cargo dinghy all-platforms
117+
cargo dinghy all-devices
118+
cargo dinghy -p auto-android-x86_64-api30 --env RUST_BACKTRACE=${{ env.RUST_BACKTRACE }} test --features "${{ matrix.features }}" -- --test-threads 1
119+
77120
Format:
78121
name: Run `rustfmt`
79122
runs-on: ubuntu-24.04
@@ -84,7 +127,7 @@ jobs:
84127
build_result:
85128
name: Result
86129
runs-on: ubuntu-24.04
87-
needs: ["Build", "Format"]
130+
needs: ["Build", "android-test", "Format"]
88131
if: always()
89132
steps:
90133
- name: Mark the job as successful

Cargo.toml

+7-3
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,19 @@ libc = "0.2"
3939
log = "0.4"
4040
glow = "0.16"
4141
osmesa-sys = { version = "0.1", optional = true }
42-
rwh_05 = { package = "raw-window-handle", version = "0.5.2", features = ["std"], optional = true }
43-
rwh_06 = { package = "raw-window-handle", version = "0.6.2", features = ["std"], optional = true }
42+
rwh_05 = { package = "raw-window-handle", version = "0.5.2", features = [
43+
"std",
44+
], optional = true }
45+
rwh_06 = { package = "raw-window-handle", version = "0.6.2", features = [
46+
"std",
47+
], optional = true }
4448

4549
[dev-dependencies]
4650
clap = "2"
4751
gl = "0.14"
4852
png = "0.17"
4953
rand = "0.8"
50-
winit = "0.29"
54+
winit = { version = "0.29.10", features = ["android-native-activity"] }
5155
serial_test = "3.1.0"
5256

5357
[target.'cfg(target_os = "macos")'.dependencies]

examples/threads.rs

+3
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ fn make_native_widget(
111111
native_widget
112112
}
113113

114+
#[cfg(target_os = "android")]
115+
fn main() {}
116+
114117
#[cfg(not(target_os = "android"))]
115118
fn main() {
116119
use winit::{

rust-toolchain.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
2-
channel = "1.80.1"
3-
components = [ "rustfmt" ]
2+
channel = "1.81.0"
3+
components = ["rustfmt"]
44
profile = "minimal"

src/platform/egl/context.rs

+8
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ impl Device {
107107
// Create a dummy pbuffer.
108108
let pbuffer = context::create_dummy_pbuffer(egl_display, egl_context);
109109

110+
EGL_FUNCTIONS.with(|egl| {
111+
if egl.MakeCurrent(egl_display, pbuffer, pbuffer, egl_context) == egl::FALSE {
112+
let err = egl.GetError().to_windowing_api_error();
113+
return Err(Error::MakeCurrentFailed(err));
114+
}
115+
Ok(())
116+
})?;
117+
110118
// Wrap up the EGL context.
111119
let context = Context {
112120
egl_context,

src/platform/egl/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ crate::implement_interfaces!();
1818
#[cfg(feature = "sm-test")]
1919
#[path = "../../tests.rs"]
2020
pub mod tests;
21+
22+
#[cfg(all(not(feature = "sm-test"), test))]
23+
#[path = "../../tests.rs"]
24+
pub mod tests;

src/platform/generic/egl/context.rs

+5
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ impl ContextDescriptor {
295295
return Err(Error::UnsupportedGLProfile);
296296
}
297297

298+
// Android/OHOS does not support OpenGL compatibility profile at all
299+
if cfg!(any(android_platform, ohos_platform)) && compatibility_profile {
300+
return Err(Error::UnsupportedGLProfile);
301+
}
302+
298303
// Create required config attributes.
299304
//
300305
// We check these separately because `eglChooseConfig` on its own might give us 32-bit

src/tests.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,7 @@ pub fn test_newly_created_contexts_are_current() {
204204
unsafe { Gl::from_loader_function(|symbol| device.get_proc_address(&context, symbol)) };
205205

206206
unsafe {
207-
// Check to make sure GL calls don't work, because there is no surface.
208-
clear(&gl, &[255, 0, 0, 255]);
209-
assert_eq!(gl.get_error(), glow::INVALID_FRAMEBUFFER_OPERATION);
210-
assert_ne!(get_pixel_from_bottom_row(&gl), [255, 0, 0, 255]);
211-
assert_eq!(gl.get_error(), glow::INVALID_FRAMEBUFFER_OPERATION);
212-
assert_eq!(gl.get_error(), glow::NO_ERROR);
213-
214-
// Make a context current.
207+
// Make a context current with surface.
215208
let surface = make_surface(&mut device, &context);
216209
device
217210
.bind_surface_to_context(&mut context, surface)

0 commit comments

Comments
 (0)