@@ -176,19 +176,63 @@ pub fn compile_v_to_c(opt CompileOptions) !VMetaInfo {
176176 return v_meta_dump
177177}
178178
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+
179203pub fn compile (opt CompileOptions) ! {
180204 err_sig := @MOD + '.' + @FN
181205 os.mkdir_all (opt.work_dir) or {
182206 return error ('$err_sig : failed making directory "$opt.work_dir ". $err ' )
183207 }
184208 build_dir := opt.build_directory ()!
185-
209+
186210 v_meta_dump := compile_v_to_c (opt) or {
187211 return IError (CompileError{
188212 kind: .v_to_c
189213 err: err.msg ()
190214 })
191215 }
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+
192236 v_cflags := v_meta_dump.c_flags
193237 imported_modules := v_meta_dump.imports
194238
@@ -329,6 +373,16 @@ pub fn compile(opt CompileOptions) ! {
329373
330374 is_debug_build := opt.is_debug_build ()
331375
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+
332386 // Sokol sapp
333387 if 'sokol.sapp' in imported_modules {
334388 if opt.verbosity > 1 {
@@ -457,14 +511,18 @@ pub fn compile(opt CompileOptions) ! {
457511 arch_o_files := o_files[arch].map ('"$it "' )
458512 arch_a_files := a_files[arch].map ('"$it "' )
459513
460- build_cmd := [
514+ mut build_cmd := [
461515 arch_cc[arch],
462516 arch_o_files.join (' ' ),
463517 '-o "$arch_lib_dir /lib${opt.lib_name} .so"' ,
464518 arch_a_files.join (' ' ),
465519 '-L"' + arch_libs[arch] + '"' ,
466520 ldflags.join (' ' ),
467521 ]
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+ }
468526
469527 jobs << job_util.ShellJob{
470528 cmd: build_cmd
0 commit comments