Skip to content

Commit 298dc77

Browse files
authored
ci: add pure -os android checks (#14837)
1 parent e9a8f5f commit 298dc77

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env -S v
2+
3+
module main
4+
5+
import os
6+
import vab.vxt
7+
import vab.android.ndk
8+
9+
fn main() {
10+
assert ndk.found()
11+
assert vxt.found()
12+
13+
work_dir := os.join_path(os.temp_dir(), 'android_cross_compile_test')
14+
os.rm(work_dir) or {}
15+
os.mkdir_all(work_dir) or { panic(err) }
16+
vexe := vxt.vexe()
17+
18+
examples_dir := os.join_path(vxt.home(), 'examples')
19+
v_example := os.join_path(examples_dir, 'toml.v')
20+
21+
ndk_version := ndk.default_version()
22+
23+
sysroot_path := ndk.sysroot_path(ndk_version) or { panic(err) }
24+
include_path := os.join_path(sysroot_path, 'usr', 'include')
25+
android_include_path := os.join_path(include_path, 'android')
26+
27+
//'-I"$include_path"'
28+
cflags := ['-I"$android_include_path"', '-Wno-unused-value', '-Wno-implicit-function-declaration',
29+
'-Wno-int-conversion']
30+
for arch in ndk.supported_archs {
31+
for level in ['min', 'max'] {
32+
compiler_api := match level {
33+
'min' {
34+
ndk.compiler_min_api(.c, ndk_version, arch) or { panic(err) }
35+
}
36+
'max' {
37+
ndk.compiler_max_api(.c, ndk_version, arch) or { panic(err) }
38+
}
39+
else {
40+
panic('invalid min/max level')
41+
}
42+
}
43+
44+
os.setenv('VCROSS_COMPILER_NAME', compiler_api, true)
45+
c_file := os.join_path(work_dir, arch + '-' + level + '.c')
46+
o_file := os.join_path(work_dir, arch + '-' + level + '.o')
47+
48+
// x.v -> x.c
49+
v_compile_cmd := '$vexe -o $c_file -os android -gc none $v_example'
50+
vres := os.execute(v_compile_cmd)
51+
if vres.exit_code != 0 {
52+
panic('"$v_compile_cmd" failed: $vres.output')
53+
}
54+
assert os.exists(c_file)
55+
56+
// x.c -> x.o
57+
compile_cmd := '$compiler_api ${cflags.join(' ')} -c $c_file -o $o_file'
58+
cres := os.execute(compile_cmd)
59+
if cres.exit_code != 0 {
60+
panic('"$compile_cmd" failed: $cres.output')
61+
}
62+
assert os.exists(o_file)
63+
compiler_exe_name := os.file_name(compiler_api)
64+
println('Compiled examples/toml.v successfully for ($level) $arch $compiler_exe_name')
65+
}
66+
}
67+
}

.github/workflows/vab_ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,27 @@ jobs:
4848
safe_name=$(echo "$example" | sed 's%/%-%' | sed 's%\.%-%' )
4949
vab examples/$example -o apks/$safe_name.apk
5050
done
51+
52+
v-compiles-os-android:
53+
runs-on: ubuntu-20.04
54+
if: github.event_name != 'push' || github.event.ref == 'refs/heads/master' || github.event.repository.full_name != 'vlang/v'
55+
timeout-minutes: 10
56+
steps:
57+
- uses: actions/checkout@v2
58+
- name: Build V
59+
run: make && sudo ./v symlink
60+
61+
- name: Install vab
62+
run: |
63+
v install vab
64+
v -g ~/.vmodules/vab
65+
sudo ln -s ~/.vmodules/vab/vab /usr/local/bin/vab
66+
67+
- name: Run vab --help
68+
run: vab --help
69+
70+
- name: Run vab doctor
71+
run: vab doctor
72+
73+
- name: Check `v -os android` *without* -apk flag
74+
run: .github/workflows/android_cross_compile.vsh

vlib/os/os_android.c.v

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module os
22

3+
#include <asset_manager.h>
4+
#include <asset_manager_jni.h>
5+
36
pub enum AssetMode {
47
buffer = C.AASSET_MODE_BUFFER // Caller plans to ask for a read-only buffer with all data.
58
random = C.AASSET_MODE_RANDOM // Read chunks, and seek forward and backward.

0 commit comments

Comments
 (0)