Convert build scripts to Python #31

Merged
MartinFouilleul merged 24 commits from build-python into main 2023-08-08 09:38:44 +00:00
12 changed files with 723 additions and 422 deletions
Showing only changes of commit d7bfb382e0 - Show all commits

View File

@ -28,36 +28,35 @@ if %target% == milepost (
if %target% == orca ( if %target% == orca (
echo building orca echo building orca
set pthread_dir=..\vcpkg\packages\pthreads_x64-windows
::copy libraries ::copy libraries
copy milepost\bin\milepost.dll bin copy milepost\bin\milepost.dll bin
copy milepost\bin\milepost.dll.lib bin copy milepost\bin\milepost.dll.lib bin
copy %pthread_dir%\bin\pthreadVC3.dll bin
::generate wasm3 api bindings ::generate wasm3 api bindings
python3 scripts\bindgen.py core src python3 scripts\bindgen.py core src\core_api.json^
--wasm3-bindings src\core_api_bind_gen.c
python3 scripts\bindgen.py gles src python3 scripts\bindgen.py gles src\gles_api.json^
--wasm3-bindings src\gles_api_bind_gen.c
python3 scripts\bindgen2.py canvas src\canvas_api.json^ python3 scripts\bindgen.py canvas src\canvas_api.json^
--guest-stubs sdk\orca_surface.c^ --guest-stubs sdk\orca_surface.c^
--guest-include graphics.h^ --guest-include graphics.h^
--wasm3-bindings src\canvas_api_bind_gen.c --wasm3-bindings src\canvas_api_bind_gen.c
python3 scripts\bindgen2.py clock src\clock_api.json^ python3 scripts\bindgen.py clock src\clock_api.json^
--guest-stubs sdk\orca_clock.c^ --guest-stubs sdk\orca_clock.c^
--guest-include platform_clock.h^ --guest-include platform_clock.h^
--wasm3-bindings src\clock_api_bind_gen.c --wasm3-bindings src\clock_api_bind_gen.c
python3 scripts\bindgen2.py io^ python3 scripts\bindgen.py io^
src\io_api.json^ src\io_api.json^
--guest-stubs sdk\io_stubs.c^ --guest-stubs sdk\io_stubs.c^
--wasm3-bindings src\io_api_bind_gen.c --wasm3-bindings src\io_api_bind_gen.c
::compile orca ::compile orca
set INCLUDES=/I src /I sdk /I ext\wasm3\source /I milepost\src /I milepost\ext /I %pthread_dir%\include set INCLUDES=/I src /I sdk /I ext\wasm3\source /I milepost\src /I milepost\ext
set LIBS=/LIBPATH:bin /LIBPATH:%pthread_dir%\lib milepost.dll.lib wasm3.lib pthreadVC3.lib set LIBS=/LIBPATH:bin milepost.dll.lib wasm3.lib
cl /Zi /Zc:preprocessor /std:c11 %INCLUDES% src\main.c /link %LIBS% /out:bin\orca.exe cl /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% src\main.c /link %LIBS% /out:bin\orca.exe
) )

View File

@ -58,22 +58,28 @@ elif [ $target = orca ] ; then
FLAGS="-g -DLOG_COMPILE_DEBUG -mmacos-version-min=10.15.4 -maes" FLAGS="-g -DLOG_COMPILE_DEBUG -mmacos-version-min=10.15.4 -maes"
# generate wasm3 api bindings # generate wasm3 api bindings
./scripts/bindgen.py core ./src
./scripts/bindgen.py gles ./src
python3 ./scripts/bindgen2.py canvas \ python3 ./scripts/bindgen.py core \
src/core_api.json \
--wasm3-bindings ./src/core_api_bind_gen.c
python3 ./scripts/bindgen.py gles \
src/gles_api.json \
--wasm3-bindings ./src/gles_api_bind_gen.c
python3 ./scripts/bindgen.py canvas \
src/canvas_api.json \ src/canvas_api.json \
--guest-stubs sdk/orca_surface.c \ --guest-stubs sdk/orca_surface.c \
--guest-include graphics.h \ --guest-include graphics.h \
--wasm3-bindings ./src/canvas_api_bind_gen.c --wasm3-bindings ./src/canvas_api_bind_gen.c
python3 ./scripts/bindgen2.py clock \ python3 ./scripts/bindgen.py clock \
src/clock_api.json \ src/clock_api.json \
--guest-stubs sdk/orca_clock.c \ --guest-stubs sdk/orca_clock.c \
--guest-include platform_clock.h \ --guest-include platform_clock.h \
--wasm3-bindings ./src/clock_api_bind_gen.c --wasm3-bindings ./src/clock_api_bind_gen.c
python3 ./scripts/bindgen2.py io \ python3 ./scripts/bindgen.py io \
src/io_api.json \ src/io_api.json \
--guest-stubs sdk/io_stubs.c \ --guest-stubs sdk/io_stubs.c \
--wasm3-bindings ./src/io_api_bind_gen.c --wasm3-bindings ./src/io_api_bind_gen.c

@ -1 +1 @@
Subproject commit 0caeccd3fba14e45f5666fa0f99fd719c9bef5fc Subproject commit 6221370aa0e8c520ebde179a1e715a8ed2e28611

View File

@ -1,135 +1,221 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys
def bindgen(apiName, cdir): from argparse import ArgumentParser
inPath = cdir + '/bindgen_' + apiName + '_api.txt' import json
outPath = cdir + '/bindgen_' + apiName + '_api.c'
inFile = open(inPath, 'r')
outFile = open(outPath, 'w')
stubs = [] def needs_arg_ptr_stub(decl):
links = [] res = (decl['ret']['tag'] == 'S')
for arg in decl['args']:
if arg['type']['tag'] == 'S':
res = True
return(res)
def gen_stub(name, sig, native_name):
if native_name == None:
native_name = name
src = 'const void* ' + name + '_stub(IM3Runtime runtime, IM3ImportContext _ctx, uint64_t * _sp, void * _mem)\n' def bindgen(apiName, spec, **kwargs):
src += '{\n' guest_stubs_path = kwargs.get("guest_stubs")
spIndex = 0 guest_include = kwargs.get("guest_include")
wasm3_bindings_path = kwargs.get("wasm3_bindings")
parsingRet = True if guest_stubs_path == None:
retCount = 0 guest_stubs_path = 'bindgen_' + apiName + '_guest_stubs.c'
argCount = 0 if wasm3_bindings_path == None:
retString = '' wasm3_bindings_path = 'bindgen_' + apiName + '_wasm3_bindings.c'
argString = ''
for index, c in enumerate(sig): host_bindings = open(wasm3_bindings_path, 'w')
if parsingRet: guest_bindings = None
if retCount > 1:
print('unsupported multiple return types\n') specFile = open(spec, 'r')
break data = json.load(specFile)
if c == '(':
parsingRet = False for decl in data:
continue if needs_arg_ptr_stub(decl):
elif c == ')': guest_bindings = open(guest_stubs_path, 'w')
print('unexpected ) while parsing return type\n') if guest_include != None:
break; s = '#include"' + guest_include + '"\n\n'
elif c == 'v': print(s, file=guest_bindings)
continue
elif c == 'i':
retString = '*((i32*)&_sp[0]) = '
elif c == 'I':
retString = '*((i64*)&_sp[0]) = '
elif c == 'f':
retString = '*((f32*)&_sp[0]) = '
elif c == 'F':
retString = '*((f64*)&_sp[0]) = '
elif c == 'p':
print('returning pointers is not supported yet\n')
break break
for decl in data:
name = decl['name']
cname = decl.get('cname', name)
if needs_arg_ptr_stub(decl):
argPtrStubName = name + '_argptr_stub'
# pointer arg stub declaration
s = ''
if decl['ret']['tag'] == 'S':
s += 'void'
else: else:
print('unrecognized type ' + c + ' in procedure return\n') s += decl['ret']['name']
break
retCount += 1 s += ' ORCA_IMPORT(' + argPtrStubName + ') ('
if decl['ret']['tag'] == 'S':
s += decl['ret']['name'] + '* __retArg'
if len(decl['args']) > 0:
s += ', '
for i, arg in enumerate(decl['args']):
s += arg['type']['name']
if arg['type']['tag'] == 'S':
s += '*'
s += ' ' + arg['name']
if i+1 < len(decl['args']):
s += ', '
s += ');\n\n'
# forward function to pointer arg stub declaration
s += decl['ret']['name'] + ' ' + name + '('
for i, arg in enumerate(decl['args']):
s += arg['type']['name'] + ' ' + arg['name']
if i+1 < len(decl['args']):
s += ', '
s += ')\n'
s += '{\n'
s += '\t'
if decl['ret']['tag'] == 'S':
s += decl['ret']['name'] + ' __ret;\n\t'
elif decl['ret']['tag'] != 'v':
s += decl['ret']['name']
s += ' __ret = '
s += argPtrStubName + '('
if decl['ret']['tag'] == 'S':
s += '&__ret'
if len(decl['args']) > 0:
s += ', '
for i, arg in enumerate(decl['args']):
if arg['type']['tag'] == 'S':
s += '&'
s += arg['name']
if i+1 < len(decl['args']):
s += ', '
s += ');\n'
if decl['ret']['tag'] != 'v':
s += '\treturn(__ret);\n'
s += '}\n\n'
print(s, file=guest_bindings)
# host-side stub
s = 'const void* ' + cname + '_stub(IM3Runtime runtime, IM3ImportContext _ctx, uint64_t* _sp, void* _mem)'
gen_stub = decl.get('gen_stub', True)
if gen_stub == False:
s += ';\n\n'
else: else:
argIndex = argCount + retCount s += '\n{\n\t'
if c == ')': retTag = decl['ret']['tag']
break
elif c == 'v': if retTag == 'i':
break s += '*((i32*)&_sp[0]) = '
elif c == 'i': elif retTag == 'I':
argString += '*(i32*)&_sp[' + str(argIndex) + ']' s += '*((i64*)&_sp[0]) = '
elif c == 'I': elif retTag == 'f':
argString += '*(i64*)&_sp[' + str(argIndex) + ']' s += '*((f32*)&_sp[0]) = '
elif c == 'f': elif retTag == 'F':
argString += '*(f32*)&_sp[' + str(argIndex) + ']' s += '*((f64*)&_sp[0]) = '
elif c == 'F': elif retTag == 'S':
argString += '*(f64*)&_sp[' + str(argIndex) + ']' retTypeName = decl['ret']['name']
elif c == 'p': retTypeCName = decl['ret'].get('cname', retTypeName)
argString += '(void*)((char*)_mem + *(i32*)&_sp[' + str(argIndex) + '])' s += '*(' + retTypeCName + '*)((char*)_mem + *(i32*)&_sp[0]) = '
s += cname + '('
firstArgIndex = 0
if retTag != 'v':
firstArgIndex = 1
for i, arg in enumerate(decl['args']):
typeName = arg['type']['name']
typeCName = arg['type'].get('cname', typeName)
argTag = arg['type']['tag']
if argTag == 'i':
s += '*(i32*)&_sp[' + str(firstArgIndex + i) + ']'
elif argTag == 'I':
s += '*(i64*)&_sp[' + str(firstArgIndex + i) + ']'
elif argTag == 'f':
s += '*(f32*)&_sp[' + str(firstArgIndex + i) + ']'
elif argTag == 'F':
s += '*(f64*)&_sp[' + str(firstArgIndex + i) + ']'
elif argTag == 'p':
s += '(void*)((char*)_mem + *(i32*)&_sp[' + str(firstArgIndex + i) + '])'
elif argTag == 'S':
s += '*(' + typeCName + '*)((char*)_mem + *(i32*)&_sp[' + str(firstArgIndex + i) + '])'
else: else:
print('unrecognized type ' + c + ' in procedure signature\n') print('unrecognized type ' + c + ' in procedure signature\n')
break break
if index+2 < len(sig): if i+1 < len(decl['args']):
argString += ', ' s += ', '
argCount += 1
src += '\t' + retString + native_name + '(' + argString + ');\n' s += ');\n\treturn(0);\n}\n\n'
src += '\treturn(0);\n'
src += '}\n'
stubs.append(src)
def gen_link(name, sig): print(s, file=host_bindings)
m3_Sig = ''
for c in sig: # link function
if c == 'p': s = 'int bindgen_link_' + apiName + '_api(IM3Module module)\n{\n\t'
m3_Sig += 'i' s += 'M3Result res;\n'
for decl in data:
name = decl['name']
cname = decl.get('cname', name)
if needs_arg_ptr_stub(decl):
name = name + '_argptr_stub'
m3Sig = ''
if decl['ret']['tag'] == 'S':
m3Sig += 'v'
else: else:
m3_Sig += c m3Sig += decl['ret']['tag']
src = '\tres = m3_LinkRawFunction(module, "*", "' + name + '", "' + m3_Sig + '", ' + name + '_stub);\n' m3Sig += '('
src += '\tif(res != m3Err_none && res != m3Err_functionLookupFailed) { log_error("error: %s\\n", res); return(-1); }\n\n' if decl['ret']['tag'] == 'S':
links.append(src) m3Sig += 'i'
for arg in decl['args']:
tag = arg['type']['tag']
if tag == 'p' or tag == 'S':
tag = 'i'
m3Sig += tag
m3Sig += ')'
for line in inFile:
if line.isspace():
continue
desc = line.split()
gen_stub(desc[0], desc[1], desc[2] if len(desc) > 2 else None) s += '\tres = m3_LinkRawFunction(module, "*", "' + name + '", "' + m3Sig + '", ' + cname + '_stub);\n'
gen_link(desc[0], desc[1]) s += '\tif(res != m3Err_none && res != m3Err_functionLookupFailed) { log_error("error: %s\\n", res); return(-1); }\n\n'
linkProc = 'int bindgen_link_' + apiName + '_api(IM3Module module)\n'
linkProc += '{\n'
linkProc += '\tM3Result res;\n'
for link in links: s += '\treturn(0);\n}\n'
linkProc += link
linkProc += '\treturn(0);\n' print(s, file=host_bindings)
linkProc += '}\n'
for stub in stubs:
outFile.write(stub)
outFile.write('\n')
outFile.write(linkProc)
inFile.close()
outFile.close()
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) < 2: parser = ArgumentParser(prog='bindgen.py')
print("bindgen require an api name\n") parser.add_argument('api')
exit(-1) parser.add_argument('spec')
parser.add_argument('-g', '--guest-stubs')
parser.add_argument('--guest-include')
parser.add_argument('--wasm3-bindings')
apiName = sys.argv[1] args = parser.parse_args()
cdir = ''
if len(sys.argv) > 2: apiName = args.api
cdir = sys.argv[2] spec = args.spec
guest_stubs_path = args.guest_stubs
if guest_stubs_path == None:
guest_stubs_path = 'bindgen_' + apiName + '_guest_stubs.c'
bindgen(apiName, cdir) wasm3_bindings_path = args.wasm3_bindings
if wasm3_bindings_path == None:
wasm3_bindings_path = 'bindgen_' + apiName + '_wasm3_bindings.c'
bindgen(apiName, spec,
guest_stubs=guest_stubs_path,
guest_include=args.guest_include,
wasm3_bindings=wasm3_bindings_path,
)

