-improved WASM compilation scripts
-added external bindbc.sdl import for WASM -working on demos (WIP, working simple demo with ECS and SDL2) -small change in ecs.std
This commit is contained in:
parent
a8c74d5045
commit
73f2aa6861
60 changed files with 9015 additions and 67 deletions
125
compile_wasm.py
125
compile_wasm.py
|
|
@ -2,11 +2,47 @@ import os
|
|||
import ntpath
|
||||
import sys
|
||||
|
||||
def compile(sources, output):
|
||||
files = []
|
||||
# r=root, d=directories, f = files
|
||||
for path in sources:
|
||||
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' and filename != 'package':
|
||||
files.append(os.path.join(r, file))
|
||||
|
||||
ldc_cmd = 'ldc2 ' + shared_flags + ldc_flags + '-oq -mtriple=wasm32-unknown-unknown-wasm -betterC -L-allow-undefined --output-bc --od=.bc --singleobj --checkaction=C --of=' + output + ' '
|
||||
|
||||
for path in sources:
|
||||
ldc_cmd += '-I' + path + ' '
|
||||
|
||||
for path in import_paths:
|
||||
ldc_cmd += '-I' + path + ' '
|
||||
|
||||
for f in files:
|
||||
ldc_cmd += f + ' '
|
||||
|
||||
print ldc_cmd
|
||||
|
||||
if os.system(ldc_cmd):
|
||||
exit(0)
|
||||
print
|
||||
|
||||
shared_flags = ''
|
||||
clean = 0
|
||||
emc_flags = ''
|
||||
ldc_flags = ''
|
||||
import_paths = ['source','tests']
|
||||
build_tests = 0
|
||||
|
||||
for arg in sys.argv:
|
||||
if(arg == '-O3'):
|
||||
for arg in sys.argv[1:]:
|
||||
if(arg == '-release'):
|
||||
ldc_flags += '-release '
|
||||
elif(arg == '-enable-inlining'):
|
||||
ldc_flags += '-enable-inlining '
|
||||
elif(arg == '-O3'):
|
||||
shared_flags += '-O3 '
|
||||
elif(arg == '-O2'):
|
||||
shared_flags += '-O2 '
|
||||
|
|
@ -20,71 +56,30 @@ for arg in sys.argv:
|
|||
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 + ' '
|
||||
elif(arg == '--build-tests'):
|
||||
build_tests = 1
|
||||
elif(arg == '--llvm-lto'):
|
||||
emc_flags += '--llvm-lto 3 '
|
||||
elif(arg == '--simd'):
|
||||
emc_flags += '-s SIMD=1 '
|
||||
elif(arg == '-opt'):
|
||||
shared_flags += '-O3 '
|
||||
ldc_flags += '-release -enable-inlining '
|
||||
emc_flags += '--llvm-lto 3 -s SIMD=1 '
|
||||
else:
|
||||
print('unknown argument: ' + arg)
|
||||
exit()
|
||||
|
||||
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))
|
||||
compile(['source'], 'ecs.bc')
|
||||
|
||||
if build_tests == 0:
|
||||
exit(0)
|
||||
|
||||
compile(['tests'], 'tests.bc')
|
||||
|
||||
|
||||
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 + ' '
|
||||
emcc_cmd = 'emcc -v ' + shared_flags + emc_flags + '-s ALLOW_MEMORY_GROWTH=1 -s MALLOC=dlmalloc -s WASM=1 -o index.html '
|
||||
|
||||
emcc_cmd += 'ecs.bc tests.bc'
|
||||
|
||||
print emcc_cmd
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue