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