View File

@ -1,214 +0,0 @@
#!/usr/bin/env python3
from argparse import ArgumentParser
import json
def needs_arg_ptr_stub(decl):
res = (decl['ret']['tag'] == 'S')
for arg in decl['args']:
if arg['type']['tag'] == 'S':
res = True
return(res)
def bindgen2(apiName, spec, **kwargs):
guest_stubs_path = kwargs["guest_stubs"]
guest_include = kwargs.get("guest-include")
wasm3_bindings_path = kwargs["wasm3_bindings"]
host_bindings = open(wasm3_bindings_path, 'w')
guest_bindings = None
specFile = open(spec, 'r')
data = json.load(specFile)
for decl in data:
if needs_arg_ptr_stub(decl):
guest_bindings = open(guest_stubs_path, 'w')
if guest_include != None:
s = '#include"' + guest_include + '"\n\n'
print(s, file=guest_bindings)
break
for decl in data:
name = decl['name']
cname = decl.get('cname', name)
if needs_arg_ptr_stub(decl):
argPtrStubName = name + '_argptr_stub'
# pointer arg stub declaration
s = ''
if decl['ret']['tag'] == 'S':
s += 'void'
else:
s += decl['ret']['name']
s += ' ORCA_IMPORT(' + argPtrStubName + ') ('
if decl['ret']['tag'] == 'S':
s += decl['ret']['name'] + '* __retArg'
if len(decl['args']) > 0:
s += ', '
for i, arg in enumerate(decl['args']):
s += arg['type']['name']
if arg['type']['tag'] == 'S':
s += '*'
s += ' ' + arg['name']
if i+1 < len(decl['args']):
s += ', '
s += ');\n\n'
# forward function to pointer arg stub declaration
s += decl['ret']['name'] + ' ' + name + '('
for i, arg in enumerate(decl['args']):
s += arg['type']['name'] + ' ' + arg['name']
if i+1 < len(decl['args']):
s += ', '
s += ')\n'
s += '{\n'
s += '\t'
if decl['ret']['tag'] == 'S':
s += decl['ret']['name'] + ' __ret;\n\t'
elif decl['ret']['tag'] != 'v':
s += decl['ret']['name']
s += ' __ret = '
s += argPtrStubName + '('
if decl['ret']['tag'] == 'S':
s += '&__ret'
if len(decl['args']) > 0:
s += ', '
for i, arg in enumerate(decl['args']):
if arg['type']['tag'] == 'S':
s += '&'
s += arg['name']
if i+1 < len(decl['args']):
s += ', '
s += ');\n'
if decl['ret']['tag'] != 'v':
s += '\treturn(__ret);\n'
s += '}\n\n'
print(s, file=guest_bindings)
# host-side stub
s = 'const void* ' + cname + '_stub(IM3Runtime runtime, IM3ImportContext _ctx, uint64_t* _sp, void* _mem)'
gen_stub = decl.get('gen_stub', True)
if gen_stub == False:
s += ';\n\n'
else:
s += '\n{\n\t'
retTag = decl['ret']['tag']
if retTag == 'i':
s += '*((i32*)&_sp[0]) = '
elif retTag == 'I':
s += '*((i64*)&_sp[0]) = '
elif retTag == 'f':
s += '*((f32*)&_sp[0]) = '
elif retTag == 'F':
s += '*((f64*)&_sp[0]) = '
elif retTag == 'S':
retTypeName = decl['ret']['name']
retTypeCName = decl['ret'].get('cname', retTypeName)
s += '*(' + retTypeCName + '*)((char*)_mem + *(i32*)&_sp[0]) = '
s += cname + '('
firstArgIndex = 0
if retTag != 'v':
firstArgIndex = 1
for i, arg in enumerate(decl['args']):
typeName = arg['type']['name']
typeCName = arg['type'].get('cname', typeName)
argTag = arg['type']['tag']
if argTag == 'i':
s += '*(i32*)&_sp[' + str(firstArgIndex + i) + ']'
elif argTag == 'I':
s += '*(i64*)&_sp[' + str(firstArgIndex + i) + ']'
elif argTag == 'f':
s += '*(f32*)&_sp[' + str(firstArgIndex + i) + ']'
elif argTag == 'F':
s += '*(f64*)&_sp[' + str(firstArgIndex + i) + ']'
elif argTag == 'p':
s += '(void*)((char*)_mem + *(i32*)&_sp[' + str(firstArgIndex + i) + '])'
elif argTag == 'S':
s += '*(' + typeCName + '*)((char*)_mem + *(i32*)&_sp[' + str(firstArgIndex + i) + '])'
else:
print('unrecognized type ' + c + ' in procedure signature\n')
break
if i+1 < len(decl['args']):
s += ', '
s += ');\n\treturn(0);\n}\n\n'
print(s, file=host_bindings)
# link function
s = 'int bindgen_link_' + apiName + '_api(IM3Module module)\n{\n\t'
s += 'M3Result res;\n'
for decl in data:
name = decl['name']
cname = decl.get('cname', name)
if needs_arg_ptr_stub(decl):
name = name + '_argptr_stub'
m3Sig = ''
if decl['ret']['tag'] == 'S':
m3Sig += 'v'
else:
m3Sig += decl['ret']['tag']
m3Sig += '('
if decl['ret']['tag'] == 'S':
m3Sig += 'i'
for arg in decl['args']:
tag = arg['type']['tag']
if tag == 'p' or tag == 'S':
tag = 'i'
m3Sig += tag
m3Sig += ')'
s += '\tres = m3_LinkRawFunction(module, "*", "' + name + '", "' + m3Sig + '", ' + cname + '_stub);\n'
s += '\tif(res != m3Err_none && res != m3Err_functionLookupFailed) { log_error("error: %s\\n", res); return(-1); }\n\n'
s += '\treturn(0);\n}\n'
print(s, file=host_bindings)
if __name__ == "__main__":
parser = ArgumentParser(prog='bindgen.py')
parser.add_argument('api')
parser.add_argument('spec')
parser.add_argument('-g', '--guest-stubs')
parser.add_argument('--guest-include')
parser.add_argument('--wasm3-bindings')
args = parser.parse_args()
apiName = args.api
spec = args.spec
guest_stubs_path = args.guest_stubs
if guest_stubs_path == None:
guest_stubs_path = 'bindgen_' + apiName + '_guest_stubs.c'
wasm3_bindings_path = args.wasm3_bindings
if wasm3_bindings_path == None:
wasm3_bindings_path = 'bindgen_' + apiName + '_wasm3_bindings.c'
bindgen2(apiName, spec,
guest_stubs_path=guest_stubs_path,
guest_include=args.guest_include,
wasm3_bindings_path=wasm3_bindings_path,
)

