build.sh 2.3 KB

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