Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright 2018 Google LLC |
| 3 | # |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | set -ex |
| 8 | |
| 9 | BASE_DIR=`cd $(dirname ${BASH_SOURCE[0]}) && pwd` |
| 10 | # This expects the environment variable EMSDK to be set |
| 11 | if [[ ! -d $EMSDK ]]; then |
| 12 | echo "Be sure to set the EMSDK environment variable." |
| 13 | exit 1 |
| 14 | fi |
| 15 | |
| 16 | BUILD_DIR=${BUILD_DIR:="out/canvaskit_wasm"} |
Kevin Lubick | 8e9750d | 2018-10-09 09:36:35 -0400 | [diff] [blame] | 17 | mkdir -p $BUILD_DIR |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 18 | # Navigate to SKIA_HOME from where this file is located. |
| 19 | pushd $BASE_DIR/../.. |
| 20 | |
| 21 | source $EMSDK/emsdk_env.sh |
Kevin Lubick | 8e9750d | 2018-10-09 09:36:35 -0400 | [diff] [blame] | 22 | EMCC=`which emcc` |
| 23 | EMCXX=`which em++` |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 24 | |
Kevin Lubick | d45c781 | 2018-10-02 11:33:52 -0400 | [diff] [blame] | 25 | RELEASE_CONF="-Oz --closure 1 --llvm-lto 3 -DSK_RELEASE" |
| 26 | EXTRA_CFLAGS="\"-DSK_RELEASE\"" |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 27 | if [[ $@ == *debug* ]]; then |
| 28 | echo "Building a Debug build" |
Kevin Lubick | d45c781 | 2018-10-02 11:33:52 -0400 | [diff] [blame] | 29 | EXTRA_CFLAGS="\"-DSK_DEBUG\"" |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 30 | RELEASE_CONF="-O0 --js-opts 0 -s SAFE_HEAP=1 -s ASSERTIONS=1 -s GL_ASSERTIONS=1 -g3 -DPATHKIT_TESTING -DSK_DEBUG" |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 31 | fi |
| 32 | |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 33 | GN_GPU="skia_enable_gpu=true" |
| 34 | WASM_GPU="-lEGL -lGLESv2 -DSK_SUPPORT_GPU=1" |
| 35 | if [[ $@ == *no_gpu* ]]; then |
| 36 | echo "Omitting the GPU backend" |
| 37 | GN_GPU="skia_enable_gpu=false" |
| 38 | WASM_GPU="-DSK_SUPPORT_GPU=0" |
| 39 | fi |
| 40 | |
| 41 | WASM_SKOTTIE="-DSK_INCLUDE_SKOTTIE=1 \ |
| 42 | modules/skottie/src/Skottie.cpp \ |
| 43 | modules/skottie/src/SkottieAdapter.cpp \ |
| 44 | modules/skottie/src/SkottieAnimator.cpp \ |
| 45 | modules/skottie/src/SkottieJson.cpp \ |
| 46 | modules/skottie/src/SkottieLayer.cpp \ |
| 47 | modules/skottie/src/SkottieLayerEffect.cpp \ |
| 48 | modules/skottie/src/SkottiePrecompLayer.cpp \ |
| 49 | modules/skottie/src/SkottieProperty.cpp \ |
| 50 | modules/skottie/src/SkottieShapeLayer.cpp \ |
| 51 | modules/skottie/src/SkottieTextLayer.cpp \ |
| 52 | modules/skottie/src/SkottieValue.cpp \ |
| 53 | modules/sksg/src/*.cpp \ |
| 54 | src/core/SkCubicMap.cpp \ |
| 55 | src/core/SkTime.cpp \ |
| 56 | src/pathops/SkOpBuilder.cpp \ |
| 57 | src/utils/SkJSON.cpp \ |
| 58 | src/utils/SkParse.cpp " |
| 59 | if [[ $@ == *no_skottie* ]]; then |
| 60 | echo "Omitting Skottie" |
| 61 | WASM_SKOTTIE="-DSK_INCLUDE_SKOTTIE=0" |
| 62 | fi |
| 63 | |
Kevin Lubick | 8e9750d | 2018-10-09 09:36:35 -0400 | [diff] [blame] | 64 | # Turn off exiting while we check for ninja (which may not be on PATH) |
| 65 | set +e |
| 66 | NINJA=`which ninja` |
| 67 | if [[ -z $NINJA ]]; then |
| 68 | git clone "https://chromium.googlesource.com/chromium/tools/depot_tools.git" --depth 1 $BUILD_DIR/depot_tools |
| 69 | NINJA=$BUILD_DIR/depot_tools/ninja |
| 70 | fi |
| 71 | # Re-enable error checking |
| 72 | set -e |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 73 | |
| 74 | echo "Compiling bitcode" |
| 75 | |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 76 | # Inspired by https://github.com/Zubnix/skia-wasm-port/blob/master/build_bindings.sh |
| 77 | ./bin/gn gen ${BUILD_DIR} \ |
| 78 | --args="cc=\"${EMCC}\" \ |
| 79 | cxx=\"${EMCXX}\" \ |
Kevin Lubick | d45c781 | 2018-10-02 11:33:52 -0400 | [diff] [blame] | 80 | extra_cflags_cc=[\"-frtti\"] \ |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 81 | extra_cflags=[\"-s\",\"USE_FREETYPE=1\",\"-s\",\"USE_LIBPNG=1\", \"-s\", \"WARN_UNALIGNED=1\", |
| 82 | \"-DIS_WEBGL=1\", \"-DSKNX_NO_SIMD\", |
Kevin Lubick | d45c781 | 2018-10-02 11:33:52 -0400 | [diff] [blame] | 83 | ${EXTRA_CFLAGS} |
| 84 | ] \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 85 | is_debug=false \ |
| 86 | is_official_build=true \ |
| 87 | is_component_build=false \ |
| 88 | target_cpu=\"wasm\" \ |
| 89 | \ |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 90 | skia_use_angle = false \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 91 | skia_use_dng_sdk=false \ |
Kevin Lubick | d45c781 | 2018-10-02 11:33:52 -0400 | [diff] [blame] | 92 | skia_use_egl=true \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 93 | skia_use_expat=false \ |
Kevin Lubick | d45c781 | 2018-10-02 11:33:52 -0400 | [diff] [blame] | 94 | skia_use_fontconfig=false \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 95 | skia_use_freetype=true \ |
| 96 | skia_use_icu=false \ |
Kevin Lubick | d45c781 | 2018-10-02 11:33:52 -0400 | [diff] [blame] | 97 | skia_use_libheif=false \ |
| 98 | skia_use_libjpeg_turbo=false \ |
| 99 | skia_use_libpng=true \ |
| 100 | skia_use_libwebp=false \ |
| 101 | skia_use_lua=false \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 102 | skia_use_piex=false \ |
Kevin Lubick | d45c781 | 2018-10-02 11:33:52 -0400 | [diff] [blame] | 103 | skia_use_vulkan=false \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 104 | skia_use_zlib=true \ |
| 105 | \ |
Kevin Lubick | 93faa67 | 2018-10-10 15:54:53 -0400 | [diff] [blame] | 106 | skia_enable_ccpr=false \ |
Kevin Lubick | 4bf2c26 | 2018-10-15 09:35:54 -0400 | [diff] [blame] | 107 | skia_enable_nvpr=false \ |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 108 | ${GN_GPU} \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 109 | skia_enable_fontmgr_empty=false \ |
| 110 | skia_enable_pdf=false" |
| 111 | |
Kevin Lubick | 8e9750d | 2018-10-09 09:36:35 -0400 | [diff] [blame] | 112 | ${NINJA} -C ${BUILD_DIR} libskia.a |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 113 | |
| 114 | export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js " |
| 115 | |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 116 | echo "Generating final wasm" |
| 117 | |
| 118 | # Skottie doesn't end up in libskia and is currently not its own library |
| 119 | # so we just hack in the .cpp files we need for now. |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 120 | ${EMCXX} \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 121 | $RELEASE_CONF \ |
| 122 | -Iinclude/c \ |
| 123 | -Iinclude/codec \ |
| 124 | -Iinclude/config \ |
| 125 | -Iinclude/core \ |
| 126 | -Iinclude/effects \ |
| 127 | -Iinclude/gpu \ |
| 128 | -Iinclude/gpu/gl \ |
| 129 | -Iinclude/pathops \ |
| 130 | -Iinclude/private \ |
| 131 | -Iinclude/utils/ \ |
| 132 | -Imodules/skottie/include \ |
| 133 | -Imodules/sksg/include \ |
| 134 | -Isrc/core/ \ |
| 135 | -Isrc/utils/ \ |
| 136 | -Isrc/sfnt/ \ |
| 137 | -Itools/fonts \ |
| 138 | -Itools \ |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 139 | $WASM_GPU \ |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 140 | -std=c++14 \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 141 | --bind \ |
| 142 | --pre-js $BASE_DIR/helper.js \ |
| 143 | --pre-js $BASE_DIR/interface.js \ |
Kevin Lubick | d45c781 | 2018-10-02 11:33:52 -0400 | [diff] [blame] | 144 | $BASE_DIR/canvaskit_bindings.cpp \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 145 | $BUILD_DIR/libskia.a \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 146 | tools/fonts/SkTestFontMgr.cpp \ |
| 147 | tools/fonts/SkTestTypeface.cpp \ |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 148 | $WASM_SKOTTIE \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 149 | -s ALLOW_MEMORY_GROWTH=1 \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 150 | -s EXPORT_NAME="CanvasKitInit" \ |
| 151 | -s FORCE_FILESYSTEM=0 \ |
| 152 | -s MODULARIZE=1 \ |
| 153 | -s NO_EXIT_RUNTIME=1 \ |
| 154 | -s STRICT=1 \ |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 155 | -s TOTAL_MEMORY=32MB \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 156 | -s USE_FREETYPE=1 \ |
| 157 | -s USE_LIBPNG=1 \ |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 158 | -s WARN_UNALIGNED=1 \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 159 | -s WASM=1 \ |
Kevin Lubick | 8e9750d | 2018-10-09 09:36:35 -0400 | [diff] [blame] | 160 | -o $BUILD_DIR/canvaskit.js |