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