bubel-ecs/compile_wasm.py
Mergul a8c74d5045 -make tests working on web
-WebAssembly now is compiled with emscripten use (stdc functions bindings only)
-added python script to build WASM version
2019-11-05 09:21:02 +01:00

91 lines
2.2 KiB
Python

import os
import ntpath
import sys
shared_flags = ''
clean = 0
for arg in sys.argv:
if(arg == '-O3'):
shared_flags += '-O3 '
elif(arg == '-O2'):
shared_flags += '-O2 '
elif(arg == '-O1'):
shared_flags += '-O1 '
elif(arg == '-O0'):
shared_flags += '-O0 '
elif(arg == '-Os'):
shared_flags += '-Os '
elif(arg == '-Oz'):
shared_flags += '-Oz '
elif(arg == '-g'):
shared_flags += '-g '
elif(arg == '--clean'):
clean = 1
if clean == 1:
for path in ['bc']:
for r, d, f in os.walk(path):
for file in f:
filename, file_extension = os.path.splitext(file)
if file_extension == '.bc':
print('remove ' + os.path.join(r, file))
os.remove(os.path.join(r, file))
exit()
paths = ['tests', 'source']
files = []
# r=root, d=directories, f = files
for path in paths:
for r, d, f in os.walk(path):
for file in f:
if ntpath.basename(file) != 'win_dll.d':
filename, file_extension = os.path.splitext(file)
if file_extension == '.d':
files.append(os.path.join(r, file))
print('files:')
for f in files:
print(f)
print
ldc_cmd = 'ldc2 ' + shared_flags + '-mtriple=wasm32-unknown-unknown-wasm -betterC -L-allow-undefined --output-bc --od=bc --checkaction=C '
for path in paths:
ldc_cmd += '-I' + path + ' '
for f in files:
ldc_cmd += f + ' '
print ldc_cmd
os.system(ldc_cmd)
print
files = []
# r=root, d=directories, f = files
for path in ['bc']:
for r, d, f in os.walk(path):
for file in f:
filename, file_extension = os.path.splitext(file)
if file_extension == '.bc':
files.append(os.path.join(r, file))
print('BC files:')
for f in files:
print(f)
print
emcc_cmd = 'emcc -v ' + shared_flags + '-s ALLOW_MEMORY_GROWTH=1 -s MALLOC=dlmalloc -s WASM=1 -o index.html '
for f in files:
emcc_cmd += f + ' '
print emcc_cmd
os.system(emcc_cmd)