Skip to content

Commit aff3acb

Browse files
authored
[GL] Testing with the Android emulator on CI
1 parent 477f179 commit aff3acb

File tree

14 files changed

+1081
-97
lines changed

14 files changed

+1081
-97
lines changed

.cargo/config

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[target.x86_64-linux-android]
2+
rustflags = [
3+
"-C", "link-arg=-lc++_static",
4+
"-C", "link-arg=-lc++abi",
5+
"-C", "link-arg=-lEGL",
6+
"-C", "link-arg=-lGLESv3",
7+
"-C", "link-arg=-llog",
8+
]

.github/workflows/CI.yml

+27-97
Original file line numberDiff line numberDiff line change
@@ -3,105 +3,35 @@ name: CI
33
on:
44
push:
55
branches-ignore: [staging.tmp]
6+
paths:
7+
#- 'examples/quad_android/**'
8+
#- '!examples/quad_android/**.md'
9+
#- 'src/backend/gl/**'
10+
#- '!src/backend/gl/**.md'
611
pull_request:
712
branches-ignore: [staging.tmp]
8-
13+
paths:
14+
#- 'examples/quad_android/**'
15+
#- '!examples/quad_android/**.md'
16+
#- 'src/backend/gl/**'
17+
#- '!src/backend/gl/**.md'
918
jobs:
10-
ios_build:
11-
name: iOS Stable
12-
runs-on: macos-10.15
13-
env:
14-
TARGET: aarch64-apple-ios
15-
steps:
16-
- uses: actions/checkout@v2
17-
- name: Prepare Rust
18-
run: rustup target add ${{ env.TARGET }}
19-
- run: cargo check --manifest-path src/backend/metal/Cargo.toml --target ${{ env.TARGET }}
20-
21-
android_build:
22-
name: Android Stable
23-
runs-on: ubuntu-18.04
24-
env:
25-
TARGET: aarch64-linux-android
26-
steps:
27-
- uses: actions/checkout@v2
28-
- run: echo "$ANDROID_HOME/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH
29-
- name: Prepare Rust
30-
run: rustup target add ${{ env.TARGET }}
31-
- run: cargo check --manifest-path src/backend/vulkan/Cargo.toml --target ${{ env.TARGET }}
32-
- run: cargo check --manifest-path src/backend/gl/Cargo.toml --target ${{ env.TARGET }}
33-
34-
webgl_build:
35-
name: Web Assembly
36-
runs-on: ubuntu-18.04
37-
steps:
38-
- uses: actions/checkout@v2
39-
- run: rustup target add wasm32-unknown-unknown
40-
- run: cargo build --manifest-path examples/Cargo.toml --features gl --target wasm32-unknown-unknown --bin quad
41-
42-
check-advisories:
43-
name: Advisory Check
44-
runs-on: ubuntu-18.04
45-
steps:
46-
- uses: actions/checkout@v2
47-
- uses: EmbarkStudios/cargo-deny-action@v1
19+
test:
20+
runs-on: macos-10.15
21+
steps:
22+
- name: checkout
23+
uses: actions/checkout@v2
24+
- name: run tests
25+
uses: reactivecircus/android-emulator-runner@v2
4826
with:
49-
command: check advisories
50-
51-
check-dependencies:
52-
name: Dependency Check
53-
runs-on: ubuntu-18.04
54-
steps:
55-
- uses: actions/checkout@v2
56-
- uses: EmbarkStudios/cargo-deny-action@v1
57-
with:
58-
command: check bans licenses sources
59-
60-
build:
61-
name: ${{ matrix.name }}
62-
runs-on: ${{ matrix.os }}
63-
strategy:
64-
fail-fast: false
65-
matrix:
66-
name:
67-
[
68-
MacOS Stable,
69-
MacOS Nightly,
70-
Ubuntu Stable,
71-
Ubuntu Nightly,
72-
Windows Stable,
73-
Windows Nightly,
74-
]
75-
include:
76-
- os: macos-10.15
77-
name: MacOS Stable
78-
channel: stable
79-
- os: macos-10.15
80-
name: MacOS Nightly
81-
channel: nightly
82-
- os: ubuntu-18.04
83-
name: Ubuntu Stable
84-
channel: stable
85-
- os: ubuntu-18.04
86-
name: Ubuntu Nightly
87-
channel: nightly
88-
- os: windows-2019
89-
name: Windows Stable
90-
channel: stable
91-
- os: windows-2019
92-
name: Windows Nightly
93-
channel: nightly
94-
steps:
95-
- uses: actions/checkout@v2
96-
- if: matrix.channel == 'nightly'
97-
name: Install latest nightly
98-
uses: actions-rs/toolchain@v1
27+
api-level: 29
28+
arch: x86_64
29+
profile: Nexus 6
30+
script: sh ./.github/workflows/android_test.sh
31+
- uses: actions/upload-artifact@master
32+
if: ${{ always() }}
9933
with:
100-
toolchain: nightly
101-
override: true
102-
- if: matrix.os == 'windows-2019'
103-
name: Install make
104-
run: choco install make
105-
#- if: matrix.channel == 'stable'
106-
# run: rustup component add clippy
107-
- run: make all
34+
name: screenshot
35+
path: |
36+
~/screenshot.png
37+
~/logcat.log