View File

@ -207,13 +207,11 @@ def windows_make_app(args):
milepost_lib = args.orca_dir + '/build/bin/milepost.dll' milepost_lib = args.orca_dir + '/build/bin/milepost.dll'
gles_lib = args.orca_dir + '/milepost/build/bin/libGLESv2.dll' gles_lib = args.orca_dir + '/milepost/build/bin/libGLESv2.dll'
egl_lib = args.orca_dir + '/milepost/build/bin/libEGL.dll' egl_lib = args.orca_dir + '/milepost/build/bin/libEGL.dll'
pthread_lib = args.orca_dir + '/build/bin/pthreadVC3.dll'
shutil.copy(orca_exe, exe_dir) shutil.copy(orca_exe, exe_dir)
shutil.copy(milepost_lib, exe_dir) shutil.copy(milepost_lib, exe_dir)
shutil.copy(gles_lib, exe_dir) shutil.copy(gles_lib, exe_dir)
shutil.copy(egl_lib, exe_dir) shutil.copy(egl_lib, exe_dir)
shutil.copy(pthread_lib, exe_dir)
#----------------------------------------------------------- #-----------------------------------------------------------
#NOTE: copy wasm module and data #NOTE: copy wasm module and data
@ -248,8 +246,10 @@ def windows_make_app(args):
#----------------------------------------------------------- #-----------------------------------------------------------
#TODO #TODO
if __name__ == "__main__": if __name__ == "__main__":
parser = ArgumentParser(prog='mkapp') parser = ArgumentParser(prog='mkapp')
init_parser(parser) init_parser(parser)
args = parser.parse_args() args = parser.parse_args()
make_app(args)

