-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.py
84 lines (73 loc) · 2.3 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/python
# INFORMATION:
# This scripts compiles Glslang and SPIR-V tools to JavaScript
import os
import shutil
EXPORTED_FUNCTIONS = [
'_gjsInitialize',
'_gjsFinalize',
'_gjsCompile',
'_gjsGetSpirvData',
'_gjsGetSpirvSize',
'_gjsGetSpirvDisassembly',
'_gjsDestruct',
]
def compileGlslang():
# Fix SPIRV-Tools CMakeLists.txt file
pathA = "externals/SPIRV-Tools/CMakeLists.txt"
pathB = "externals/SPIRV-Tools/CMakeLists.txt.bak"
shutil.copyfile(pathA, pathB)
with open(pathB, 'rb') as infile, open(pathA, 'wb') as outfile:
for line in infile:
line = line.replace('${CMAKE_SYSTEM_NAME}', 'Linux')
outfile.write(line)
# CMake
cmd = 'cmake'
cmd += os.path.expandvars(' -DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake')
cmd += ' -DCMAKE_BUILD_TYPE=Release'
if os.name == 'nt':
cmd += ' -G \"MinGW Makefiles\"'
if os.name == 'posix':
cmd += ' -G \"Unix Makefiles\"'
os.system(cmd + ' externals/glslang/CMakeLists.txt')
os.system(cmd + ' externals/SPIRV-Tools/CMakeLists.txt')
os.system(cmd + ' helper/CMakeLists.txt')
# Make Glslang
os.chdir('externals/glslang')
if os.name == 'nt':
os.system('mingw32-make')
if os.name == 'posix':
os.system('make')
os.chdir('../..')
# Make SPIRV-Tools
os.chdir('externals/SPIRV-Tools')
if os.name == 'nt':
os.system('mingw32-make')
if os.name == 'posix':
os.system('make')
os.chdir('../..')
# Make Glslang.JS helper
os.chdir('helper')
if os.name == 'nt':
os.system('mingw32-make')
if os.name == 'posix':
os.system('make')
os.chdir('..')
# Compile static library to JavaScript
cmd = os.path.expandvars('$EMSCRIPTEN/em++')
cmd += ' -O1'
cmd += ' externals/glslang/glslang/libglslang.a'
cmd += ' externals/glslang/glslang/OSDependent/Unix/libOSDependent.a'
cmd += ' externals/glslang/OGLCompilersDLL/libOGLCompiler.a'
cmd += ' externals/glslang/SPIRV/libSPIRV.a'
cmd += ' externals/SPIRV-Tools/libSPIRV-Tools.a'
cmd += ' helper/libglslangjs_helper.a'
cmd += ' -s EXPORTED_FUNCTIONS=\"[\''+ '\', \''.join(EXPORTED_FUNCTIONS) +'\']\"'
cmd += ' -o src/glslang.out.js'
os.system(cmd)
if __name__ == "__main__":
if os.name in ['nt', 'posix']:
compileGlslang()
else:
print "Your operating system is not supported by this script:"
print "Please, use Emscripten to compile Glslang manually to src/glslang.out.js"