From 298dc77c38f0856d06905dbdda30780b3c6424a3 Mon Sep 17 00:00:00 2001 From: Larpon Date: Thu, 23 Jun 2022 10:22:55 +0200 Subject: [PATCH] ci: add pure `-os android` checks (#14837) --- .github/workflows/android_cross_compile.vsh | 67 +++++++++++++++++++++ .github/workflows/vab_ci.yml | 24 ++++++++ vlib/os/os_android.c.v | 3 + 3 files changed, 94 insertions(+) create mode 100755 .github/workflows/android_cross_compile.vsh diff --git a/.github/workflows/android_cross_compile.vsh b/.github/workflows/android_cross_compile.vsh new file mode 100755 index 000000000..40526bca7 --- /dev/null +++ b/.github/workflows/android_cross_compile.vsh @@ -0,0 +1,67 @@ +#!/usr/bin/env -S v + +module main + +import os +import vab.vxt +import vab.android.ndk + +fn main() { + assert ndk.found() + assert vxt.found() + + work_dir := os.join_path(os.temp_dir(), 'android_cross_compile_test') + os.rm(work_dir) or {} + os.mkdir_all(work_dir) or { panic(err) } + vexe := vxt.vexe() + + examples_dir := os.join_path(vxt.home(), 'examples') + v_example := os.join_path(examples_dir, 'toml.v') + + ndk_version := ndk.default_version() + + sysroot_path := ndk.sysroot_path(ndk_version) or { panic(err) } + include_path := os.join_path(sysroot_path, 'usr', 'include') + android_include_path := os.join_path(include_path, 'android') + + //'-I"$include_path"' + cflags := ['-I"$android_include_path"', '-Wno-unused-value', '-Wno-implicit-function-declaration', + '-Wno-int-conversion'] + for arch in ndk.supported_archs { + for level in ['min', 'max'] { + compiler_api := match level { + 'min' { + ndk.compiler_min_api(.c, ndk_version, arch) or { panic(err) } + } + 'max' { + ndk.compiler_max_api(.c, ndk_version, arch) or { panic(err) } + } + else { + panic('invalid min/max level') + } + } + + os.setenv('VCROSS_COMPILER_NAME', compiler_api, true) + c_file := os.join_path(work_dir, arch + '-' + level + '.c') + o_file := os.join_path(work_dir, arch + '-' + level + '.o') + + // x.v -> x.c + v_compile_cmd := '$vexe -o $c_file -os android -gc none $v_example' + vres := os.execute(v_compile_cmd) + if vres.exit_code != 0 { + panic('"$v_compile_cmd" failed: $vres.output') + } + assert os.exists(c_file) + + // x.c -> x.o + compile_cmd := '$compiler_api ${cflags.join(' ')} -c $c_file -o $o_file' + cres := os.execute(compile_cmd) + if cres.exit_code != 0 { + panic('"$compile_cmd" failed: $cres.output') + } + assert os.exists(o_file) + compiler_exe_name := os.file_name(compiler_api) + println('Compiled examples/toml.v successfully for ($level) $arch $compiler_exe_name') + } + } +} diff --git a/.github/workflows/vab_ci.yml b/.github/workflows/vab_ci.yml index 190ff8aec..79fc88bbe 100644 --- a/.github/workflows/vab_ci.yml +++ b/.github/workflows/vab_ci.yml @@ -48,3 +48,27 @@ jobs: safe_name=$(echo "$example" | sed 's%/%-%' | sed 's%\.%-%' ) vab examples/$example -o apks/$safe_name.apk done + + v-compiles-os-android: + runs-on: ubuntu-20.04 + if: github.event_name != 'push' || github.event.ref == 'refs/heads/master' || github.event.repository.full_name != 'vlang/v' + timeout-minutes: 10 + steps: + - uses: actions/checkout@v2 + - name: Build V + run: make && sudo ./v symlink + + - name: Install vab + run: | + v install vab + v -g ~/.vmodules/vab + sudo ln -s ~/.vmodules/vab/vab /usr/local/bin/vab + + - name: Run vab --help + run: vab --help + + - name: Run vab doctor + run: vab doctor + + - name: Check `v -os android` *without* -apk flag + run: .github/workflows/android_cross_compile.vsh diff --git a/vlib/os/os_android.c.v b/vlib/os/os_android.c.v index 0ef6fb2de..c7e6f6551 100644 --- a/vlib/os/os_android.c.v +++ b/vlib/os/os_android.c.v @@ -1,5 +1,8 @@ module os +#include +#include + pub enum AssetMode { buffer = C.AASSET_MODE_BUFFER // Caller plans to ask for a read-only buffer with all data. random = C.AASSET_MODE_RANDOM // Read chunks, and seek forward and backward. -- 2.30.2