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 | a96ec09 | 2018-12-17 11:08:36 -0500 | [diff] [blame] | 23 | RELEASE_CONF="-Oz --closure 1 --llvm-lto 3 -DSK_RELEASE --pre-js $BASE_DIR/release.js \ |
| 24 | -DGR_GL_CHECK_ALLOC_WITH_GET_ERROR=0" |
| 25 | EXTRA_CFLAGS="\"-DSK_RELEASE\", \"-DGR_GL_CHECK_ALLOC_WITH_GET_ERROR=0\"," |
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 | a96ec09 | 2018-12-17 11:08:36 -0500 | [diff] [blame] | 29 | RELEASE_CONF="-O0 --js-opts 0 -s DEMANGLE_SUPPORT=1 -s ASSERTIONS=1 -s GL_ASSERTIONS=1 -g4 \ |
| 30 | --source-map-base /node_modules/canvaskit/bin/ -DSK_DEBUG --pre-js $BASE_DIR/debug.js" |
Kevin Lubick | 3d99b1e | 2018-10-16 10:15:01 -0400 | [diff] [blame] | 31 | BUILD_DIR=${BUILD_DIR:="out/canvaskit_wasm_debug"} |
Kevin Lubick | f9910ea | 2018-12-03 14:49:15 -0500 | [diff] [blame] | 32 | elif [[ $@ == *profiling* ]]; then |
| 33 | echo "Building a build for profiling" |
Kevin Lubick | a96ec09 | 2018-12-17 11:08:36 -0500 | [diff] [blame] | 34 | RELEASE_CONF="-O3 --source-map-base /node_modules/canvaskit/bin/ --profiling -g4 -DSK_RELEASE \ |
| 35 | --pre-js $BASE_DIR/release.js -DGR_GL_CHECK_ALLOC_WITH_GET_ERROR=0" |
Kevin Lubick | f9910ea | 2018-12-03 14:49:15 -0500 | [diff] [blame] | 36 | BUILD_DIR=${BUILD_DIR:="out/canvaskit_wasm_profile"} |
Kevin Lubick | 3d99b1e | 2018-10-16 10:15:01 -0400 | [diff] [blame] | 37 | else |
| 38 | BUILD_DIR=${BUILD_DIR:="out/canvaskit_wasm"} |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 39 | fi |
| 40 | |
Kevin Lubick | 3d99b1e | 2018-10-16 10:15:01 -0400 | [diff] [blame] | 41 | mkdir -p $BUILD_DIR |
| 42 | |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 43 | GN_GPU="skia_enable_gpu=true" |
Kevin Lubick | 2cf29ce | 2018-10-25 14:46:50 -0400 | [diff] [blame] | 44 | GN_GPU_FLAGS="\"-DIS_WEBGL=1\", \"-DSK_DISABLE_LEGACY_SHADERCONTEXT\"," |
| 45 | WASM_GPU="-lEGL -lGLESv2 -DSK_SUPPORT_GPU=1 \ |
Kevin Lubick | b07204a | 2018-11-20 14:07:42 -0500 | [diff] [blame] | 46 | -DSK_DISABLE_LEGACY_SHADERCONTEXT --pre-js $BASE_DIR/cpu.js --pre-js $BASE_DIR/gpu.js" |
Kevin Lubick | 3d99b1e | 2018-10-16 10:15:01 -0400 | [diff] [blame] | 47 | if [[ $@ == *cpu* ]]; then |
| 48 | echo "Using the CPU backend instead of the GPU backend" |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 49 | GN_GPU="skia_enable_gpu=false" |
Kevin Lubick | 3d99b1e | 2018-10-16 10:15:01 -0400 | [diff] [blame] | 50 | GN_GPU_FLAGS="" |
Kevin Lubick | 5b90b84 | 2018-10-17 07:57:18 -0400 | [diff] [blame] | 51 | WASM_GPU="-DSK_SUPPORT_GPU=0 --pre-js $BASE_DIR/cpu.js" |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 52 | fi |
| 53 | |
Kevin Lubick | 4683942 | 2019-01-03 14:27:27 -0500 | [diff] [blame] | 54 | WASM_SKOTTIE=" \ |
| 55 | $BASE_DIR/skottie_bindings.cpp \ |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 56 | modules/skottie/src/Skottie.cpp \ |
| 57 | modules/skottie/src/SkottieAdapter.cpp \ |
| 58 | modules/skottie/src/SkottieAnimator.cpp \ |
| 59 | modules/skottie/src/SkottieJson.cpp \ |
| 60 | modules/skottie/src/SkottieLayer.cpp \ |
| 61 | modules/skottie/src/SkottieLayerEffect.cpp \ |
| 62 | modules/skottie/src/SkottiePrecompLayer.cpp \ |
| 63 | modules/skottie/src/SkottieProperty.cpp \ |
| 64 | modules/skottie/src/SkottieShapeLayer.cpp \ |
| 65 | modules/skottie/src/SkottieTextLayer.cpp \ |
| 66 | modules/skottie/src/SkottieValue.cpp \ |
| 67 | modules/sksg/src/*.cpp \ |
Florin Malita | e29d579 | 2019-01-23 11:12:07 -0500 | [diff] [blame] | 68 | modules/skshaper/src/SkShaper.cpp \ |
| 69 | modules/skshaper/src/SkShaper_primitive.cpp \ |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 70 | src/core/SkCubicMap.cpp \ |
| 71 | src/core/SkTime.cpp \ |
| 72 | src/pathops/SkOpBuilder.cpp \ |
| 73 | src/utils/SkJSON.cpp \ |
| 74 | src/utils/SkParse.cpp " |
| 75 | if [[ $@ == *no_skottie* ]]; then |
| 76 | echo "Omitting Skottie" |
Kevin Lubick | 4683942 | 2019-01-03 14:27:27 -0500 | [diff] [blame] | 77 | WASM_SKOTTIE="" |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 78 | fi |
| 79 | |
Florin Malita | c2e85f9 | 2018-11-29 11:38:12 -0500 | [diff] [blame] | 80 | WASM_MANAGED_SKOTTIE="\ |
| 81 | -DSK_INCLUDE_MANAGED_SKOTTIE=1 \ |
| 82 | modules/skottie/utils/SkottieUtils.cpp" |
| 83 | if [[ $@ == *no_managed_skottie* ]]; then |
| 84 | echo "Omitting managed Skottie" |
| 85 | WASM_MANAGED_SKOTTIE="-DSK_INCLUDE_MANAGED_SKOTTIE=0" |
| 86 | fi |
| 87 | |
Kevin Lubick | 53eabf6 | 2018-12-10 12:41:26 -0500 | [diff] [blame] | 88 | HTML_CANVAS_API="--pre-js $BASE_DIR/htmlcanvas/preamble.js \ |
| 89 | --pre-js $BASE_DIR/htmlcanvas/util.js \ |
| 90 | --pre-js $BASE_DIR/htmlcanvas/color.js \ |
| 91 | --pre-js $BASE_DIR/htmlcanvas/font.js \ |
| 92 | --pre-js $BASE_DIR/htmlcanvas/canvas2dcontext.js \ |
| 93 | --pre-js $BASE_DIR/htmlcanvas/htmlcanvas.js \ |
| 94 | --pre-js $BASE_DIR/htmlcanvas/imagedata.js \ |
| 95 | --pre-js $BASE_DIR/htmlcanvas/lineargradient.js \ |
Kevin Lubick | a40f832 | 2018-12-17 16:01:36 -0500 | [diff] [blame] | 96 | --pre-js $BASE_DIR/htmlcanvas/path2d.js \ |
Kevin Lubick | 53eabf6 | 2018-12-10 12:41:26 -0500 | [diff] [blame] | 97 | --pre-js $BASE_DIR/htmlcanvas/pattern.js \ |
| 98 | --pre-js $BASE_DIR/htmlcanvas/radialgradient.js \ |
| 99 | --pre-js $BASE_DIR/htmlcanvas/postamble.js " |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 100 | if [[ $@ == *no_canvas* ]]; then |
| 101 | echo "Omitting bindings for HTML Canvas API" |
| 102 | HTML_CANVAS_API="" |
| 103 | fi |
| 104 | |
Kevin Lubick | ddd0a33 | 2018-12-12 10:35:13 -0500 | [diff] [blame] | 105 | BUILTIN_FONT="$BASE_DIR/fonts/NotoMono-Regular.ttf.cpp" |
| 106 | if [[ $@ == *no_font* ]]; then |
| 107 | echo "Omitting the built-in font(s)" |
| 108 | BUILTIN_FONT="" |
| 109 | else |
| 110 | # Generate the font's binary file (which is covered by .gitignore) |
| 111 | python tools/embed_resources.py \ |
| 112 | --name SK_EMBEDDED_FONTS \ |
| 113 | --input $BASE_DIR/fonts/NotoMono-Regular.ttf \ |
| 114 | --output $BASE_DIR/fonts/NotoMono-Regular.ttf.cpp \ |
| 115 | --align 4 |
| 116 | fi |
| 117 | |
Kevin Lubick | 8e9750d | 2018-10-09 09:36:35 -0400 | [diff] [blame] | 118 | # Turn off exiting while we check for ninja (which may not be on PATH) |
| 119 | set +e |
| 120 | NINJA=`which ninja` |
| 121 | if [[ -z $NINJA ]]; then |
| 122 | git clone "https://chromium.googlesource.com/chromium/tools/depot_tools.git" --depth 1 $BUILD_DIR/depot_tools |
| 123 | NINJA=$BUILD_DIR/depot_tools/ninja |
| 124 | fi |
| 125 | # Re-enable error checking |
| 126 | set -e |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 127 | |
| 128 | echo "Compiling bitcode" |
| 129 | |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 130 | # Inspired by https://github.com/Zubnix/skia-wasm-port/blob/master/build_bindings.sh |
| 131 | ./bin/gn gen ${BUILD_DIR} \ |
| 132 | --args="cc=\"${EMCC}\" \ |
| 133 | cxx=\"${EMCXX}\" \ |
Kevin Lubick | d45c781 | 2018-10-02 11:33:52 -0400 | [diff] [blame] | 134 | extra_cflags_cc=[\"-frtti\"] \ |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 135 | extra_cflags=[\"-s\",\"USE_FREETYPE=1\",\"-s\",\"USE_LIBPNG=1\", \"-s\", \"WARN_UNALIGNED=1\", |
Kevin Lubick | 2cf29ce | 2018-10-25 14:46:50 -0400 | [diff] [blame] | 136 | \"-DSKNX_NO_SIMD\", \"-DSK_DISABLE_AAA\", \"-DSK_DISABLE_DAA\", \"-DSK_DISABLE_READBUFFER\", |
Mike Klein | 5437823 | 2018-11-08 12:08:05 +0000 | [diff] [blame] | 137 | \"-DSK_DISABLE_EFFECT_DESERIALIZATION\", |
Kevin Lubick | f20c349 | 2018-10-17 09:46:00 -0400 | [diff] [blame] | 138 | ${GN_GPU_FLAGS} |
Kevin Lubick | d45c781 | 2018-10-02 11:33:52 -0400 | [diff] [blame] | 139 | ${EXTRA_CFLAGS} |
| 140 | ] \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 141 | is_debug=false \ |
| 142 | is_official_build=true \ |
| 143 | is_component_build=false \ |
| 144 | target_cpu=\"wasm\" \ |
| 145 | \ |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 146 | skia_use_angle = false \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 147 | skia_use_dng_sdk=false \ |
Kevin Lubick | d45c781 | 2018-10-02 11:33:52 -0400 | [diff] [blame] | 148 | skia_use_egl=true \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 149 | skia_use_expat=false \ |
Kevin Lubick | d45c781 | 2018-10-02 11:33:52 -0400 | [diff] [blame] | 150 | skia_use_fontconfig=false \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 151 | skia_use_freetype=true \ |
| 152 | skia_use_icu=false \ |
Kevin Lubick | d45c781 | 2018-10-02 11:33:52 -0400 | [diff] [blame] | 153 | skia_use_libheif=false \ |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 154 | skia_use_system_libjpeg_turbo = false \ |
| 155 | skia_use_libjpeg_turbo=true \ |
Kevin Lubick | d45c781 | 2018-10-02 11:33:52 -0400 | [diff] [blame] | 156 | skia_use_libpng=true \ |
| 157 | skia_use_libwebp=false \ |
| 158 | skia_use_lua=false \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 159 | skia_use_piex=false \ |
Kevin Lubick | d45c781 | 2018-10-02 11:33:52 -0400 | [diff] [blame] | 160 | skia_use_vulkan=false \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 161 | skia_use_zlib=true \ |
| 162 | \ |
Kevin Lubick | 93faa67 | 2018-10-10 15:54:53 -0400 | [diff] [blame] | 163 | skia_enable_ccpr=false \ |
Kevin Lubick | 4bf2c26 | 2018-10-15 09:35:54 -0400 | [diff] [blame] | 164 | skia_enable_nvpr=false \ |
Kevin Lubick | 32dfdbe | 2018-10-18 09:47:01 -0400 | [diff] [blame] | 165 | skia_enable_skpicture=false \ |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 166 | ${GN_GPU} \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 167 | skia_enable_fontmgr_empty=false \ |
| 168 | skia_enable_pdf=false" |
| 169 | |
Kevin Lubick | 8e9750d | 2018-10-09 09:36:35 -0400 | [diff] [blame] | 170 | ${NINJA} -C ${BUILD_DIR} libskia.a |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 171 | |
| 172 | export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js " |
| 173 | |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 174 | echo "Generating final wasm" |
| 175 | |
| 176 | # Skottie doesn't end up in libskia and is currently not its own library |
| 177 | # so we just hack in the .cpp files we need for now. |
Kevin Lubick | b9d7fb9 | 2018-10-19 09:33:12 -0400 | [diff] [blame] | 178 | # Emscripten prefers that libskia.a goes last in order, otherwise, it |
| 179 | # may drop symbols that it incorrectly thinks aren't used. One day, |
| 180 | # Emscripten will use LLD, which may relax this requirement. |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 181 | ${EMCXX} \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 182 | $RELEASE_CONF \ |
Kevin Lubick | 134be1d | 2018-10-30 15:05:04 -0400 | [diff] [blame] | 183 | -Iexperimental \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 184 | -Iinclude/c \ |
| 185 | -Iinclude/codec \ |
| 186 | -Iinclude/config \ |
| 187 | -Iinclude/core \ |
| 188 | -Iinclude/effects \ |
| 189 | -Iinclude/gpu \ |
| 190 | -Iinclude/gpu/gl \ |
| 191 | -Iinclude/pathops \ |
| 192 | -Iinclude/private \ |
| 193 | -Iinclude/utils/ \ |
| 194 | -Imodules/skottie/include \ |
Florin Malita | c2e85f9 | 2018-11-29 11:38:12 -0500 | [diff] [blame] | 195 | -Imodules/skottie/utils \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 196 | -Imodules/sksg/include \ |
Florin Malita | e29d579 | 2019-01-23 11:12:07 -0500 | [diff] [blame] | 197 | -Imodules/skshaper/include \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 198 | -Isrc/core/ \ |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 199 | -Isrc/gpu/ \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 200 | -Isrc/sfnt/ \ |
Kevin Lubick | b5ae3b5 | 2018-11-03 07:51:19 -0400 | [diff] [blame] | 201 | -Isrc/shaders/ \ |
Kevin Lubick | 134be1d | 2018-10-30 15:05:04 -0400 | [diff] [blame] | 202 | -Isrc/utils/ \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 203 | -Itools \ |
Kevin Lubick | 134be1d | 2018-10-30 15:05:04 -0400 | [diff] [blame] | 204 | -Itools/fonts \ |
Kevin Lubick | 2cf29ce | 2018-10-25 14:46:50 -0400 | [diff] [blame] | 205 | -DSK_DISABLE_READBUFFER \ |
| 206 | -DSK_DISABLE_AAA \ |
| 207 | -DSK_DISABLE_DAA \ |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 208 | $WASM_GPU \ |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 209 | -std=c++14 \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 210 | --bind \ |
| 211 | --pre-js $BASE_DIR/helper.js \ |
| 212 | --pre-js $BASE_DIR/interface.js \ |
Kevin Lubick | 65846c0 | 2019-01-04 14:16:19 -0500 | [diff] [blame] | 213 | --post-js $BASE_DIR/ready.js \ |
Kevin Lubick | 006a6f3 | 2018-10-19 14:34:34 -0400 | [diff] [blame] | 214 | $HTML_CANVAS_API \ |
Kevin Lubick | ddd0a33 | 2018-12-12 10:35:13 -0500 | [diff] [blame] | 215 | $BUILTIN_FONT \ |
Kevin Lubick | d45c781 | 2018-10-02 11:33:52 -0400 | [diff] [blame] | 216 | $BASE_DIR/canvaskit_bindings.cpp \ |
Kevin Lubick | 53965c9 | 2018-10-11 08:51:55 -0400 | [diff] [blame] | 217 | $WASM_SKOTTIE \ |
Florin Malita | c2e85f9 | 2018-11-29 11:38:12 -0500 | [diff] [blame] | 218 | $WASM_MANAGED_SKOTTIE \ |
Kevin Lubick | b9d7fb9 | 2018-10-19 09:33:12 -0400 | [diff] [blame] | 219 | $BUILD_DIR/libskia.a \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 220 | -s ALLOW_MEMORY_GROWTH=1 \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 221 | -s EXPORT_NAME="CanvasKitInit" \ |
| 222 | -s FORCE_FILESYSTEM=0 \ |
| 223 | -s MODULARIZE=1 \ |
| 224 | -s NO_EXIT_RUNTIME=1 \ |
| 225 | -s STRICT=1 \ |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 226 | -s TOTAL_MEMORY=32MB \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 227 | -s USE_FREETYPE=1 \ |
| 228 | -s USE_LIBPNG=1 \ |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 229 | -s WARN_UNALIGNED=1 \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 230 | -s WASM=1 \ |
Kevin Lubick | 8e9750d | 2018-10-09 09:36:35 -0400 | [diff] [blame] | 231 | -o $BUILD_DIR/canvaskit.js |