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 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. 22git config --global --add safe.directory /app 23 24NUM_CORES=$(nproc) 25echo "Detected $NUM_CORES cores for building" 26 27DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 28VERSION=$(sed -n '0,/^v20/ s/^v\(20[0-9.]*\).*/\1/p' $DIR/../../CHANGES).${GITHUB_RUN_NUMBER:-0} 29echo "Version: $VERSION" 30 31build() { 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 43 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 54 55 popd 56 mkdir -p out/$type 57 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/ 63 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 69 fi 70} 71 72if [ ! -d external/spirv-headers ] ; then 73 echo "Fetching SPIRV-headers" 74 git clone https://github.com/KhronosGroup/SPIRV-Headers.git external/spirv-headers 75fi 76 77echo Building ${BASH_REMATCH[1]} 78build web\ 79 -DSPIRV_COLOR_TERMINAL=OFF\ 80 -DSPIRV_SKIP_TESTS=ON\ 81 -DSPIRV_SKIP_EXECUTABLES=ON 82 83wc -c out/*/* 84