blob: 503656507499b3e51630e3bc743356eda3a97a64 [file] [log] [blame]
Kevin Lubick217056c2018-09-20 17:39:31 -04001#!/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
7set -ex
8
9BASE_DIR=`cd $(dirname ${BASH_SOURCE[0]}) && pwd`
10# This expects the environment variable EMSDK to be set
11if [[ ! -d $EMSDK ]]; then
12 echo "Be sure to set the EMSDK environment variable."
13 exit 1
14fi
15
Kevin Lubick217056c2018-09-20 17:39:31 -040016# Navigate to SKIA_HOME from where this file is located.
17pushd $BASE_DIR/../..
18
19source $EMSDK/emsdk_env.sh
Kevin Lubick8e9750d2018-10-09 09:36:35 -040020EMCC=`which emcc`
21EMCXX=`which em++`
Kevin Lubick217056c2018-09-20 17:39:31 -040022
Kevin Lubickd45c7812018-10-02 11:33:52 -040023RELEASE_CONF="-Oz --closure 1 --llvm-lto 3 -DSK_RELEASE"
24EXTRA_CFLAGS="\"-DSK_RELEASE\""
Kevin Lubick217056c2018-09-20 17:39:31 -040025if [[ $@ == *debug* ]]; then
26 echo "Building a Debug build"
Kevin Lubickd45c7812018-10-02 11:33:52 -040027 EXTRA_CFLAGS="\"-DSK_DEBUG\""
Kevin Lubick3d99b1e2018-10-16 10:15:01 -040028 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"}
30else
31 BUILD_DIR=${BUILD_DIR:="out/canvaskit_wasm"}
Kevin Lubick217056c2018-09-20 17:39:31 -040032fi
33
Kevin Lubick3d99b1e2018-10-16 10:15:01 -040034mkdir -p $BUILD_DIR
35
Kevin Lubick53965c92018-10-11 08:51:55 -040036GN_GPU="skia_enable_gpu=true"
Kevin Lubickf2a146c2018-10-17 14:59:35 -040037GN_GPU_FLAGS="\"-DSK_DISABLE_AAA\", \"-DSK_DISABLE_DAA\", \"-DIS_WEBGL=1\", \"-DSK_DISABLE_LEGACY_SHADERCONTEXT\","
Kevin Lubickf20c3492018-10-17 09:46:00 -040038WASM_GPU="-lEGL -lGLESv2 -DSK_SUPPORT_GPU=1 -DSK_DISABLE_AAA -DSK_DISABLE_DAA \
Kevin Lubickf2a146c2018-10-17 14:59:35 -040039 -DSK_DISABLE_LEGACY_SHADERCONTEXT --pre-js $BASE_DIR/gpu.js"
Kevin Lubick3d99b1e2018-10-16 10:15:01 -040040if [[ $@ == *cpu* ]]; then
41 echo "Using the CPU backend instead of the GPU backend"
Kevin Lubick53965c92018-10-11 08:51:55 -040042 GN_GPU="skia_enable_gpu=false"
Kevin Lubick3d99b1e2018-10-16 10:15:01 -040043 GN_GPU_FLAGS=""
Kevin Lubick5b90b842018-10-17 07:57:18 -040044 WASM_GPU="-DSK_SUPPORT_GPU=0 --pre-js $BASE_DIR/cpu.js"
Kevin Lubick53965c92018-10-11 08:51:55 -040045fi
46
47WASM_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 "
65if [[ $@ == *no_skottie* ]]; then
66 echo "Omitting Skottie"
67 WASM_SKOTTIE="-DSK_INCLUDE_SKOTTIE=0"
68fi
69
Kevin Lubick8e9750d2018-10-09 09:36:35 -040070# Turn off exiting while we check for ninja (which may not be on PATH)
71set +e
72NINJA=`which ninja`
73if [[ -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
76fi
77# Re-enable error checking
78set -e
Kevin Lubick217056c2018-09-20 17:39:31 -040079
80echo "Compiling bitcode"
81
Kevin Lubick217056c2018-09-20 17:39:31 -040082# 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 Lubickd45c7812018-10-02 11:33:52 -040086 extra_cflags_cc=[\"-frtti\"] \
Kevin Lubicke805b242018-10-10 14:55:01 -040087 extra_cflags=[\"-s\",\"USE_FREETYPE=1\",\"-s\",\"USE_LIBPNG=1\", \"-s\", \"WARN_UNALIGNED=1\",
Kevin Lubickf20c3492018-10-17 09:46:00 -040088 \"-DSKNX_NO_SIMD\",
89 ${GN_GPU_FLAGS}
Kevin Lubickd45c7812018-10-02 11:33:52 -040090 ${EXTRA_CFLAGS}
91 ] \
Kevin Lubick217056c2018-09-20 17:39:31 -040092 is_debug=false \
93 is_official_build=true \
94 is_component_build=false \
95 target_cpu=\"wasm\" \
96 \
Kevin Lubicke805b242018-10-10 14:55:01 -040097 skia_use_angle = false \
Kevin Lubick217056c2018-09-20 17:39:31 -040098 skia_use_dng_sdk=false \
Kevin Lubickd45c7812018-10-02 11:33:52 -040099 skia_use_egl=true \
Kevin Lubick217056c2018-09-20 17:39:31 -0400100 skia_use_expat=false \
Kevin Lubickd45c7812018-10-02 11:33:52 -0400101 skia_use_fontconfig=false \
Kevin Lubick217056c2018-09-20 17:39:31 -0400102 skia_use_freetype=true \
103 skia_use_icu=false \
Kevin Lubickd45c7812018-10-02 11:33:52 -0400104 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 Lubick217056c2018-09-20 17:39:31 -0400109 skia_use_piex=false \
Kevin Lubickd45c7812018-10-02 11:33:52 -0400110 skia_use_vulkan=false \
Kevin Lubick217056c2018-09-20 17:39:31 -0400111 skia_use_zlib=true \
112 \
Kevin Lubick93faa672018-10-10 15:54:53 -0400113 skia_enable_ccpr=false \
Kevin Lubick4bf2c262018-10-15 09:35:54 -0400114 skia_enable_nvpr=false \
Kevin Lubick32dfdbe2018-10-18 09:47:01 -0400115 skia_enable_skpicture=false \
Kevin Lubick53965c92018-10-11 08:51:55 -0400116 ${GN_GPU} \
Kevin Lubick217056c2018-09-20 17:39:31 -0400117 skia_enable_fontmgr_empty=false \
118 skia_enable_pdf=false"
119
Kevin Lubick8e9750d2018-10-09 09:36:35 -0400120${NINJA} -C ${BUILD_DIR} libskia.a
Kevin Lubick217056c2018-09-20 17:39:31 -0400121
122export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js "
123
Kevin Lubick217056c2018-09-20 17:39:31 -0400124echo "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 Lubicke805b242018-10-10 14:55:01 -0400128${EMCXX} \
Kevin Lubick217056c2018-09-20 17:39:31 -0400129 $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 Lubick53965c92018-10-11 08:51:55 -0400147 $WASM_GPU \
Kevin Lubicke805b242018-10-10 14:55:01 -0400148 -std=c++14 \
Kevin Lubick217056c2018-09-20 17:39:31 -0400149 --bind \
150 --pre-js $BASE_DIR/helper.js \
151 --pre-js $BASE_DIR/interface.js \
Kevin Lubickd45c7812018-10-02 11:33:52 -0400152 $BASE_DIR/canvaskit_bindings.cpp \
Kevin Lubick217056c2018-09-20 17:39:31 -0400153 $BUILD_DIR/libskia.a \
Kevin Lubick217056c2018-09-20 17:39:31 -0400154 tools/fonts/SkTestFontMgr.cpp \
155 tools/fonts/SkTestTypeface.cpp \
Kevin Lubick53965c92018-10-11 08:51:55 -0400156 $WASM_SKOTTIE \
Kevin Lubick217056c2018-09-20 17:39:31 -0400157 -s ALLOW_MEMORY_GROWTH=1 \
Kevin Lubick217056c2018-09-20 17:39:31 -0400158 -s EXPORT_NAME="CanvasKitInit" \
159 -s FORCE_FILESYSTEM=0 \
160 -s MODULARIZE=1 \
161 -s NO_EXIT_RUNTIME=1 \
162 -s STRICT=1 \
Kevin Lubicke805b242018-10-10 14:55:01 -0400163 -s TOTAL_MEMORY=32MB \
Kevin Lubick217056c2018-09-20 17:39:31 -0400164 -s USE_FREETYPE=1 \
165 -s USE_LIBPNG=1 \
Kevin Lubicke805b242018-10-10 14:55:01 -0400166 -s WARN_UNALIGNED=1 \
Kevin Lubick217056c2018-09-20 17:39:31 -0400167 -s WASM=1 \
Kevin Lubick8e9750d2018-10-09 09:36:35 -0400168 -o $BUILD_DIR/canvaskit.js