• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# Copyright (c) 2020 The Khronos Group Inc.
4#
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
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
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.
16
17set -e
18
19NUM_CORES=$(nproc)
20echo "Detected $NUM_CORES cores for building"
21
22DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
23VERSION=$(sed -n '0,/^v20/ s/^v\(20[0-9.]*\).*/\1/p' $DIR/../../CHANGES).${GITHUB_RUN_NUMBER:-0}
24echo "Version: $VERSION"
25
26build() {
27    type=$1
28    shift
29    args=$@
30    mkdir -p build/$type
31    pushd build/$type
32    echo $args
33    emcmake cmake \
34        -DCMAKE_BUILD_TYPE=Release \
35        $args \
36        ../..
37    emmake make -j $(( $NUM_CORES )) SPIRV-Tools-static
38
39    echo Building js interface
40    emcc \
41        --bind \
42        -I../../include \
43        -std=c++11 \
44        ../../source/wasm/spirv-tools.cpp \
45        source/libSPIRV-Tools.a \
46        -o spirv-tools.js \
47        -s MODULARIZE \
48        -Oz
49
50    popd
51    mkdir -p out/$type
52
53    # copy other js files
54    cp source/wasm/spirv-tools.d.ts out/$type/
55    sed -e 's/\("version"\s*:\s*\).*/\1"'$VERSION'",/' source/wasm/package.json > out/$type/package.json
56    cp source/wasm/README.md out/$type/
57    cp LICENSE out/$type/
58
59    cp build/$type/spirv-tools.js out/$type/
60    gzip -9 -k -f out/$type/spirv-tools.js
61    if [ -e build/$type/spirv-tools.wasm ] ; then
62       cp build/$type/spirv-tools.wasm out/$type/
63       gzip -9 -k -f out/$type/spirv-tools.wasm
64    fi
65}
66
67if [ ! -d external/spirv-headers ] ; then
68    echo "Fetching SPIRV-headers"
69    git clone https://github.com/KhronosGroup/SPIRV-Headers.git external/spirv-headers
70fi
71
72echo Building ${BASH_REMATCH[1]}
73build web\
74    -DSPIRV_COLOR_TERMINAL=OFF\
75    -DSPIRV_SKIP_TESTS=ON\
76    -DSPIRV_SKIP_EXECUTABLES=ON
77
78wc -c out/*/*
79