|
| 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 | +} |
0 commit comments