-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add raylib support #235
Open
mohamedLT
wants to merge
4
commits into
vlang:master
Choose a base branch
from
mohamedLT:raylib
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add raylib support #235
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,6 +177,41 @@ pub fn compile_v_to_c(opt CompileOptions) !VMetaInfo { | |
return v_meta_dump | ||
} | ||
|
||
fn build_raylib(opt CompileOptions, raylib_path string, arch string) ! { | ||
build_path := os.join_path(raylib_path, 'build') | ||
// check if the library already exists or compile it | ||
if os.exists(os.join_path(build_path, arch, 'libraylib.a')) { | ||
return | ||
} else { | ||
src_path := os.join_path(raylib_path, 'src') | ||
ndk_path := ndk.root() | ||
os.execute('make -C ${src_path} clean') | ||
arch_name := if arch == 'arm64-v8a' { | ||
'arm64' | ||
} else if arch == 'armeabi-v7a' { | ||
'arm' | ||
} else if arch in ['x86', 'x86_64'] { | ||
arch | ||
} else { | ||
'' | ||
} | ||
if arch_name !in ['arm64', 'arm', 'x86', 'x86_64'] { | ||
return error('${arch_name} is now a known architecture') | ||
} | ||
os.execute('make -C ${src_path} PLATFORM=PLATFORM_ANDROID ANDROID_NDK=${ndk_path} ANDROID_ARCH=${arch_name} ANDROID_API_VERSION=${opt.api_level} ') | ||
taget_path := os.join_path(build_path, arch) | ||
os.mkdir_all(taget_path) or { return error('failed making directory "${taget_path}"') } | ||
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}') | ||
} | ||
} | ||
} | ||
|
||
fn download_raylib(raylib_path string) { | ||
// clone raylib from github | ||
os.execute('git clone https://github.com/raysan5/raylib.git ${raylib_path}') | ||
} | ||
|
||
pub fn compile(opt CompileOptions) ! { | ||
err_sig := @MOD + '.' + @FN | ||
os.mkdir_all(opt.work_dir) or { | ||
|
@@ -190,6 +225,30 @@ pub fn compile(opt CompileOptions) ! { | |
err: err.msg() | ||
}) | ||
} | ||
|
||
is_raylib := 'mohamedlt.vraylib' in v_meta_dump.imports | ||
|
||
// check if raylib floder is found else clone it | ||
if is_raylib { | ||
raylib_path := os.join_path(vxt.vmodules() or { | ||
return error('${err_sig}:vmodules folder not found') | ||
}, 'vab', 'raylib') | ||
if os.exists(raylib_path) { | ||
for arch in opt.archs { | ||
build_raylib(opt, raylib_path, arch) or { | ||
return error('cant build raylib ERROR: ${err}') | ||
} | ||
} | ||
} else { | ||
download_raylib(raylib_path) | ||
for arch in opt.archs { | ||
build_raylib(opt, raylib_path, arch) or { | ||
return error('cant build raylib ERROR: ${err}') | ||
} | ||
} | ||
} | ||
} | ||
|
||
v_cflags := v_meta_dump.c_flags | ||
imported_modules := v_meta_dump.imports | ||
|
||
|
@@ -325,6 +384,14 @@ pub fn compile(opt CompileOptions) ! { | |
|
||
is_debug_build := opt.is_debug_build() | ||
|
||
// add needed flags for raylib | ||
if is_raylib { | ||
ldflags << '-lEGL' | ||
ldflags << '-lGLESv2' | ||
ldflags << '-u ANativeActivity_onCreate' | ||
ldflags << '-lOpenSLES' | ||
} | ||
|
||
// Sokol sapp | ||
if 'sokol.sapp' in imported_modules { | ||
if opt.verbosity > 1 { | ||
|
@@ -453,14 +520,22 @@ pub fn compile(opt CompileOptions) ! { | |
arch_o_files := o_files[arch].map('"${it}"') | ||
arch_a_files := a_files[arch].map('"${it}"') | ||
|
||
build_cmd := [ | ||
mut build_cmd := [ | ||
arch_cc[arch], | ||
arch_o_files.join(' '), | ||
'-o "${arch_lib_dir}/lib${opt.lib_name}.so"', | ||
arch_a_files.join(' '), | ||
'-L"' + arch_libs[arch] + '"', | ||
ldflags.join(' '), | ||
] | ||
lflags := os.join_path(vxt.vmodules() or { | ||
return error('${err_sig}:vmodules folder not found') | ||
}, 'vab', 'raylib', 'build', arch) | ||
|
||
// add the compiled raylib libraries for each arch | ||
if is_raylib { | ||
build_cmd << '-L ${lflags}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe initialisation of 'lflags' for raylib would be nice put inside |
||
} | ||
|
||
jobs << job_util.ShellJob{ | ||
cmd: build_cmd | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be more eficient and nicer with
mach{...}
instead ofif ... else if ... else
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would look cleaner with
match
. Theelse
branch for the match would take care of the followingif
as well.