Get entire Orca build working on Windows
This commit is contained in:
parent
25f660227f
commit
10351e45cd
|
@ -1,26 +1,17 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
def bindgen(apiName, cdir):
|
||||||
print("bindgen require an api name\n")
|
inPath = cdir + '/bindgen_' + apiName + '_api.txt'
|
||||||
exit(-1);
|
outPath = cdir + '/bindgen_' + apiName + '_api.c'
|
||||||
|
|
||||||
apiName = sys.argv[1]
|
inFile = open(inPath, 'r')
|
||||||
cdir = ''
|
outFile = open(outPath, 'w')
|
||||||
|
|
||||||
if len(sys.argv) > 2:
|
stubs = []
|
||||||
cdir = sys.argv[2]
|
links = []
|
||||||
|
|
||||||
inPath = cdir + '/bindgen_' + apiName + '_api.txt'
|
def gen_stub(name, sig, native_name):
|
||||||
outPath = cdir + '/bindgen_' + apiName + '_api.c'
|
|
||||||
|
|
||||||
inFile = open(inPath, 'r')
|
|
||||||
outFile = open(outPath, 'w')
|
|
||||||
|
|
||||||
stubs = []
|
|
||||||
links = []
|
|
||||||
|
|
||||||
def gen_stub(name, sig, native_name):
|
|
||||||
if native_name == None:
|
if native_name == None:
|
||||||
native_name = name
|
native_name = name
|
||||||
|
|
||||||
|
@ -91,7 +82,7 @@ def gen_stub(name, sig, native_name):
|
||||||
src += '}\n'
|
src += '}\n'
|
||||||
stubs.append(src)
|
stubs.append(src)
|
||||||
|
|
||||||
def gen_link(name, sig):
|
def gen_link(name, sig):
|
||||||
m3_Sig = ''
|
m3_Sig = ''
|
||||||
for c in sig:
|
for c in sig:
|
||||||
if c == 'p':
|
if c == 'p':
|
||||||
|
@ -103,7 +94,7 @@ def gen_link(name, sig):
|
||||||
src += '\tif(res != m3Err_none && res != m3Err_functionLookupFailed) { log_error("error: %s\\n", res); return(-1); }\n\n'
|
src += '\tif(res != m3Err_none && res != m3Err_functionLookupFailed) { log_error("error: %s\\n", res); return(-1); }\n\n'
|
||||||
links.append(src)
|
links.append(src)
|
||||||
|
|
||||||
for line in inFile:
|
for line in inFile:
|
||||||
if line.isspace():
|
if line.isspace():
|
||||||
continue
|
continue
|
||||||
desc = line.split()
|
desc = line.split()
|
||||||
|
@ -111,21 +102,34 @@ for line in inFile:
|
||||||
gen_stub(desc[0], desc[1], desc[2] if len(desc) > 2 else None)
|
gen_stub(desc[0], desc[1], desc[2] if len(desc) > 2 else None)
|
||||||
gen_link(desc[0], desc[1])
|
gen_link(desc[0], desc[1])
|
||||||
|
|
||||||
linkProc = 'int bindgen_link_' + apiName + '_api(IM3Module module)\n'
|
linkProc = 'int bindgen_link_' + apiName + '_api(IM3Module module)\n'
|
||||||
linkProc += '{\n'
|
linkProc += '{\n'
|
||||||
linkProc += '\tM3Result res;\n'
|
linkProc += '\tM3Result res;\n'
|
||||||
|
|
||||||
for link in links:
|
for link in links:
|
||||||
linkProc += link
|
linkProc += link
|
||||||
|
|
||||||
linkProc += '\treturn(0);\n'
|
linkProc += '\treturn(0);\n'
|
||||||
linkProc += '}\n'
|
linkProc += '}\n'
|
||||||
|
|
||||||
for stub in stubs:
|
for stub in stubs:
|
||||||
outFile.write(stub)
|
outFile.write(stub)
|
||||||
|
|
||||||
outFile.write('\n')
|
outFile.write('\n')
|
||||||
outFile.write(linkProc)
|
outFile.write(linkProc)
|
||||||
|
|
||||||
inFile.close()
|
inFile.close()
|
||||||
outFile.close()
|
outFile.close()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print("bindgen require an api name\n")
|
||||||
|
exit(-1)
|
||||||
|
|
||||||
|
apiName = sys.argv[1]
|
||||||
|
cdir = ''
|
||||||
|
|
||||||
|
if len(sys.argv) > 2:
|
||||||
|
cdir = sys.argv[2]
|
||||||
|
|
||||||
|
bindgen(apiName, cdir)
|
||||||
|
|
|
@ -3,31 +3,6 @@
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
import json
|
import json
|
||||||
|
|
||||||
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'
|
|
||||||
|
|
||||||
host_bindings = open(wasm3_bindings_path, 'w')
|
|
||||||
guest_bindings = None
|
|
||||||
|
|
||||||
specFile = open(spec, 'r')
|
|
||||||
data = json.load(specFile)
|
|
||||||
|
|
||||||
def needs_arg_ptr_stub(decl):
|
def needs_arg_ptr_stub(decl):
|
||||||
res = (decl['ret']['tag'] == 'S')
|
res = (decl['ret']['tag'] == 'S')
|
||||||
for arg in decl['args']:
|
for arg in decl['args']:
|
||||||
|
@ -35,15 +10,26 @@ def needs_arg_ptr_stub(decl):
|
||||||
res = True
|
res = True
|
||||||
return(res)
|
return(res)
|
||||||
|
|
||||||
for decl in data:
|
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):
|
if needs_arg_ptr_stub(decl):
|
||||||
guest_bindings = open(guest_stubs_path, 'w')
|
guest_bindings = open(guest_stubs_path, 'w')
|
||||||
if args.guest_include != None:
|
if guest_include != None:
|
||||||
s = '#include"' + args.guest_include + '"\n\n'
|
s = '#include"' + guest_include + '"\n\n'
|
||||||
print(s, file=guest_bindings)
|
print(s, file=guest_bindings)
|
||||||
break
|
break
|
||||||
|
|
||||||
for decl in data:
|
for decl in data:
|
||||||
|
|
||||||
name = decl['name']
|
name = decl['name']
|
||||||
cname = decl.get('cname', name)
|
cname = decl.get('cname', name)
|
||||||
|
@ -164,11 +150,11 @@ for decl in data:
|
||||||
|
|
||||||
print(s, file=host_bindings)
|
print(s, file=host_bindings)
|
||||||
|
|
||||||
# link function
|
# link function
|
||||||
s = 'int bindgen_link_' + apiName + '_api(IM3Module module)\n{\n\t'
|
s = 'int bindgen_link_' + apiName + '_api(IM3Module module)\n{\n\t'
|
||||||
s += 'M3Result res;\n'
|
s += 'M3Result res;\n'
|
||||||
|
|
||||||
for decl in data:
|
for decl in data:
|
||||||
name = decl['name']
|
name = decl['name']
|
||||||
cname = decl.get('cname', name)
|
cname = decl.get('cname', name)
|
||||||
|
|
||||||
|
@ -196,6 +182,33 @@ for decl in data:
|
||||||
s += '\tif(res != m3Err_none && res != m3Err_functionLookupFailed) { log_error("error: %s\\n", res); return(-1); }\n\n'
|
s += '\tif(res != m3Err_none && res != m3Err_functionLookupFailed) { log_error("error: %s\\n", res); return(-1); }\n\n'
|
||||||
|
|
||||||
|
|
||||||
s += '\treturn(0);\n}\n'
|
s += '\treturn(0);\n}\n'
|
||||||
|
|
||||||
print(s, file=host_bindings)
|
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,
|
||||||
|
)
|
||||||
|
|
|
@ -9,6 +9,8 @@ import subprocess
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
import checksum
|
import checksum
|
||||||
|
from bindgen import bindgen
|
||||||
|
from bindgen2 import bindgen2
|
||||||
from log import *
|
from log import *
|
||||||
from utils import pushd, removeall
|
from utils import pushd, removeall
|
||||||
|
|
||||||
|
@ -28,6 +30,7 @@ def build_runtime(args):
|
||||||
|
|
||||||
build_milepost("lib", args.release)
|
build_milepost("lib", args.release)
|
||||||
build_wasm3(args.release)
|
build_wasm3(args.release)
|
||||||
|
build_orca(args.release)
|
||||||
|
|
||||||
|
|
||||||
def build_milepost(target, release):
|
def build_milepost(target, release):
|
||||||
|
@ -213,6 +216,75 @@ def build_wasm3_lib_win(release):
|
||||||
], check=True)
|
], check=True)
|
||||||
|
|
||||||
|
|
||||||
|
def build_orca(release):
|
||||||
|
print("Building Orca...")
|
||||||
|
|
||||||
|
os.makedirs("bin", exist_ok=True)
|
||||||
|
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
build_orca_win(release)
|
||||||
|
elif platform.system() == "Darwin":
|
||||||
|
raise "can't yet build Orca on Mac"
|
||||||
|
else:
|
||||||
|
log_error(f"can't build Orca for unknown platform '{platform.system()}'")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def build_orca_win(release):
|
||||||
|
pthread_dir = "..\\vcpkg\\packages\\pthreads_x64-windows"
|
||||||
|
|
||||||
|
# copy libraries
|
||||||
|
shutil.copy("milepost\\bin\\milepost.dll", "bin")
|
||||||
|
shutil.copy("milepost\\bin\\milepost.dll.lib", "bin")
|
||||||
|
shutil.copy(os.path.join(pthread_dir, "bin\\pthreadVC3.dll"), "bin")
|
||||||
|
|
||||||
|
# generate wasm3 api bindings
|
||||||
|
bindgen("core", "src")
|
||||||
|
bindgen("gles", "src")
|
||||||
|
bindgen2("canvas", "src\\canvas_api.json",
|
||||||
|
guest_stubs="sdk\\orca_surface.c",
|
||||||
|
guest_include="graphics.h",
|
||||||
|
wasm3_bindings="src\\canvas_api_bind_gen.c",
|
||||||
|
)
|
||||||
|
bindgen2("clock", "src\\clock_api.json",
|
||||||
|
guest_stubs="sdk\\orca_clock.c",
|
||||||
|
guest_include="platform_clock.h",
|
||||||
|
wasm3_bindings="src\\clock_api_bind_gen.c",
|
||||||
|
)
|
||||||
|
bindgen2("io", "src\\io_api.json",
|
||||||
|
guest_stubs="sdk\\io_stubs.c",
|
||||||
|
wasm3_bindings="src\\io_api_bind_gen.c",
|
||||||
|
)
|
||||||
|
|
||||||
|
# compile orca
|
||||||
|
pthread_include = os.path.join(pthread_dir, "include")
|
||||||
|
includes = [
|
||||||
|
"/I", "src",
|
||||||
|
"/I", "sdk",
|
||||||
|
"/I", "ext\wasm3\source",
|
||||||
|
"/I", "milepost\src",
|
||||||
|
"/I", "milepost\ext",
|
||||||
|
"/I", pthread_include,
|
||||||
|
]
|
||||||
|
pthread_lib = os.path.join(pthread_dir, "lib")
|
||||||
|
libs = [
|
||||||
|
"/LIBPATH:bin",
|
||||||
|
f"/LIBPATH:{pthread_lib}",
|
||||||
|
"milepost.dll.lib",
|
||||||
|
"wasm3.lib",
|
||||||
|
"pthreadVC3.lib",
|
||||||
|
]
|
||||||
|
|
||||||
|
subprocess.run([
|
||||||
|
"cl",
|
||||||
|
"/Zi", "/Zc:preprocessor", "/std:c11",
|
||||||
|
*includes,
|
||||||
|
"src\\main.c",
|
||||||
|
"/link", *libs,
|
||||||
|
"/out:bin\\orca.exe",
|
||||||
|
], check=True)
|
||||||
|
|
||||||
|
|
||||||
def ensure_programs():
|
def ensure_programs():
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue