blob: f309e2021efa2f12561f40bfd450521d1ca41f82 [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 Lubick217056c2018-09-20 17:39:31 -040030 RELEASE_CONF="-O0 --js-opts 0 -s SAFE_HEAP=1 -s ASSERTIONS=1 -g3 -DPATHKIT_TESTING -DSK_DEBUG"
31fi
32
Kevin Lubick8e9750d2018-10-09 09:36:35 -040033# Turn off exiting while we check for ninja (which may not be on PATH)
34set +e
35NINJA=`which ninja`
36if [[ -z $NINJA ]]; then
37 git clone "https://chromium.googlesource.com/chromium/tools/depot_tools.git" --depth 1 $BUILD_DIR/depot_tools
38 NINJA=$BUILD_DIR/depot_tools/ninja
39fi
40# Re-enable error checking
41set -e
Kevin Lubick217056c2018-09-20 17:39:31 -040042
43echo "Compiling bitcode"
44
Kevin Lubick217056c2018-09-20 17:39:31 -040045# Inspired by https://github.com/Zubnix/skia-wasm-port/blob/master/build_bindings.sh
46./bin/gn gen ${BUILD_DIR} \
47 --args="cc=\"${EMCC}\" \
48 cxx=\"${EMCXX}\" \
Kevin Lubickd45c7812018-10-02 11:33:52 -040049 extra_cflags_cc=[\"-frtti\"] \
50 extra_cflags=[\"-s\",\"USE_FREETYPE=1\",\"-s\",\"USE_LIBPNG=1\", \"-DIS_WEBGL=1\",
51 ${EXTRA_CFLAGS}
52 ] \
Kevin Lubick217056c2018-09-20 17:39:31 -040053 is_debug=false \
54 is_official_build=true \
55 is_component_build=false \
56 target_cpu=\"wasm\" \
57 \
Kevin Lubick217056c2018-09-20 17:39:31 -040058 skia_use_dng_sdk=false \
Kevin Lubickd45c7812018-10-02 11:33:52 -040059 skia_use_egl=true \
Kevin Lubick217056c2018-09-20 17:39:31 -040060 skia_use_expat=false \
Kevin Lubickd45c7812018-10-02 11:33:52 -040061 skia_use_expat=false \
62 skia_use_fontconfig=false \
Kevin Lubick217056c2018-09-20 17:39:31 -040063 skia_use_freetype=true \
64 skia_use_icu=false \
Kevin Lubickd45c7812018-10-02 11:33:52 -040065 skia_use_libheif=false \
66 skia_use_libjpeg_turbo=false \
67 skia_use_libpng=true \
68 skia_use_libwebp=false \
69 skia_use_lua=false \
Kevin Lubick217056c2018-09-20 17:39:31 -040070 skia_use_piex=false \
Kevin Lubickd45c7812018-10-02 11:33:52 -040071 skia_use_vulkan=false \
72 skia_use_vulkan=false \
Kevin Lubick217056c2018-09-20 17:39:31 -040073 skia_use_zlib=true \
74 \
75 skia_enable_gpu=true \
76 skia_enable_fontmgr_empty=false \
77 skia_enable_pdf=false"
78
Kevin Lubick8e9750d2018-10-09 09:36:35 -040079${NINJA} -C ${BUILD_DIR} libskia.a
Kevin Lubick217056c2018-09-20 17:39:31 -040080
81export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js "
82
Kevin Lubick217056c2018-09-20 17:39:31 -040083echo "Generating final wasm"
84
85# Skottie doesn't end up in libskia and is currently not its own library
86# so we just hack in the .cpp files we need for now.
87${EMCC} \
88 $RELEASE_CONF \
89 -Iinclude/c \
90 -Iinclude/codec \
91 -Iinclude/config \
92 -Iinclude/core \
93 -Iinclude/effects \
94 -Iinclude/gpu \
95 -Iinclude/gpu/gl \
96 -Iinclude/pathops \
97 -Iinclude/private \
98 -Iinclude/utils/ \
99 -Imodules/skottie/include \
100 -Imodules/sksg/include \
101 -Isrc/core/ \
102 -Isrc/utils/ \
103 -Isrc/sfnt/ \
104 -Itools/fonts \
105 -Itools \
106 -lEGL \
107 -lGLESv2 \
108 -std=c++11 \
109 --bind \
110 --pre-js $BASE_DIR/helper.js \
111 --pre-js $BASE_DIR/interface.js \
Kevin Lubickd45c7812018-10-02 11:33:52 -0400112 $BASE_DIR/canvaskit_bindings.cpp \
Kevin Lubick217056c2018-09-20 17:39:31 -0400113 $BUILD_DIR/libskia.a \
114 modules/skottie/src/Skottie.cpp \
115 modules/skottie/src/SkottieAdapter.cpp \
116 modules/skottie/src/SkottieAnimator.cpp \
117 modules/skottie/src/SkottieJson.cpp \
118 modules/skottie/src/SkottieLayer.cpp \
119 modules/skottie/src/SkottieLayerEffect.cpp \
120 modules/skottie/src/SkottiePrecompLayer.cpp \
Kevin Lubickd45c7812018-10-02 11:33:52 -0400121 modules/skottie/src/SkottieProperty.cpp \
Kevin Lubick217056c2018-09-20 17:39:31 -0400122 modules/skottie/src/SkottieShapeLayer.cpp \
123 modules/skottie/src/SkottieTextLayer.cpp \
124 modules/skottie/src/SkottieValue.cpp \
125 modules/sksg/src/*.cpp \
126 src/core/SkCubicMap.cpp \
127 src/core/SkTime.cpp \
128 src/pathops/SkOpBuilder.cpp \
Kevin Lubick217056c2018-09-20 17:39:31 -0400129 tools/fonts/SkTestFontMgr.cpp \
130 tools/fonts/SkTestTypeface.cpp \
131 src/utils/SkJSON.cpp \
132 src/utils/SkParse.cpp \
133 -s ALLOW_MEMORY_GROWTH=1 \
134 -s TOTAL_MEMORY=64MB \
135 -s EXPORT_NAME="CanvasKitInit" \
136 -s FORCE_FILESYSTEM=0 \
137 -s MODULARIZE=1 \
138 -s NO_EXIT_RUNTIME=1 \
139 -s STRICT=1 \
140 -s USE_FREETYPE=1 \
141 -s USE_LIBPNG=1 \
142 -s WASM=1 \
Kevin Lubick8e9750d2018-10-09 09:36:35 -0400143 -o $BUILD_DIR/canvaskit.js