add build.vsh, update android
@@ -83,7 +83,7 @@ Vendetta is three programs in one repository:
8383
84843. **The Android app**. The same `src/` code compiled by `vab` into a
8585 NativeActivity APK (`vab --name Vendetta --libs <dir> src`), running
86- `java/src/io/github/diviocity/vendetta/VendettaActivity.java` with
86+ `java/src/vorelabs/vendetta/VendettaActivity.java` with
8787 in-tree headers and a supplied `libmpv.so` (see
8888 `libvendetta/mpv/android/README.md`). Android-specific divergences are
8989 everything under `module main` guarded by `$if android`, the
@@ -0,0 +1,147 @@
1+#!/usr/bin/env -S v run
2+import imp
3+
4+// one architecture per build: vab links every ABI against the same -L path, and
5+// lld stops at the first libmpv.so it finds (libvendetta/mpv/android/README.md)
6+const android_arch = 'arm64-v8a'
7+const android_kit = 'libvendetta/mpv/android'
8+const android_lib = '${android_kit}/lib'
9+
10+// libplayer.so also ships in the kit, but is mpv-android's and is not needed
11+const android_libs = ['libmpv.so', 'libavcodec.so', 'libavdevice.so', 'libavfilter.so',
12+ 'libavformat.so', 'libavutil.so', 'libc++_shared.so', 'libswresample.so', 'libswscale.so']
13+const android_headers = ['client.h', 'render.h', 'render_gl.h']
14+
15+mut ctx := imp.new()
16+
17+android := ctx.flag(id: 'android', help: 'build an apk')
18+
19+target_exe := if android {
20+ 'vendetta.apk'
21+} else {
22+ $if windows { 'vendetta.exe' } $else { 'vendetta' }
23+}
24+
25+ctx.default(['build'])
26+
27+ctx.add_target(target_exe)
28+
29+ctx.add_flow(
30+ id: 'check'
31+ help: 'check external dependencies'
32+ flow: fn (self imp.Flow) ! {
33+ mut missing := []string{}
34+
35+ if !imp.check_v_modules(['ui2']) {
36+ missing << 'ui2'
37+ }
38+
39+ if self.flag('android') {
40+ if !imp.check_binary(['vab']) {
41+ missing << 'vab'
42+ }
43+ for lib in android_libs {
44+ path := '${android_lib}/${android_arch}/${lib}'
45+ if !exists(path) {
46+ missing << path
47+ }
48+ }
49+ for header in android_headers {
50+ path := '${android_kit}/include/mpv/${header}'
51+ if !exists(path) {
52+ missing << path
53+ }
54+ }
55+ } else {
56+ if !imp.check_system_c_links(['mpv/client.h', 'mpv/render.h', 'mpv/render_gl.h'], flags: ['-lmpv']) {
57+ missing << 'libmpv headers'
58+ }
59+ if !imp.check_system_c_links(['X11/Xlib.h', 'X11/Xutil.h', 'X11/keysym.h', 'X11/Xatom.h'], flags: ['-lX11']) {
60+ missing << 'libX11 headers'
61+ }
62+ if !imp.check_system_c_links(['X11/extensions/Xrandr.h'], flags: ['-lXrandr']) {
63+ missing << 'libXrandr headers'
64+ }
65+ if !imp.check_system_c_links(['X11/extensions/XInput2.h'], flags: ['-lXi']) {
66+ missing << 'libXi headers'
67+ }
68+ if !imp.check_system_c_links(['X11/Xcursor/Xcursor.h'], flags: ['-lXcursor']) {
69+ missing << 'libXcursor headers'
70+ }
71+ if !imp.check_system_c_links(['GL/gl.h'], flags: ['-lGL', '-I/usr/include', '-I/usr/local/include', '-w']) {
72+ missing << 'libGL headers'
73+ }
74+ if !imp.check_system_c_links(['dlfcn.h'], flags: ['-ldl']) {
75+ missing << 'dlfcn.h'
76+ }
77+ if !imp.check_system_c_links(['pthread.h'], flags: ['-lpthread']) {
78+ missing << 'pthread.h'
79+ }
80+ if !imp.check_system_c_links(['math.h'], flags: ['-lm']) {
81+ missing << 'math.h'
82+ }
83+ }
84+
85+ if missing.len > 0 {
86+ println('could not find:')
87+ println(missing.join('\n'))
88+ if self.flag('android') {
89+ println('see ${android_kit}/README.md for the mpv-android build')
90+ }
91+ println('check failed, exiting...')
92+ exit(1)
93+ }
94+ }
95+)
96+
97+ctx.add_flow(
98+ id: 'build'
99+ help: 'build the release binary'
100+ takes: if android { ['src', 'libvendetta', 'java'] } else { ['src', 'libvendetta'] }
101+ gives: [target_exe]
102+ check: .mtime
103+ pre: if android { [imp.FlowDep{id: 'check'}] } else { []imp.FlowDep{} }
104+ flags: [
105+ imp.Flag{id: 'prod', help: 'optimised desktop build'},
106+ imp.Flag{id: 'mpris', help: 'enable mpris support'},
107+ ]
108+ flow: fn [target_exe] (self imp.Flow) ! {
109+ mut args := []string{}
110+ if self.flag('android') {
111+ flat_link := '${android_lib}/libmpv.so'
112+ if real_path(flat_link) != real_path('${android_lib}/${android_arch}/libmpv.so') {
113+ rm(flat_link) or {}
114+ symlink('${android_arch}/libmpv.so', flat_link)!
115+ }
116+ args << [
117+ 'vab',
118+ '--archs', android_arch,
119+ '--name', 'Vendetta',
120+ '--package-id', 'vorelabs.vendetta',
121+ '--libs', abs_path(android_lib),
122+ '--package-overrides', abs_path('java'),
123+ '-f', '-d sokol_gles3',
124+ 'src',
125+ ]
126+ } else {
127+ args << 'v'
128+ $if darwin {
129+ args << ['-d', 'darwin_sokol_glcore33']
130+ }
131+ if self.flag('mpris') {
132+ args << ['-d', 'mpris']
133+ }
134+ if self.flag('prod') {
135+ args << '-prod'
136+ }
137+ args << ['-d', 'ui2_custom_rendering', '-o', target_exe, 'src']
138+ }
139+ imp.system_args(args)!
140+ }
141+)
142+
143+ctx.add_auto_flow(.clean)
144+if !android {
145+ ctx.add_auto_flow(.run)
146+}
147+ctx.flow()
@@ -4,7 +4,7 @@
44 android:versionCode="1"
55 android:versionName="@string/v_app_name"
66 android:installLocation="auto"
7- package="io.github.diviocity.vendetta"
7+ package="vorelabs.vendetta"
88>
99
1010 <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30" />
@@ -19,7 +19,7 @@
1919 tools:replace="android:icon,android:theme,android:allowBackup,label"
2020 >
2121
22- <activity android:name="io.github.diviocity.vendetta.VendettaActivity"
22+ <activity android:name="vorelabs.vendetta.VendettaActivity"
2323 android:configChanges="orientation|screenSize|keyboard|keyboardHidden"
2424 android:launchMode="singleTask"
2525 android:exported="true"