Basic build instructions, or you can download the precompiled builds from below.
## Build with zig 0.11.0 (later might work too)
git clone https://github.com/joshua-software-dev/glslang.git
cd glslang
./update_glslang_sources.py
cd ..
mkdir build
cd build
env \
CC="zig cc --target=wasm32-wasi" \
CXX="zig c++ --target=wasm32-wasi" \
cmake \
-DWASI=1 \
-DCMAKE_SYSTEM_NAME=WASI \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_GLSLANG_BINARIES=ON \
-DENABLE_GLSLANG_INSTALL=OFF \
-DENABLE_OPT=OFF \
-DENABLE_PCH=OFF \
../glslang
# To build with the spirv_tools optimizer enabled:
cd glslang/External/spirv-tools
git apply spirv_tools.patch
cd ../../../
mkdir build
cd build
env \
CC="zig cc --target=wasm32-wasi" \
CXX="zig c++ --target=wasm32-wasi" \
cmake \
-DWASI=1 \
-DCMAKE_SYSTEM_NAME=WASI \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_GLSLANG_BINARIES=ON \
-DENABLE_GLSLANG_INSTALL=OFF \
-DENABLE_OPT=ON \
-DENABLE_PCH=OFF \
-DSPIRV_SKIP_EXECUTABLES=ON \
-DSPIRV_SKIP_TESTS=ON \
-DENABLE_SPIRV_TOOLS_INSTALL=OFF \
-DSPIRV_TOOLS_BUILD_STATIC=ON \
-DSPIRV_TOOLS_LIBRARY_TYPE=STATIC \
../glslang
## Docker Build instructions
#
# Outside docker container
git clone https://github.com/joshua-software-dev/glslang.git
cd glslang
./update_glslang_sources.py
docker run --rm -it -v `pwd`:/src -w /src ghcr.io/webassembly/wasi-sdk /bin/bash
# Inside docker container
mkdir build
cd build
cmake \
-DCMAKE_TOOLCHAIN_FILE=/usr/share/cmake/wasi-sdk.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_GLSLANG_BINARIES=ON \
-DENABLE_GLSLANG_INSTALL=OFF \
-DENABLE_OPT=OFF \
/src
make -j $(nproc)
or
cmake --build . -j
# To build with the spirv_tools optimizer enabled:
#
# Outside docker container
cd glslang/External/spirv-tools
git apply spirv_tools.patch
cd ../../..
# Inside docker container
cmake \
-DCMAKE_TOOLCHAIN_FILE=/usr/share/cmake/wasi-sdk.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_GLSLANG_BINARIES=ON \
-DENABLE_GLSLANG_INSTALL=OFF \
-DENABLE_OPT=ON \
-DSPIRV_SKIP_EXECUTABLES=ON \
-DSPIRV_SKIP_TESTS=ON \
-DENABLE_SPIRV_TOOLS_INSTALL=OFF \
-DSPIRV_TOOLS_BUILD_STATIC=ON \
-DSPIRV_TOOLS_LIBRARY_TYPE=STATIC \
/src
make -j $(nproc)
or
cmake --build . -jThe spirv.patch is not suitable for merging back into spirv_tools, unfortunately. It mostly just disables building the shared library that otherwise cannot be turned off. A better patch would add proper flags for disabling this shared library, but that's out of scope of this quick and dirty fix.
Usage Instructions:
Run in a wasm runtime (for example wasmtime or wasmer) like so:
# wasi provides some filesystem sandboxing by only allowing access
# to explicitly allowed directories and their subdirectories
# with ".", you may may provide paths descending from this folder to glslang
# use -- to provide arguments to glslang instead of wasmtime
wasmtime --dir="." glslang.wasm -- -V -o example.frag.spv example.frag.glsl
# running the native binary to compare
glslang -V -o example2.frag.spv example.frag.glsl
diff example.frag.spv example2.frag.spv
echo "$?" # prints 0the zig builds seem to not be correctly stripping some things, so they are unnecessarily large. Not ideal, but for a local build, its the easiest cross-compiler to setup.