View File

@ -10,7 +10,6 @@ from zipfile import ZipFile
from . import checksum from . import checksum
from .bindgen import bindgen from .bindgen import bindgen
from .bindgen2 import bindgen2
from .log import * from .log import *
from .utils import pushd, removeall from .utils import pushd, removeall
@ -109,6 +108,7 @@ def build_milepost_lib_win(release):
"src\\glsl_shaders\\backprop.glsl", "src\\glsl_shaders\\backprop.glsl",
"src\\glsl_shaders\\merge.glsl", "src\\glsl_shaders\\merge.glsl",
"src\\glsl_shaders\\raster.glsl", "src\\glsl_shaders\\raster.glsl",
"src\\glsl_shaders\\balance_workgroups.glsl",
]) ])
includes = [ includes = [
@ -140,7 +140,7 @@ def build_milepost_lib_win(release):
"cl", "cl",
"/we4013", "/Zi", "/Zc:preprocessor", "/we4013", "/Zi", "/Zc:preprocessor",
"/DMP_BUILD_DLL", "/DMP_BUILD_DLL",
"/std:c11", "/std:c11", "/experimental:c11atomics",
*includes, *includes,
"src/milepost.c", "/Fo:bin/milepost.o", "src/milepost.c", "/Fo:bin/milepost.o",
"/LD", "/link", "/LD", "/link",
@ -293,37 +293,30 @@ def build_orca(release):
def build_orca_win(release): def build_orca_win(release):
pthread_dir = "..\\vcpkg\\packages\\pthreads_x64-windows"
# copy libraries # copy libraries
shutil.copy("milepost\\bin\\milepost.dll", "bin") shutil.copy("milepost\\bin\\milepost.dll", "bin")
shutil.copy("milepost\\bin\\milepost.dll.lib", "bin") shutil.copy("milepost\\bin\\milepost.dll.lib", "bin")
shutil.copy(os.path.join(pthread_dir, "bin\\pthreadVC3.dll"), "bin")
gen_all_bindings() gen_all_bindings()
# compile orca # compile orca
pthread_include = os.path.join(pthread_dir, "include")
includes = [ includes = [
"/I", "src", "/I", "src",
"/I", "sdk", "/I", "sdk",
"/I", "ext\wasm3\source", "/I", "ext\wasm3\source",
"/I", "milepost\src", "/I", "milepost\src",
"/I", "milepost\ext", "/I", "milepost\ext",
"/I", pthread_include,
] ]
pthread_lib = os.path.join(pthread_dir, "lib")
libs = [ libs = [
"/LIBPATH:bin", "/LIBPATH:bin",
f"/LIBPATH:{pthread_lib}",
"milepost.dll.lib", "milepost.dll.lib",
"wasm3.lib", "wasm3.lib",
"pthreadVC3.lib",
] ]
subprocess.run([ subprocess.run([
"cl", "cl",
"/Zi", "/Zc:preprocessor", "/std:c11", "/Zi", "/Zc:preprocessor",
"/std:c11", "/experimental:c11atomics",
*includes, *includes,
"src\\main.c", "src\\main.c",
"/link", *libs, "/link", *libs,
@ -378,20 +371,24 @@ def build_orca_mac(release):
def gen_all_bindings(): def gen_all_bindings():
bindgen("core", "src") bindgen("core", "src/core_api.json",
bindgen("gles", "src") wasm3_bindings="src/core_api_bind_gen.c",
)
bindgen("gles", "src/gles_api.json",
wasm3_bindings="src/gles_api_bind_gen.c",
)
bindgen2("canvas", "src/canvas_api.json", bindgen("canvas", "src/canvas_api.json",
guest_stubs="sdk/orca_surface.c", guest_stubs="sdk/orca_surface.c",
guest_include="graphics.h", guest_include="graphics.h",
wasm3_bindings="src/canvas_api_bind_gen.c", wasm3_bindings="src/canvas_api_bind_gen.c",
) )
bindgen2("clock", "src/clock_api.json", bindgen("clock", "src/clock_api.json",
guest_stubs="sdk/orca_clock.c", guest_stubs="sdk/orca_clock.c",
guest_include="platform_clock.h", guest_include="platform_clock.h",
wasm3_bindings="src/clock_api_bind_gen.c", wasm3_bindings="src/clock_api_bind_gen.c",
) )
bindgen2("io", "src/io_api.json", bindgen("io", "src/io_api.json",
guest_stubs="sdk/io_stubs.c", guest_stubs="sdk/io_stubs.c",
wasm3_bindings="src/io_api_bind_gen.c", wasm3_bindings="src/io_api_bind_gen.c",
) )

View File

@ -1,12 +0,0 @@
cosf f(f)
sinf f(f)
floorf f(f)
sqrtf f(f)
cos F(F)
sin F(F)
sqrt F(F)
fabs F(F)
orca_log v(iipipiip)
orca_mem_grow i(I)
orca_assert i(ppipp)

View File

@ -1,44 +0,0 @@
glCreateProgram i(v)
glCreateShader i(i)
glCompileShader v(i)
glAttachShader v(ii)
glLinkProgram v(i)
glUseProgram v(i)
glGetError i(v)
glClearColor v(ffff)
glClear v(i)
glViewport v(iiii)
glGetShaderiv v(iip)
glGetShaderInfoLog v(iipp)
glBindFramebuffer v(ii)
glBindTexture v(ii)
glActiveTexture v(i)
glGenBuffers v(ip)
glGenTextures v(ip)
glGenFramebuffers v(ip)
glFramebufferTexture2D v(iiiii)
glCheckFramebufferStatus i(i)
glTexImage2D v(iiiiiiiip)
glTexParameteri v(iii)
glBindBuffer v(ii)
glBufferData v(iipi)
glUniform1i v(ii)
glUniform2i v(iii)
glUniform1f v(if)
glUniform2f v(iff)
glUniform3f v(ifff)
glUniformMatrix4fv v(iiip)
glGetAttribLocation i(ip)
glGetUniformLocation i(ip)
glVertexAttribPointer v(iiiiip)
glEnableVertexAttribArray v(i)
glDrawArrays v(iii)

103
src/core_api.json Normal file
View File

@ -0,0 +1,103 @@
[
{
"name": "cosf",
"cname": "cosf",
"ret": {"name": "float", "tag": "f"},
"args": [ {"name": "x",
"type": {"name": "float", "tag": "f"}}]
},
{
"name": "sinf",
"cname": "sinf",
"ret": {"name": "float", "tag": "f"},
"args": [ {"name": "x",
"type": {"name": "float", "tag": "f"}}]
},
{
"name": "floorf",
"cname": "floorf",
"ret": {"name": "float", "tag": "f"},
"args": [ {"name": "x",
"type": {"name": "float", "tag": "f"}}]
},
{
"name": "sqrtf",
"cname": "sqrtf",
"ret": {"name": "float", "tag": "f"},
"args": [ {"name": "x",
"type": {"name": "float", "tag": "f"}}]
},
{
"name": "cos",
"cname": "cos",
"ret": {"name": "double", "tag": "F"},
"args": [ {"name": "x",
"type": {"name": "double", "tag": "F"}}]
},
{
"name": "sin",
"cname": "sin",
"ret": {"name": "double", "tag": "F"},
"args": [ {"name": "x",
"type": {"name": "double", "tag": "F"}}]
},
{
"name": "sqrt",
"cname": "sqrt",
"ret": {"name": "double", "tag": "F"},
"args": [ {"name": "x",
"type": {"name": "double", "tag": "F"}}]
},
{
"name": "fabs",
"cname": "fabs",
"ret": {"name": "double", "tag": "F"},
"args": [ {"name": "x",
"type": {"name": "double", "tag": "F"}}]
},
{
"name": "orca_log",
"cname": "orca_log",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "level",
"type": {"name": "log_level", "tag": "i"}},
{"name": "fileLen",
"type": {"name": "int", "tag": "i"}},
{"name": "file",
"type": {"name": "char*", "tag": "p"}},
{"name": "functionLen",
"type": {"name": "int", "tag": "i"}},
{"name": "function",
"type": {"name": "char*", "tag": "p"}},
{"name": "line",
"type": {"name": "int", "tag": "i"}},
{"name": "msgLen",
"type": {"name": "int", "tag": "i"}},
{"name": "msg",
"type": {"name": "char*", "tag": "p"}}
]
},
{
"name": "orca_mem_grow",
"cname": "orca_mem_grow",
"ret": {"name": "int", "tag": "i"},
"args": [ {"name": "size",
"type": {"name": "u64", "tag": "I"}}]
},
{
"name": "orca_assert",
"cname": "orca_assert",
"ret": {"name": "int", "tag": "i"},
"args": [ {"name": "file",
"type": {"name": "const char*", "tag": "p"}},
{"name": "function",
"type": {"name": "const char*", "tag": "p"}},
{"name": "line",
"type": {"name": "int", "tag": "i"}},
{"name": "src",
"type": {"name": "const char*", "tag": "p"}},
{"name": "note",
"type": {"name": "const char*", "tag": "p"}}
]
}
]

383
src/gles_api.json Normal file
View File

@ -0,0 +1,383 @@
[
{
"name": "glCreateProgram",
"cname": "glCreateProgram",
"ret": {"name": "int", "tag": "i"},
"args": []
},
{
"name": "glCreateShader",
"cname": "glCreateShader",
"ret": {"name": "int", "tag": "i"},
"args": [ {"name": "shaderType",
"type": {"name": "GLenum", "tag": "i"}}]
},
{
"name": "glCompileShader",
"cname": "glCompileShader",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "shader",
"type": {"name": "GLuint", "tag": "i"}}]
},
{
"name": "glAttachShader",
"cname": "glAttachShader",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "program",
"type": {"name": "GLuint", "tag": "i"}},
{"name": "shader",
"type": {"name": "GLuint", "tag": "i"}}
]
},
{
"name": "glLinkProgram",
"cname": "glLinkProgram",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "program",
"type": {"name": "GLuint", "tag": "i"}}]
},
{
"name": "glUseProgram",
"cname": "glUseProgram",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "program",
"type": {"name": "GLuint", "tag": "i"}}]
},
{
"name": "glGetError",
"cname": "glGetError",
"ret": {"name": "GLenum", "tag": "i"},
"args": []
},
{
"name": "glClearColor",
"cname": "glClearColor",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "red",
"type": {"name": "GLfloat", "tag": "f"}},
{"name": "green",
"type": {"name": "GLfloat", "tag": "f"}},
{"name": "blue",
"type": {"name": "GLfloat", "tag": "f"}},
{"name": "alpha",
"type": {"name": "GLfloat", "tag": "f"}}
]
},
{
"name": "glClear",
"cname": "glClear",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "mask",
"type": {"name": "GLbitfield", "tag": "i"}}]
},
{
"name": "glViewport",
"cname": "glViewport",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "x",
"type": {"name": "GLint", "tag": "i"}},
{"name": "y",
"type": {"name": "GLint", "tag": "i"}},
{"name": "width",
"type": {"name": "GLsizei", "tag": "i"}},
{"name": "height",
"type": {"name": "GLsizei", "tag": "i"}}
]
},
{
"name": "glGetShaderiv",
"cname": "glGetShaderiv",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "shader",
"type": {"name": "GLuint", "tag": "i"}},
{"name": "pname",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "params",
"type": {"name": "GLint*", "tag": "p"}}
]
},
{
"name": "glGetShaderInfoLog",
"cname": "glGetShaderInfoLog",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "shader",
"type": {"name": "GLuint", "tag": "i"}},
{"name": "maxLength",
"type": {"name": "GLsizei", "tag": "i"}},
{"name": "length",
"type": {"name": "GLsizei", "tag": "p"}},
{"name": "infoLog",
"type": {"name": "GLchar", "tag": "p"}}
]
},
{
"name": "glBindFramebuffer",
"cname": "glBindFramebuffer",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "target",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "framebuffer",
"type": {"name": "GLuint", "tag": "i"}}
]
},
{
"name": "glBindTexture",
"cname": "glBindTexture",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "target",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "texture",
"type": {"name": "GLuint", "tag": "i"}}
]
},
{
"name": "glActiveTexture",
"cname": "glActiveTexture",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "texture",
"type": {"name": "GLuint", "tag": "i"}}]
},
{
"name": "glGenBuffers",
"cname": "glGenBuffers",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "n",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "buffers",
"type": {"name": "GLuint*", "tag": "p"}}
]
},
{
"name": "glGenTextures",
"cname": "glGenTextures",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "n",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "textures",
"type": {"name": "GLuint*", "tag": "p"}}
]
},
{
"name": "glGenFramebuffers",
"cname": "glGenFramebuffers",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "n",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "framebuffers",
"type": {"name": "GLuint*", "tag": "p"}}
]
},
{
"name": "glFramebufferTexture2D",
"cname": "glFramebufferTexture2D",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "target",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "attachment",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "textarget",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "texture",
"type": {"name": "GLuint", "tag": "i"}},
{"name": "level",
"type": {"name": "GLint", "tag": "i"}}
]
},
{
"name": "glCheckFramebufferStatus",
"cname": "glCheckFramebufferStatus",
"ret": {"name": "GLenum", "tag": "i"},
"args": [ {"name": "target",
"type": {"name": "GLenum", "tag": "i"}}]
},
{
"name": "glTexImage2D",
"cname": "glTexImage2D",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "target",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "level",
"type": {"name": "GLint", "tag": "i"}},
{"name": "internalformat",
"type": {"name": "GLint", "tag": "i"}},
{"name": "width",
"type": {"name": "GLsizei", "tag": "i"}},
{"name": "height",
"type": {"name": "GLsizei", "tag": "i"}},
{"name": "border",
"type": {"name": "GLint", "tag": "i"}},
{"name": "format",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "type",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "data",
"type": {"name": "void*", "tag": "p"}}
]
},
{
"name": "glTexParameteri",
"cname": "glTexParameteri",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "target",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "pname",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "param",
"type": {"name": "GLint", "tag": "i"}}
]
},
{
"name": "glBindBuffer",
"cname": "glBindBuffer",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "target",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "buffer",
"type": {"name": "GLuint", "tag": "i"}}
]
},
{
"name": "glBufferData",
"cname": "glBufferData",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "target",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "size",
"type": {"name": "GLsizeiptr", "tag": "i"}},
{"name": "data",
"type": {"name": "void*", "tag": "p"}},
{"name": "usage",
"type": {"name": "GLenum", "tag": "i"}}
]
},
{
"name": "glUniform1i",
"cname": "glUniform1i",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "location",
"type": {"name": "GLint", "tag": "i"}},
{"name": "v0",
"type": {"name": "GLint", "tag": "i"}}
]
},
{
"name": "glUniform2i",
"cname": "glUniform2i",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "location",
"type": {"name": "GLint", "tag": "i"}},
{"name": "v0",
"type": {"name": "GLint", "tag": "i"}},
{"name": "v1",
"type": {"name": "GLint", "tag": "i"}}
]
},
{
"name": "glUniform1f",
"cname": "glUniform1f",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "location",
"type": {"name": "GLint", "tag": "i"}},
{"name": "v0",
"type": {"name": "GLfloat", "tag": "f"}}
]
},
{
"name": "glUniform2f",
"cname": "glUniform2f",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "location",
"type": {"name": "GLint", "tag": "i"}},
{"name": "v0",
"type": {"name": "GLfloat", "tag": "f"}},
{"name": "v1",
"type": {"name": "GLfloat", "tag": "f"}}
]
},
{
"name": "glUniform3f",
"cname": "glUniform3f",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "location",
"type": {"name": "GLint", "tag": "i"}},
{"name": "v0",
"type": {"name": "GLfloat", "tag": "f"}},
{"name": "v1",
"type": {"name": "GLfloat", "tag": "f"}},
{"name": "v2",
"type": {"name": "GLfloat", "tag": "f"}}
]
},
{
"name": "glUniformMatrix4fv",
"cname": "glUniformMatrix4fv",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "location",
"type": {"name": "GLint", "tag": "i"}},
{"name": "count",
"type": {"name": "GLsizei", "tag": "i"}},
{"name": "transpose",
"type": {"name": "GLboolean", "tag": "i"}},
{"name": "value",
"type": {"name": "GLfloat*", "tag": "p"}}
]
},
{
"name": "glGetAttribLocation",
"cname": "glGetAttribLocation",
"ret": {"name": "GLint", "tag": "i"},
"args": [ {"name": "program",
"type": {"name": "GLuint", "tag": "i"}},
{"name": "name",
"type": {"name": "GLchar*", "tag": "p"}}
]
},
{
"name": "glGetUniformLocation",
"cname": "glGetUniformLocation",
"ret": {"name": "GLint", "tag": "i"},
"args": [ {"name": "program",
"type": {"name": "GLuint", "tag": "i"}},
{"name": "name",
"type": {"name": "GLchar*", "tag": "p"}}
]
},
{
"name": "glVertexAttribPointer",
"cname": "glVertexAttribPointer",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "index",
"type": {"name": "GLuint", "tag": "i"}},
{"name": "size",
"type": {"name": "GLint", "tag": "i"}},
{"name": "type",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "normalized",
"type": {"name": "GLboolean", "tag": "i"}},
{"name": "stride",
"type": {"name": "GLsizei", "tag": "i"}},
{"name": "pointer",
"type": {"name": "void*", "tag": "p"}}
]
},
{
"name": "glEnableVertexAttribArray",
"cname": "glEnableVertexAttribArray",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "index",
"type": {"name": "GLuint", "tag": "i"}}]
},
{
"name": "glDrawArrays",
"cname": "glDrawArrays",
"ret": {"name": "void", "tag": "v"},
"args": [ {"name": "mode",
"type": {"name": "GLenum", "tag": "i"}},
{"name": "first",
"type": {"name": "GLint", "tag": "i"}},
{"name": "count",
"type": {"name": "GLsizei", "tag": "i"}}
]
}
]

