blob: b7a8653de1e012bd23d5753d844077c3e4f9a9d1 [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 Lubick134be1d2018-10-30 15:05:04 -040028 RELEASE_CONF="-O0 --js-opts 0 -s DEMANGLE_SUPPORT=1 -s ASSERTIONS=1 -s GL_ASSERTIONS=1 -g3 -DPATHKIT_TESTING -DSK_DEBUG"
Kevin Lubick3d99b1e2018-10-16 10:15:01 -040029 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 Lubick2cf29ce2018-10-25 14:46:50 -040037GN_GPU_FLAGS="\"-DIS_WEBGL=1\", \"-DSK_DISABLE_LEGACY_SHADERCONTEXT\","
38WASM_GPU="-lEGL -lGLESv2 -DSK_SUPPORT_GPU=1 \
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 Lubick134be1d2018-10-30 15:05:04 -040070GN_NIMA="skia_enable_nima=true"
71WASM_NIMA="-DSK_INCLUDE_NIMA=1 \
72 experimental/nima/NimaActor.cpp"
73if [[ $@ == *no_nima* ]]; then
74 echo "Omitting Nima"
75 GN_NIMA="skia_enable_nima=false"
76 WASM_NIMA="-DSK_INCLUDE_NIMA=0"
77fi
78
Kevin Lubick006a6f32018-10-19 14:34:34 -040079HTML_CANVAS_API="--pre-js $BASE_DIR/htmlcanvas/canvas2d.js"
80if [[ $@ == *no_canvas* ]]; then
81 echo "Omitting bindings for HTML Canvas API"
82 HTML_CANVAS_API=""
83fi
84
Kevin Lubick8e9750d2018-10-09 09:36:35 -040085# Turn off exiting while we check for ninja (which may not be on PATH)
86set +e
87NINJA=`which ninja`
88if [[ -z $NINJA ]]; then
89 git clone "https://chromium.googlesource.com/chromium/tools/depot_tools.git" --depth 1 $BUILD_DIR/depot_tools
90 NINJA=$BUILD_DIR/depot_tools/ninja
91fi
92# Re-enable error checking
93set -e
Kevin Lubick217056c2018-09-20 17:39:31 -040094
95echo "Compiling bitcode"
96
Kevin Lubick217056c2018-09-20 17:39:31 -040097# Inspired by https://github.com/Zubnix/skia-wasm-port/blob/master/build_bindings.sh
98./bin/gn gen ${BUILD_DIR} \
99 --args="cc=\"${EMCC}\" \
100 cxx=\"${EMCXX}\" \
Kevin Lubickd45c7812018-10-02 11:33:52 -0400101 extra_cflags_cc=[\"-frtti\"] \
Kevin Lubicke805b242018-10-10 14:55:01 -0400102 extra_cflags=[\"-s\",\"USE_FREETYPE=1\",\"-s\",\"USE_LIBPNG=1\", \"-s\", \"WARN_UNALIGNED=1\",
Kevin Lubick2cf29ce2018-10-25 14:46:50 -0400103 \"-DSKNX_NO_SIMD\", \"-DSK_DISABLE_AAA\", \"-DSK_DISABLE_DAA\", \"-DSK_DISABLE_READBUFFER\",
Kevin Lubickf20c3492018-10-17 09:46:00 -0400104 ${GN_GPU_FLAGS}
Kevin Lubickd45c7812018-10-02 11:33:52 -0400105 ${EXTRA_CFLAGS}
106 ] \
Kevin Lubick217056c2018-09-20 17:39:31 -0400107 is_debug=false \
108 is_official_build=true \
109 is_component_build=false \
110 target_cpu=\"wasm\" \
111 \
Kevin Lubicke805b242018-10-10 14:55:01 -0400112 skia_use_angle = false \
Kevin Lubick217056c2018-09-20 17:39:31 -0400113 skia_use_dng_sdk=false \
Kevin Lubickd45c7812018-10-02 11:33:52 -0400114 skia_use_egl=true \
Kevin Lubick217056c2018-09-20 17:39:31 -0400115 skia_use_expat=false \
Kevin Lubickd45c7812018-10-02 11:33:52 -0400116 skia_use_fontconfig=false \
Kevin Lubick217056c2018-09-20 17:39:31 -0400117 skia_use_freetype=true \
118 skia_use_icu=false \
Kevin Lubickd45c7812018-10-02 11:33:52 -0400119 skia_use_libheif=false \
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400120 skia_use_system_libjpeg_turbo = false \
121 skia_use_libjpeg_turbo=true \
Kevin Lubickd45c7812018-10-02 11:33:52 -0400122 skia_use_libpng=true \
123 skia_use_libwebp=false \
124 skia_use_lua=false \
Kevin Lubick217056c2018-09-20 17:39:31 -0400125 skia_use_piex=false \
Kevin Lubickd45c7812018-10-02 11:33:52 -0400126 skia_use_vulkan=false \
Kevin Lubick217056c2018-09-20 17:39:31 -0400127 skia_use_zlib=true \
128 \
Kevin Lubick93faa672018-10-10 15:54:53 -0400129 skia_enable_ccpr=false \
Kevin Lubick4bf2c262018-10-15 09:35:54 -0400130 skia_enable_nvpr=false \
Kevin Lubick32dfdbe2018-10-18 09:47:01 -0400131 skia_enable_skpicture=false \
Kevin Lubick134be1d2018-10-30 15:05:04 -0400132 ${GN_NIMA} \
Kevin Lubickb9d7fb92018-10-19 09:33:12 -0400133 skia_enable_effect_deserialization = false \
Kevin Lubick53965c92018-10-11 08:51:55 -0400134 ${GN_GPU} \
Kevin Lubick217056c2018-09-20 17:39:31 -0400135 skia_enable_fontmgr_empty=false \
136 skia_enable_pdf=false"
137
Kevin Lubick8e9750d2018-10-09 09:36:35 -0400138${NINJA} -C ${BUILD_DIR} libskia.a
Kevin Lubick217056c2018-09-20 17:39:31 -0400139
140export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js "
141
Kevin Lubick217056c2018-09-20 17:39:31 -0400142echo "Generating final wasm"
143
144# Skottie doesn't end up in libskia and is currently not its own library
145# so we just hack in the .cpp files we need for now.
Kevin Lubickb9d7fb92018-10-19 09:33:12 -0400146# Emscripten prefers that libskia.a goes last in order, otherwise, it
147# may drop symbols that it incorrectly thinks aren't used. One day,
148# Emscripten will use LLD, which may relax this requirement.
Kevin Lubicke805b242018-10-10 14:55:01 -0400149${EMCXX} \
Kevin Lubick217056c2018-09-20 17:39:31 -0400150 $RELEASE_CONF \
Kevin Lubick134be1d2018-10-30 15:05:04 -0400151 -Iexperimental \
Kevin Lubick217056c2018-09-20 17:39:31 -0400152 -Iinclude/c \
153 -Iinclude/codec \
154 -Iinclude/config \
155 -Iinclude/core \
156 -Iinclude/effects \
157 -Iinclude/gpu \
158 -Iinclude/gpu/gl \
159 -Iinclude/pathops \
160 -Iinclude/private \
161 -Iinclude/utils/ \
162 -Imodules/skottie/include \
163 -Imodules/sksg/include \
164 -Isrc/core/ \
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400165 -Isrc/gpu/ \
Kevin Lubick217056c2018-09-20 17:39:31 -0400166 -Isrc/sfnt/ \
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400167 -Isrc/shaders/ \
Kevin Lubick134be1d2018-10-30 15:05:04 -0400168 -Isrc/utils/ \
Kevin Lubick217056c2018-09-20 17:39:31 -0400169 -Itools \
Kevin Lubick134be1d2018-10-30 15:05:04 -0400170 -Itools/fonts \
171 -I$BUILD_DIR/gen/third_party/Nima-Cpp/Nima-Cpp \
172 -I$BUILD_DIR/gen/third_party/Nima-Cpp/Nima-Math-Cpp \
Kevin Lubick2cf29ce2018-10-25 14:46:50 -0400173 -DSK_DISABLE_READBUFFER \
174 -DSK_DISABLE_AAA \
175 -DSK_DISABLE_DAA \
Kevin Lubick53965c92018-10-11 08:51:55 -0400176 $WASM_GPU \
Kevin Lubicke805b242018-10-10 14:55:01 -0400177 -std=c++14 \
Kevin Lubick217056c2018-09-20 17:39:31 -0400178 --bind \
179 --pre-js $BASE_DIR/helper.js \
180 --pre-js $BASE_DIR/interface.js \
Kevin Lubick006a6f32018-10-19 14:34:34 -0400181 $HTML_CANVAS_API \
Kevin Lubickd45c7812018-10-02 11:33:52 -0400182 $BASE_DIR/canvaskit_bindings.cpp \
Kevin Lubick217056c2018-09-20 17:39:31 -0400183 tools/fonts/SkTestFontMgr.cpp \
184 tools/fonts/SkTestTypeface.cpp \
Kevin Lubick134be1d2018-10-30 15:05:04 -0400185 $WASM_NIMA \
Kevin Lubick53965c92018-10-11 08:51:55 -0400186 $WASM_SKOTTIE \
Kevin Lubickb9d7fb92018-10-19 09:33:12 -0400187 $BUILD_DIR/libskia.a \
Kevin Lubick217056c2018-09-20 17:39:31 -0400188 -s ALLOW_MEMORY_GROWTH=1 \
Kevin Lubick217056c2018-09-20 17:39:31 -0400189 -s EXPORT_NAME="CanvasKitInit" \
190 -s FORCE_FILESYSTEM=0 \
191 -s MODULARIZE=1 \
192 -s NO_EXIT_RUNTIME=1 \
193 -s STRICT=1 \
Kevin Lubicke805b242018-10-10 14:55:01 -0400194 -s TOTAL_MEMORY=32MB \
Kevin Lubick217056c2018-09-20 17:39:31 -0400195 -s USE_FREETYPE=1 \
196 -s USE_LIBPNG=1 \
Kevin Lubicke805b242018-10-10 14:55:01 -0400197 -s WARN_UNALIGNED=1 \
Kevin Lubick217056c2018-09-20 17:39:31 -0400198 -s WASM=1 \
Kevin Lubick8e9750d2018-10-09 09:36:35 -0400199 -o $BUILD_DIR/canvaskit.js