Roll external/abseil_cpp/ 8f739d18b..917bfee46 (2 commits) (#5887)
[KhronosGroup/SPIRV-Tools.git] / source / wasm / build.sh
blobf4663565e95951a4d4f6ad47f0d6e3917338a6dc
1 #!/bin/bash
3 # Copyright (c) 2020 The Khronos Group Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 set -e
19 # This is required to run any git command in the docker since owner will
20 # have changed between the clone environment, and the docker container.
21 # Marking the root of the repo as safe for ownership changes.
22 git config --global --add safe.directory /app
24 NUM_CORES=$(nproc)
25 echo "Detected $NUM_CORES cores for building"
27 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
28 VERSION=$(sed -n '0,/^v20/ s/^v\(20[0-9.]*\).*/\1/p' $DIR/../../CHANGES).${GITHUB_RUN_NUMBER:-0}
29 echo "Version: $VERSION"
31 build() {
32 type=$1
33 shift
34 args=$@
35 mkdir -p build/$type
36 pushd build/$type
37 echo $args
38 emcmake cmake \
39 -DCMAKE_BUILD_TYPE=Release \
40 $args \
41 ../..
42 emmake make -j $(( $NUM_CORES )) SPIRV-Tools-static
44 echo Building js interface
45 emcc \
46 --bind \
47 -I../../include \
48 -std=c++17 \
49 ../../source/wasm/spirv-tools.cpp \
50 source/libSPIRV-Tools.a \
51 -o spirv-tools.js \
52 -s MODULARIZE \
53 -Oz
55 popd
56 mkdir -p out/$type
58 # copy other js files
59 cp source/wasm/spirv-tools.d.ts out/$type/
60 sed -e 's/\("version"\s*:\s*\).*/\1"'$VERSION'",/' source/wasm/package.json > out/$type/package.json
61 cp source/wasm/README.md out/$type/
62 cp LICENSE out/$type/
64 cp build/$type/spirv-tools.js out/$type/
65 gzip -9 -k -f out/$type/spirv-tools.js
66 if [ -e build/$type/spirv-tools.wasm ] ; then
67 cp build/$type/spirv-tools.wasm out/$type/
68 gzip -9 -k -f out/$type/spirv-tools.wasm
72 if [ ! -d external/spirv-headers ] ; then
73 echo "Fetching deps"
74 utils/git-sync-deps
77 echo Building ${BASH_REMATCH[1]}
78 build web\
79 -DSPIRV_COLOR_TERMINAL=OFF\
80 -DSPIRV_SKIP_TESTS=ON\
81 -DSPIRV_SKIP_EXECUTABLES=ON
83 wc -c out/*/*