blob: 67be659dcac59e196b1bc8153d16d6e7d6dd3a0c [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
16BUILD_DIR=${BUILD_DIR:="out/canvaskit_wasm"}
Kevin Lubick8e9750d2018-10-09 09:36:35 -040017mkdir -p $BUILD_DIR
Kevin Lubick217056c2018-09-20 17:39:31 -040018# Navigate to SKIA_HOME from where this file is located.
19pushd $BASE_DIR/../..
20
21source $EMSDK/emsdk_env.sh
Kevin Lubick8e9750d2018-10-09 09:36:35 -040022EMCC=`which emcc`
23EMCXX=`which em++`
Kevin Lubick217056c2018-09-20 17:39:31 -040024
Kevin Lubickd45c7812018-10-02 11:33:52 -040025RELEASE_CONF="-Oz --closure 1 --llvm-lto 3 -DSK_RELEASE"
26EXTRA_CFLAGS="\"-DSK_RELEASE\""
Kevin Lubick217056c2018-09-20 17:39:31 -040027if [[ $@ == *debug* ]]; then
28 echo "Building a Debug build"
Kevin Lubickd45c7812018-10-02 11:33:52 -040029 EXTRA_CFLAGS="\"-DSK_DEBUG\""
Kevin Lubicke805b242018-10-10 14:55:01 -040030 RELEASE_CONF="-O0 --js-opts 0 -s SAFE_HEAP=1 -s ASSERTIONS=1 -s GL_ASSERTIONS=1 -g3 -DPATHKIT_TESTING -DSK_DEBUG"
Kevin Lubick217056c2018-09-20 17:39:31 -040031fi
32
Kevin Lubick53965c92018-10-11 08:51:55 -040033GN_GPU="skia_enable_gpu=true"
34WASM_GPU="-lEGL -lGLESv2 -DSK_SUPPORT_GPU=1"
35if [[ $@ == *no_gpu* ]]; then
36 echo "Omitting the GPU backend"
37 GN_GPU="skia_enable_gpu=false"
38 WASM_GPU="-DSK_SUPPORT_GPU=0"
39fi
40
41WASM_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 "
59if [[ $@ == *no_skottie* ]]; then
60 echo "Omitting Skottie"
61 WASM_SKOTTIE="-DSK_INCLUDE_SKOTTIE=0"
62fi
63
Kevin Lubick8e9750d2018-10-09 09:36:35 -040064# Turn off exiting while we check for ninja (which may not be on PATH)
65set +e
66NINJA=`which ninja`
67if [[ -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
70fi
71# Re-enable error checking
72set -e
Kevin Lubick217056c2018-09-20 17:39:31 -040073
74echo "Compiling bitcode"
75
Kevin Lubick217056c2018-09-20 17:39:31 -040076# 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 Lubickd45c7812018-10-02 11:33:52 -040080 extra_cflags_cc=[\"-frtti\"] \
Kevin Lubicke805b242018-10-10 14:55:01 -040081 extra_cflags=[\"-s\",\"USE_FREETYPE=1\",\"-s\",\"USE_LIBPNG=1\", \"-s\", \"WARN_UNALIGNED=1\",
82 \"-DIS_WEBGL=1\", \"-DSKNX_NO_SIMD\",
Kevin Lubickd45c7812018-10-02 11:33:52 -040083 ${EXTRA_CFLAGS}
84 ] \
Kevin Lubick217056c2018-09-20 17:39:31 -040085 is_debug=false \
86 is_official_build=true \
87 is_component_build=false \
88 target_cpu=\"wasm\" \
89 \
Kevin Lubicke805b242018-10-10 14:55:01 -040090 skia_use_angle = false \
Kevin Lubick217056c2018-09-20 17:39:31 -040091 skia_use_dng_sdk=false \
Kevin Lubickd45c7812018-10-02 11:33:52 -040092 skia_use_egl=true \
Kevin Lubick217056c2018-09-20 17:39:31 -040093 skia_use_expat=false \
Kevin Lubickd45c7812018-10-02 11:33:52 -040094 skia_use_fontconfig=false \
Kevin Lubick217056c2018-09-20 17:39:31 -040095 skia_use_freetype=true \
96 skia_use_icu=false \
Kevin Lubickd45c7812018-10-02 11:33:52 -040097 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 Lubick217056c2018-09-20 17:39:31 -0400102 skia_use_piex=false \
Kevin Lubickd45c7812018-10-02 11:33:52 -0400103 skia_use_vulkan=false \
Kevin Lubick217056c2018-09-20 17:39:31 -0400104 skia_use_zlib=true \
105 \
Kevin Lubick93faa672018-10-10 15:54:53 -0400106 skia_enable_ccpr=false \
Kevin Lubick4bf2c262018-10-15 09:35:54 -0400107 skia_enable_nvpr=false \
Kevin Lubick53965c92018-10-11 08:51:55 -0400108 ${GN_GPU} \
Kevin Lubick217056c2018-09-20 17:39:31 -0400109 skia_enable_fontmgr_empty=false \
110 skia_enable_pdf=false"
111
Kevin Lubick8e9750d2018-10-09 09:36:35 -0400112${NINJA} -C ${BUILD_DIR} libskia.a
Kevin Lubick217056c2018-09-20 17:39:31 -0400113
114export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js "
115
Kevin Lubick217056c2018-09-20 17:39:31 -0400116echo "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 Lubicke805b242018-10-10 14:55:01 -0400120${EMCXX} \
Kevin Lubick217056c2018-09-20 17:39:31 -0400121 $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 Lubick53965c92018-10-11 08:51:55 -0400139 $WASM_GPU \
Kevin Lubicke805b242018-10-10 14:55:01 -0400140 -std=c++14 \
Kevin Lubick217056c2018-09-20 17:39:31 -0400141 --bind \
142 --pre-js $BASE_DIR/helper.js \
143 --pre-js $BASE_DIR/interface.js \
Kevin Lubickd45c7812018-10-02 11:33:52 -0400144 $BASE_DIR/canvaskit_bindings.cpp \
Kevin Lubick217056c2018-09-20 17:39:31 -0400145 $BUILD_DIR/libskia.a \
Kevin Lubick217056c2018-09-20 17:39:31 -0400146 tools/fonts/SkTestFontMgr.cpp \
147 tools/fonts/SkTestTypeface.cpp \
Kevin Lubick53965c92018-10-11 08:51:55 -0400148 $WASM_SKOTTIE \
Kevin Lubick217056c2018-09-20 17:39:31 -0400149 -s ALLOW_MEMORY_GROWTH=1 \
Kevin Lubick217056c2018-09-20 17:39:31 -0400150 -s EXPORT_NAME="CanvasKitInit" \
151 -s FORCE_FILESYSTEM=0 \
152 -s MODULARIZE=1 \
153 -s NO_EXIT_RUNTIME=1 \
154 -s STRICT=1 \
Kevin Lubicke805b242018-10-10 14:55:01 -0400155 -s TOTAL_MEMORY=32MB \
Kevin Lubick217056c2018-09-20 17:39:31 -0400156 -s USE_FREETYPE=1 \
157 -s USE_LIBPNG=1 \
Kevin Lubicke805b242018-10-10 14:55:01 -0400158 -s WARN_UNALIGNED=1 \
Kevin Lubick217056c2018-09-20 17:39:31 -0400159 -s WASM=1 \
Kevin Lubick8e9750d2018-10-09 09:36:35 -0400160 -o $BUILD_DIR/canvaskit.js