@@ -176,19 +176,63 @@ pub fn compile_v_to_c(opt CompileOptions) !VMetaInfo {
176
176
return v_meta_dump
177
177
}
178
178
179
+ fn build_raylib (opt CompileOptions,raylib_path string ,arch string ) ? {
180
+ build_path := os.join_path (raylib_path,'build' )
181
+ // check if the library already exists or compile it
182
+ if os.exists (os.join_path (build_path,arch,'libraylib.a' )){
183
+ return
184
+ }
185
+ else {
186
+ src_path := os.join_path (raylib_path,'src' )
187
+ ndk_path := ndk.root ()
188
+ os.execute ('make -C $src_path clean' )
189
+ arch_name := if arch == 'arm64-v8a' {'arm64' } else if arch == 'armeabi-v7a' {'arm' } else if arch in ['x86' ,'x86_64' ] {arch} else {'' }
190
+ if arch_name ! in ['arm64' ,'arm' ,'x86' ,'x86_64' ]{return error ('$arch_name is now a known architecture' )}
191
+ os.execute ('make -C $src_path PLATFORM=PLATFORM_ANDROID ANDROID_NDK=$ndk_path ANDROID_ARCH=$arch_name ANDROID_API_VERSION=$opt.api_level ' )
192
+ taget_path := os.join_path (build_path,arch)
193
+ os.mkdir_all (taget_path) or {return error ('failed making directory "$taget_path "' )}
194
+ os.mv (os.join_path (src_path,'libraylib.a' ),taget_path) or {return error ('failed to move .a file from $src_path to $taget_path ' )}
195
+ }
196
+ }
197
+
198
+ fn download_raylib (raylib_path string ){
199
+ // clone raylib from github
200
+ os.execute ('git clone https://github.com/raysan5/raylib.git $raylib_path ' )
201
+ }
202
+
179
203
pub fn compile (opt CompileOptions) ! {
180
204
err_sig := @MOD + '.' + @FN
181
205
os.mkdir_all (opt.work_dir) or {
182
206
return error ('$err_sig : failed making directory "$opt.work_dir ". $err ' )
183
207
}
184
208
build_dir := opt.build_directory ()!
185
-
209
+
186
210
v_meta_dump := compile_v_to_c (opt) or {
187
211
return IError (CompileError{
188
212
kind: .v_to_c
189
213
err: err.msg ()
190
214
})
191
215
}
216
+
217
+ is_raylib := 'mohamedlt.vraylib' in v_meta_dump.imports
218
+
219
+ // check if raylib floder is found else clone it
220
+ if is_raylib{
221
+ raylib_path := os.join_path (vxt.vmodules ()or {return error ('$err_sig :vmodules folder not found' )},'vab' ,'raylib' )
222
+ if os.exists (raylib_path){
223
+ for arch in opt.archs{
224
+ build_raylib (opt,raylib_path,arch)or { return error ('cant build raylib ERROR: $err ' )}
225
+ }
226
+ }
227
+ else {
228
+ download_raylib (raylib_path)
229
+ for arch in opt.archs{
230
+ build_raylib (opt,raylib_path,arch)or { return error ('cant build raylib ERROR: $err ' )}
231
+ }
232
+ }
233
+
234
+ }
235
+
192
236
v_cflags := v_meta_dump.c_flags
193
237
imported_modules := v_meta_dump.imports
194
238
@@ -329,6 +373,16 @@ pub fn compile(opt CompileOptions) ! {
329
373
330
374
is_debug_build := opt.is_debug_build ()
331
375
376
+
377
+ // add needed flags for raylib
378
+ if is_raylib{
379
+ ldflags << '-lEGL'
380
+ ldflags << '-lGLESv2'
381
+ ldflags << '-u ANativeActivity_onCreate'
382
+ ldflags<< '-lOpenSLES'
383
+
384
+ }
385
+
332
386
// Sokol sapp
333
387
if 'sokol.sapp' in imported_modules {
334
388
if opt.verbosity > 1 {
@@ -457,14 +511,18 @@ pub fn compile(opt CompileOptions) ! {
457
511
arch_o_files := o_files[arch].map ('"$it "' )
458
512
arch_a_files := a_files[arch].map ('"$it "' )
459
513
460
- build_cmd := [
514
+ mut build_cmd := [
461
515
arch_cc[arch],
462
516
arch_o_files.join (' ' ),
463
517
'-o "$arch_lib_dir /lib${opt.lib_name} .so"' ,
464
518
arch_a_files.join (' ' ),
465
519
'-L"' + arch_libs[arch] + '"' ,
466
520
ldflags.join (' ' ),
467
521
]
522
+ // add the compiled raylib libraries for each arch
523
+ if is_raylib {
524
+ build_cmd<< '-L ${os.join_path(vxt.vmodules()or{return error('$err_sig:vmodules folder not found')} ,' vab',' raylib',' build',arch)}'
525
+ }
468
526
469
527
jobs << job_util.ShellJob{
470
528
cmd: build_cmd
0 commit comments