vendetta / build.vsh
147 lines · 134 sloc · 4.01 KB · 18961e95223a6030fd007472d4b38a498fd1ed14
Raw
1#!/usr/bin/env -S v run
2import x.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)
6const android_arch = 'arm64-v8a'
7const android_kit = 'libvendetta/mpv/android'
8const android_lib = '${android_kit}/lib'
9
10// libplayer.so also ships in the kit, but is mpv-android's and is not needed
11const android_libs = ['libmpv.so', 'libavcodec.so', 'libavdevice.so', 'libavfilter.so',
12 'libavformat.so', 'libavutil.so', 'libc++_shared.so', 'libswresample.so', 'libswscale.so']
13const android_headers = ['client.h', 'render.h', 'render_gl.h']
14
15mut ctx := imp.new()
16
17android := ctx.flag(id: 'android', help: 'build an apk')
18
19target_exe := if android {
20 'vendetta.apk'
21} else {
22 $if windows { 'vendetta.exe' } $else { 'vendetta' }
23}
24
25ctx.default(['build'])
26
27ctx.add_target(target_exe)
28
29ctx.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
97ctx.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
143ctx.add_auto_flow(.clean)
144if !android {
145 ctx.add_auto_flow(.run)
146}
147ctx.flow()
148