.github/workflows/android_test.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
set -ex
4+
5+
rustup target install x86_64-linux-android
6+
cargo install cargo-apk
7+
cargo apk run --package quad_android --target x86_64-linux-android
8+
9+
sleep 30s
10+
11+
adb shell /system/bin/screencap -p /sdcard/screenshot.png
12+
adb pull /sdcard/screenshot.png ~/screenshot.png
13+
adb logcat *:S RustStdoutStderr:V -d > ~/logcat.log
14+
15+
if grep -e 'thread.*panicked at' ~/logcat.log;
16+
then
17+
exit 1
18+
else
19+
exit 0
20+
fi

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313
"src/hal",
1414
"src/warden",
1515
"examples",
16+
"examples/quad_android",
1617
]
1718

1819
[patch."https://github.com/gfx-rs/naga"]

examples/quad_android/Cargo.toml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[package]
2+
name = "quad_android"
3+
version = "0.1.0"
4+
publish = false
5+
workspace = "../.."
6+
edition = "2018"
7+
8+
[lib]
9+
crate-type = ["cdylib"]
10+
11+
[features]
12+
default = ["gl"]
13+
gl = ["gfx-backend-gl"]
14+
15+
[target.'cfg(target_os = "android")'.dependencies]
16+
android_logger = "0.9"
17+
image = "0.23.12"
18+
log = "0.4"
19+
hal = { path = "../../src/hal", version = "0.6", package = "gfx-hal" }
20+
auxil = { path = "../../src/auxil/auxil", version = "0.5", package = "gfx-auxil" }
21+
gfx-backend-empty = { path = "../../src/backend/empty", version = "0.6" }
22+
winit = "0.23"
23+
ndk-glue = "0.2"
24+
25+
[target.'cfg(target_os = "android")'.dependencies.gfx-backend-gl]
26+
path = "../../src/backend/gl"
27+
optional = true
28+
29+
[package.metadata.android]
30+
package_name = "com.rust.game"
31+
label = "GfxQuad"
32+
# Vulkan supports on devices running Android API level 24 or higher.
33+
target_sdk_version = 29
34+
min_sdk_version = 29
35+
fullscreen = true
36+
opengles_version = [3, 0]
37+
orientation = "sensorLandscape"

examples/quad_android/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Quad
2+
3+
The following image is an output of `cargo run --bin quad --features=gl`:
4+
5+
![screenshot](screenshot.png "Quad")

examples/quad_android/data/index.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<html>
2+
<head>
3+
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
4+
</head>
5+
<body>
6+
<script src="./spirv_cross_wrapper_glsl.js"></script>
7+
<script type="module">
8+
import init from './quad.js';
9+
window.addEventListener("load", () => {
10+
const module = window.sc_internal_wrapper().then(module => {
11+
window.sc_internal = module;
12+
init('./quad_bg.wasm');
13+
});
14+
});
15+
</script>
16+
</body>
17+
</html>
18+

examples/quad_android/data/logo.png

24.3 KB
Loading

examples/quad_android/data/quad.frag

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#version 450
2+
#extension GL_ARB_separate_shader_objects : enable
3+
4+
layout(location = 0) in vec2 v_uv;
5+
layout(location = 0) out vec4 target0;
6+
7+
layout(set = 0, binding = 0) uniform texture2D u_texture;
8+
layout(set = 0, binding = 1) uniform sampler u_sampler;
9+
10+
void main() {
11+
target0 = texture(sampler2D(u_texture, u_sampler), v_uv);
12+
}
720 Bytes
Binary file not shown.

examples/quad_android/data/quad.vert

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#version 450
2+
#extension GL_ARB_separate_shader_objects : enable
3+
4+
// see colour-uniform example for the case where this is a push constant
5+
const float scale = 1.2f;
6+
7+
layout(location = 0) in vec2 a_pos;
8+
layout(location = 1) in vec2 a_uv;
9+
layout(location = 0) out vec2 v_uv;
10+
11+
out gl_PerVertex {
12+
vec4 gl_Position;
13+
};
14+
15+
void main() {
16+
v_uv = a_uv;
17+
gl_Position = vec4(scale * a_pos, 0.0, 1.0);
18+
}
868 Bytes
Binary file not shown.

examples/quad_android/screenshot.png

37.9 KB
Loading

0 commit comments

Comments
 (0)