Merge pull request #1907 from kainino0x/separate-web-and-emscripten

Separate GLSLANG_WEB (min-size build) and Emscripten options
This commit is contained in:
John Kessenich 2019-09-19 09:12:52 -06:00 committed by GitHub
commit f7a48b153f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 99 additions and 61 deletions

View file

@ -6,6 +6,10 @@ else(WIN32)
message("unknown platform")
endif(WIN32)
if(EMSCRIPTEN OR ENABLE_GLSLANG_WEB)
add_subdirectory(OSDependent/Web)
endif(EMSCRIPTEN OR ENABLE_GLSLANG_WEB)
set(SOURCES
MachineIndependent/glslang.m4
MachineIndependent/glslang.y
@ -114,16 +118,3 @@ 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 -s EXPORT_NAME=\"glslangModule\"")
em_link_pre_js(glslang.js ${CMAKE_CURRENT_SOURCE_DIR}/glslang.pre.js)
endif(EMSCRIPTEN)
endif(ENABLE_GLSLANG_WEB)

View file

@ -0,0 +1,24 @@
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")
em_link_pre_js(glslang.js "${CMAKE_CURRENT_SOURCE_DIR}/glslang.pre.js")
target_link_options(glslang.js PRIVATE
"SHELL:--bind -s MODULARIZE=1")
if(ENABLE_EMSCRIPTEN_ENVIRONMENT_NODE)
target_link_options(glslang.js PRIVATE
"SHELL:-s ENVIRONMENT=node -s BINARYEN_ASYNC_COMPILATION=0")
else()
target_link_options(glslang.js PRIVATE
"SHELL:-s ENVIRONMENT=web,worker")
endif()
if(NOT ENABLE_EMSCRIPTEN_ENVIRONMENT_NODE)
add_custom_command(TARGET glslang.js POST_BUILD
COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/glslang.after.js >> ${CMAKE_CURRENT_BINARY_DIR}/glslang.js)
endif()
endif(EMSCRIPTEN)

View file

@ -0,0 +1,26 @@
export default (() => {
const initialize = () => {
return new Promise(resolve => {
Module({
locateFile() {
const i = import.meta.url.lastIndexOf('/')
return import.meta.url.substring(0, i) + '/glslang.wasm';
},
onRuntimeInitialized() {
resolve({
compileGLSLZeroCopy: this.compileGLSLZeroCopy,
compileGLSL: this.compileGLSL,
});
},
});
});
};
let instance;
return () => {
if (!instance) {
instance = initialize();
}
return instance;
};
})();

View file

@ -35,17 +35,16 @@
#include <cstdio>
#include <cstdint>
#include <memory>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif // __EMSCRIPTEN__
#include <memory>
#endif
#include "../SPIRV/GlslangToSpv.h"
#include "../SPIRV/doc.h"
#include "./../glslang/Public/ShaderLang.h"
#include "../../../SPIRV/GlslangToSpv.h"
#include "../../../glslang/Public/ShaderLang.h"
#ifndef EMSCRIPTEN_KEEPALIVE
#ifndef __EMSCRIPTEN__
#define EMSCRIPTEN_KEEPALIVE
#endif

View file

@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/bin/bash
if [ "$1" = 'web' ]
then