Commit c96e42dc by Ryan Harrison

Add WASM build target for Web version of glslang

This adds build rules to support generating a WASM binary to be used on the web. The API exposed to web applications is definated in the new glslang.js.cpp file.
parent 3cea2e58
......@@ -32,6 +32,9 @@ option(ENABLE_HLSL "Enables HLSL input support" ON)
option(ENABLE_OPT "Enables spirv-opt capability if present" 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)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "..." FORCE)
endif()
......@@ -98,6 +101,27 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC")
add_compile_options(/GR-) # Disable RTTI
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(EMSCRIPTEN)
add_compile_options(-Os -g -flto -fno-exceptions)
endif(EMSCRIPTEN)
endif(ENABLE_GLSLANG_WEB)
# Request C++11
if(${CMAKE_VERSION} VERSION_LESS 3.1)
# CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD
......
Build as usual (see `README.md`), but:
* Need `emsdk` in your *PATH*
+ 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* Add flag to disable SPIRV-Tool inclusion even if directory is
present.
* Wrap call to `cmake` using `emconfigure`:
+ e.g. `emconfigure cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_GLSLANG_WEB=ON
-DENABLE_HLSL=OFF -DCMAKE_INSTALL_PREFIX="$(pwd)/install" ..`
+ To get a 'true' size, make sure to use `brotli` to compress the .js and .wasm files
......@@ -122,3 +122,15 @@ if(ENABLE_GLSLANG_INSTALL)
install(FILES ${file} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/glslang/${dir})
endforeach()
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