Unverified Commit 37fc4d27 by John Kessenich Committed by GitHub

Merge pull request #1867 from zoddicus/addWebBuild

Add WASM build target for Web version of glslang
parents 3cea2e58 7eb3e6e0
...@@ -9,6 +9,9 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) ...@@ -9,6 +9,9 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Adhere to GNU filesystem layout conventions # Adhere to GNU filesystem layout conventions
include(GNUInstallDirs) include(GNUInstallDirs)
# Needed for CMAKE_DEPENDENT_OPTION macro
include(CMakeDependentOption)
option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
set(LIB_TYPE STATIC) set(LIB_TYPE STATIC)
...@@ -28,7 +31,10 @@ option(ENABLE_GLSLANG_BINARIES "Builds glslangValidator and spirv-remap" ON) ...@@ -28,7 +31,10 @@ option(ENABLE_GLSLANG_BINARIES "Builds glslangValidator and spirv-remap" ON)
option(ENABLE_NV_EXTENSIONS "Enables support of Nvidia-specific extensions" ON) option(ENABLE_NV_EXTENSIONS "Enables support of Nvidia-specific extensions" ON)
option(ENABLE_HLSL "Enables HLSL input support" ON) option(ENABLE_GLSLANG_WEB "Reduces glslang to minumum needed for web use" OFF)
option(ENABLE_EMSCRIPTEN_SINGLE_FILE "If using emscripten, enables SINGLE_FILE build" OFF)
CMAKE_DEPENDENT_OPTION(ENABLE_HLSL "Enables HLSL input support" ON "NOT ENABLE_GLSLANG_WEB" OFF)
option(ENABLE_OPT "Enables spirv-opt capability if present" ON) option(ENABLE_OPT "Enables spirv-opt capability if present" ON)
...@@ -98,6 +104,32 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC") ...@@ -98,6 +104,32 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC")
add_compile_options(/GR-) # Disable RTTI add_compile_options(/GR-) # Disable RTTI
endif() endif()
if(ENABLE_GLSLANG_WEB)
if(EMSCRIPTEN)
add_compile_options(-Os -fno-exceptions)
add_compile_options("SHELL: -s WASM=1")
add_compile_options("SHELL: -s WASM_OBJECT_FILES=0")
add_link_options(-Os)
add_link_options("SHELL: -s FILESYSTEM=0")
add_link_options("SHELL: --llvm-lto 1")
add_link_options("SHELL: --closure 1")
add_link_options("SHELL: -s ENVIRONMENT=web,worker")
add_link_options("SHELL: -s ALLOW_MEMORY_GROWTH=1")
add_link_options("SHELL: -s MODULARIZE=1")
if(ENABLE_EMSCRIPTEN_SINGLE_FILE)
add_link_options("SHELL: -s SINGLE_FILE=1")
endif(ENABLE_EMSCRIPTEN_SINGLE_FILE)
else()
if(MSVC)
add_compile_options(/Os /GR-)
else()
add_compile_options(-Os -fno-exceptions)
add_link_options(-Os)
endif()
endif(EMSCRIPTEN)
endif(ENABLE_GLSLANG_WEB)
# Request C++11 # Request C++11
if(${CMAKE_VERSION} VERSION_LESS 3.1) if(${CMAKE_VERSION} VERSION_LESS 3.1)
# CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD
......
...@@ -163,6 +163,22 @@ bison --defines=MachineIndependent/glslang_tab.cpp.h ...@@ -163,6 +163,22 @@ bison --defines=MachineIndependent/glslang_tab.cpp.h
The above command is also available in the bash script at The above command is also available in the bash script at
`glslang/updateGrammar`. `glslang/updateGrammar`.
### WASM for the the Web
Use the steps in [Build Steps](#build-steps), which following notes/exceptions:
* `emsdk` needs to be present in your executable search path, *PATH* for
Bash-like enivironments
+ Instructions located
[here](https://emscripten.org/docs/getting_started/downloads.html#sdk-download-and-install)
* Do not checkout SPIRV-Tools into `External`
+ Does not work correctly with emscripten out of the box and we don't want it
in the build anyway. *TBD* Have build ignore SPIRV-Tools for web build
* Wrap call to `cmake` using `emconfigure` with ENABLE_GLSLANG_WEB=ON:
+ e.g. For Linux, `emconfigure cmake -DCMAKE_BUILD_TYPE=Release
-DENABLE_GLSLANG_WEB=ON -DCMAKE_INSTALL_PREFIX="$(pwd)/install" ..`
* To get a 'true' minimized build, make sure to use `brotli` to compress the .js
and .wasm files
Testing Testing
------- -------
......
...@@ -122,3 +122,15 @@ if(ENABLE_GLSLANG_INSTALL) ...@@ -122,3 +122,15 @@ if(ENABLE_GLSLANG_INSTALL)
install(FILES ${file} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/glslang/${dir}) install(FILES ${file} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/glslang/${dir})
endforeach() endforeach()
endif(ENABLE_GLSLANG_INSTALL) endif(ENABLE_GLSLANG_INSTALL)
if(ENABLE_GLSLANG_WEB)
add_executable(glslang.js glslang.js.cpp)
glslang_set_link_args(glslang.js)
target_link_libraries(glslang.js glslang SPIRV)
if(EMSCRIPTEN)
set_target_properties(glslang.js PROPERTIES
OUTPUT_NAME "glslang"
SUFFIX ".js"
LINK_FLAGS "--bind")
endif(EMSCRIPTEN)
endif(ENABLE_GLSLANG_WEB)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment