From ae222b3a85a0d7ddb7e70bda29699b954d45c35b Mon Sep 17 00:00:00 2001 From: diviocity Date: Sun, 1 Nov 2026 22:20:20 +0100 Subject: [PATCH] add build.vsh, update android --- AGENTS.md | 2 +- build.vsh | 147 +++++++++++++++++++++++++++++++++++++++ java/AndroidManifest.xml | 4 +- 3 files changed, 150 insertions(+), 3 deletions(-) create mode 100755 build.vsh diff --git a/AGENTS.md b/AGENTS.md index ea49112..6b93cb5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -83,7 +83,7 @@ Vendetta is three programs in one repository: 3. **The Android app**. The same `src/` code compiled by `vab` into a NativeActivity APK (`vab --name Vendetta --libs src`), running - `java/src/io/github/diviocity/vendetta/VendettaActivity.java` with + `java/src/vorelabs/vendetta/VendettaActivity.java` with in-tree headers and a supplied `libmpv.so` (see `libvendetta/mpv/android/README.md`). Android-specific divergences are everything under `module main` guarded by `$if android`, the diff --git a/build.vsh b/build.vsh new file mode 100755 index 0000000..e29687d --- /dev/null +++ b/build.vsh @@ -0,0 +1,147 @@ +#!/usr/bin/env -S v run +import imp + +// one architecture per build: vab links every ABI against the same -L path, and +// lld stops at the first libmpv.so it finds (libvendetta/mpv/android/README.md) +const android_arch = 'arm64-v8a' +const android_kit = 'libvendetta/mpv/android' +const android_lib = '${android_kit}/lib' + +// libplayer.so also ships in the kit, but is mpv-android's and is not needed +const android_libs = ['libmpv.so', 'libavcodec.so', 'libavdevice.so', 'libavfilter.so', + 'libavformat.so', 'libavutil.so', 'libc++_shared.so', 'libswresample.so', 'libswscale.so'] +const android_headers = ['client.h', 'render.h', 'render_gl.h'] + +mut ctx := imp.new() + +android := ctx.flag(id: 'android', help: 'build an apk') + +target_exe := if android { + 'vendetta.apk' +} else { + $if windows { 'vendetta.exe' } $else { 'vendetta' } +} + +ctx.default(['build']) + +ctx.add_target(target_exe) + +ctx.add_flow( + id: 'check' + help: 'check external dependencies' + flow: fn (self imp.Flow) ! { + mut missing := []string{} + + if !imp.check_v_modules(['ui2']) { + missing << 'ui2' + } + + if self.flag('android') { + if !imp.check_binary(['vab']) { + missing << 'vab' + } + for lib in android_libs { + path := '${android_lib}/${android_arch}/${lib}' + if !exists(path) { + missing << path + } + } + for header in android_headers { + path := '${android_kit}/include/mpv/${header}' + if !exists(path) { + missing << path + } + } + } else { + if !imp.check_system_c_links(['mpv/client.h', 'mpv/render.h', 'mpv/render_gl.h'], flags: ['-lmpv']) { + missing << 'libmpv headers' + } + if !imp.check_system_c_links(['X11/Xlib.h', 'X11/Xutil.h', 'X11/keysym.h', 'X11/Xatom.h'], flags: ['-lX11']) { + missing << 'libX11 headers' + } + if !imp.check_system_c_links(['X11/extensions/Xrandr.h'], flags: ['-lXrandr']) { + missing << 'libXrandr headers' + } + if !imp.check_system_c_links(['X11/extensions/XInput2.h'], flags: ['-lXi']) { + missing << 'libXi headers' + } + if !imp.check_system_c_links(['X11/Xcursor/Xcursor.h'], flags: ['-lXcursor']) { + missing << 'libXcursor headers' + } + if !imp.check_system_c_links(['GL/gl.h'], flags: ['-lGL', '-I/usr/include', '-I/usr/local/include', '-w']) { + missing << 'libGL headers' + } + if !imp.check_system_c_links(['dlfcn.h'], flags: ['-ldl']) { + missing << 'dlfcn.h' + } + if !imp.check_system_c_links(['pthread.h'], flags: ['-lpthread']) { + missing << 'pthread.h' + } + if !imp.check_system_c_links(['math.h'], flags: ['-lm']) { + missing << 'math.h' + } + } + + if missing.len > 0 { + println('could not find:') + println(missing.join('\n')) + if self.flag('android') { + println('see ${android_kit}/README.md for the mpv-android build') + } + println('check failed, exiting...') + exit(1) + } + } +) + +ctx.add_flow( + id: 'build' + help: 'build the release binary' + takes: if android { ['src', 'libvendetta', 'java'] } else { ['src', 'libvendetta'] } + gives: [target_exe] + check: .mtime + pre: if android { [imp.FlowDep{id: 'check'}] } else { []imp.FlowDep{} } + flags: [ + imp.Flag{id: 'prod', help: 'optimised desktop build'}, + imp.Flag{id: 'mpris', help: 'enable mpris support'}, + ] + flow: fn [target_exe] (self imp.Flow) ! { + mut args := []string{} + if self.flag('android') { + flat_link := '${android_lib}/libmpv.so' + if real_path(flat_link) != real_path('${android_lib}/${android_arch}/libmpv.so') { + rm(flat_link) or {} + symlink('${android_arch}/libmpv.so', flat_link)! + } + args << [ + 'vab', + '--archs', android_arch, + '--name', 'Vendetta', + '--package-id', 'vorelabs.vendetta', + '--libs', abs_path(android_lib), + '--package-overrides', abs_path('java'), + '-f', '-d sokol_gles3', + 'src', + ] + } else { + args << 'v' + $if darwin { + args << ['-d', 'darwin_sokol_glcore33'] + } + if self.flag('mpris') { + args << ['-d', 'mpris'] + } + if self.flag('prod') { + args << '-prod' + } + args << ['-d', 'ui2_custom_rendering', '-o', target_exe, 'src'] + } + imp.system_args(args)! + } +) + +ctx.add_auto_flow(.clean) +if !android { + ctx.add_auto_flow(.run) +} +ctx.flow() diff --git a/java/AndroidManifest.xml b/java/AndroidManifest.xml index 43b2ba1..b5d4465 100644 --- a/java/AndroidManifest.xml +++ b/java/AndroidManifest.xml @@ -4,7 +4,7 @@ android:versionCode="1" android:versionName="@string/v_app_name" android:installLocation="auto" - package="io.github.diviocity.vendetta" + package="vorelabs.vendetta" > @@ -19,7 +19,7 @@ tools:replace="android:icon,android:theme,android:allowBackup,label" > -