View File

@ -7,7 +7,6 @@
*****************************************************************/ *****************************************************************/
#include<stdio.h> #include<stdio.h>
#include<errno.h> #include<errno.h>
#include<pthread.h>
#include<math.h> #include<math.h>
#define MG_INCLUDE_GL_API #define MG_INCLUDE_GL_API
@ -298,15 +297,15 @@ void orca_runtime_init(orca_runtime* runtime)
runtime->wasmMemory.ptr = mem_base_reserve(allocator, runtime->wasmMemory.reserved); runtime->wasmMemory.ptr = mem_base_reserve(allocator, runtime->wasmMemory.reserved);
} }
#include"bindgen_core_api.c" #include"core_api_bind_gen.c"
#include"canvas_api_bind.c" #include"canvas_api_bind.c"
#include"clock_api_bind_gen.c" #include"clock_api_bind_gen.c"
#include"io_api_bind_gen.c" #include"io_api_bind_gen.c"
#include"bindgen_gles_api.c" #include"gles_api_bind_gen.c"
#include"manual_gles_api.c" #include"manual_gles_api.c"
void* orca_runloop(void* user) i32 orca_runloop(void* user)
{ {
orca_app* app = &__orcaApp; orca_app* app = &__orcaApp;
@ -328,7 +327,7 @@ void* orca_runloop(void* user)
options); options);
mp_request_quit(); mp_request_quit();
return((void*)-1); return(-1);
} }
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
@ -378,7 +377,7 @@ void* orca_runloop(void* user)
options); options);
mp_request_quit(); mp_request_quit();
return((void*)-1); return(-1);
} }
//NOTE: Find and type check event handlers. //NOTE: Find and type check event handlers.
@ -473,7 +472,7 @@ void* orca_runloop(void* user)
options); options);
mp_request_quit(); mp_request_quit();
return((void*)-1); return(-1);
} }
} }
@ -803,8 +802,7 @@ int main(int argc, char** argv)
mp_window_focus(app->window); mp_window_focus(app->window);
mp_window_center(app->window); mp_window_center(app->window);
pthread_t runloopThread; mp_thread* runloopThread = mp_thread_create(orca_runloop, 0);
pthread_create(&runloopThread, 0, orca_runloop, 0);
while(!mp_should_quit()) while(!mp_should_quit())
{ {
@ -812,8 +810,7 @@ int main(int argc, char** argv)
//TODO: what to do with mem scratch here? //TODO: what to do with mem scratch here?
} }
void* res; mp_thread_join(runloopThread, NULL);
pthread_join(runloopThread, &res);
mg_canvas_destroy(app->canvas); mg_canvas_destroy(app->canvas);
mg_surface_destroy(app->surface); mg_surface_destroy(app->surface);