1cb93a386Sopenharmony_ci#!/bin/bash
2cb93a386Sopenharmony_ci# Copyright 2018 Google LLC
3cb93a386Sopenharmony_ci#
4cb93a386Sopenharmony_ci# Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci# found in the LICENSE file.
6cb93a386Sopenharmony_ci
7cb93a386Sopenharmony_ciset -ex
8cb93a386Sopenharmony_ci
9cb93a386Sopenharmony_ciBASE_DIR=`cd $(dirname ${BASH_SOURCE[0]}) && pwd`
10cb93a386Sopenharmony_ci# This expects the environment variable EMSDK to be set
11cb93a386Sopenharmony_ciif [[ ! -d $EMSDK ]]; then
12cb93a386Sopenharmony_ci  cat >&2 << "EOF"
13cb93a386Sopenharmony_ciBe sure to set the EMSDK environment variable to the location of Emscripten SDK:
14cb93a386Sopenharmony_ci
15cb93a386Sopenharmony_ci    https://emscripten.org/docs/getting_started/downloads.html
16cb93a386Sopenharmony_ciEOF
17cb93a386Sopenharmony_ci  exit 1
18cb93a386Sopenharmony_cifi
19cb93a386Sopenharmony_ci
20cb93a386Sopenharmony_ci# Navigate to SKIA_HOME from where this file is located.
21cb93a386Sopenharmony_cipushd $BASE_DIR/../..
22cb93a386Sopenharmony_ci
23cb93a386Sopenharmony_cisource $EMSDK/emsdk_env.sh
24cb93a386Sopenharmony_ciEMCC=`which emcc`
25cb93a386Sopenharmony_ciEMCXX=`which em++`
26cb93a386Sopenharmony_ciEMAR=`which emar`
27cb93a386Sopenharmony_ci
28cb93a386Sopenharmony_ciRELEASE_CONF="-Oz --closure 1 -DSK_RELEASE --pre-js $BASE_DIR/release.js"
29cb93a386Sopenharmony_ciEXTRA_CFLAGS="\"-DSK_RELEASE\","
30cb93a386Sopenharmony_ciIS_OFFICIAL_BUILD="true"
31cb93a386Sopenharmony_ci
32cb93a386Sopenharmony_ci# Tracing will be disabled in release/profiling unless this flag is seen. Tracing will
33cb93a386Sopenharmony_ci# be on debug builds always.
34cb93a386Sopenharmony_ciif [[ $@ != *force_tracing* ]] ; then
35cb93a386Sopenharmony_ci  RELEASE_CONF+=" -DSK_DISABLE_TRACING"
36cb93a386Sopenharmony_ci  EXTRA_CFLAGS+="\"-DSK_DISABLE_TRACING\","
37cb93a386Sopenharmony_cifi
38cb93a386Sopenharmony_ci
39cb93a386Sopenharmony_ciif [[ $@ == *debug* ]]; then
40cb93a386Sopenharmony_ci  echo "Building a Debug build"
41cb93a386Sopenharmony_ci  EXTRA_CFLAGS="\"-DSK_DEBUG\","
42cb93a386Sopenharmony_ci  RELEASE_CONF="-O0 --js-opts 0 -s DEMANGLE_SUPPORT=1 -s ASSERTIONS=1 -s GL_ASSERTIONS=1 -g3 \
43cb93a386Sopenharmony_ci                --source-map-base /node_modules/canvaskit/bin/ -DSK_DEBUG --pre-js $BASE_DIR/debug.js"
44cb93a386Sopenharmony_ci  BUILD_DIR=${BUILD_DIR:="out/canvaskit_wasm_debug"}
45cb93a386Sopenharmony_cielif [[ $@ == *profiling* ]]; then
46cb93a386Sopenharmony_ci  echo "Building a build for profiling"
47cb93a386Sopenharmony_ci  RELEASE_CONF+=" --profiling-funcs --closure 0"
48cb93a386Sopenharmony_ci  BUILD_DIR=${BUILD_DIR:="out/canvaskit_wasm_profile"}
49cb93a386Sopenharmony_cielif [[ $@ == *simd* ]]; then
50cb93a386Sopenharmony_ci  echo "Building with SIMD operations"
51cb93a386Sopenharmony_ci  BUILD_DIR=${BUILD_DIR:="out/canvaskit_wasm_experimental_simd"}
52cb93a386Sopenharmony_cielse
53cb93a386Sopenharmony_ci  BUILD_DIR=${BUILD_DIR:="out/canvaskit_wasm"}
54cb93a386Sopenharmony_cifi
55cb93a386Sopenharmony_ci
56cb93a386Sopenharmony_ciif [[ $@ == *simd* ]]; then
57cb93a386Sopenharmony_ci  RELEASE_CONF+=" -msimd128"
58cb93a386Sopenharmony_ci  EXTRA_CFLAGS+="\"-msimd128\","
59cb93a386Sopenharmony_cifi
60cb93a386Sopenharmony_ci
61cb93a386Sopenharmony_cimkdir -p $BUILD_DIR
62cb93a386Sopenharmony_ci# sometimes the .a files keep old symbols around - cleaning them out makes sure
63cb93a386Sopenharmony_ci# we get a fresh build.
64cb93a386Sopenharmony_cirm -f $BUILD_DIR/*.a
65cb93a386Sopenharmony_ci
66cb93a386Sopenharmony_ciGN_GPU="skia_enable_gpu=true skia_gl_standard = \"webgl\""
67cb93a386Sopenharmony_ciGN_GPU_FLAGS="\"-DSK_DISABLE_LEGACY_SHADERCONTEXT\","
68cb93a386Sopenharmony_ciWASM_GPU="-lGL -DSK_SUPPORT_GPU=1 -DSK_GL \
69cb93a386Sopenharmony_ci          -DSK_DISABLE_LEGACY_SHADERCONTEXT --pre-js $BASE_DIR/cpu.js --pre-js $BASE_DIR/gpu.js\
70cb93a386Sopenharmony_ci          -s USE_WEBGL2=1"
71cb93a386Sopenharmony_ciif [[ $@ == *cpu* ]]; then
72cb93a386Sopenharmony_ci  echo "Using the CPU backend instead of the GPU backend"
73cb93a386Sopenharmony_ci  GN_GPU="skia_enable_gpu=false"
74cb93a386Sopenharmony_ci  GN_GPU_FLAGS=""
75cb93a386Sopenharmony_ci  WASM_GPU="-DSK_SUPPORT_GPU=0 -DSK_ENABLE_SKSL --pre-js $BASE_DIR/cpu.js -s USE_WEBGL2=0"
76cb93a386Sopenharmony_cifi
77cb93a386Sopenharmony_ci
78cb93a386Sopenharmony_ciSKP_JS="--pre-js $BASE_DIR/skp.js"
79cb93a386Sopenharmony_ciGN_SKP_FLAGS=""
80cb93a386Sopenharmony_ciWASM_SKP="-DSK_SERIALIZE_SKP"
81cb93a386Sopenharmony_ciif [[ $@ == *no_skp_serialization* ]]; then
82cb93a386Sopenharmony_ci  # This saves about 20kb compressed.
83cb93a386Sopenharmony_ci  SKP_JS=""
84cb93a386Sopenharmony_ci  WASM_SKP=""
85cb93a386Sopenharmony_ci  GN_SKP_FLAGS="\"-DSK_DISABLE_EFFECT_DESERIALIZATION\","
86cb93a386Sopenharmony_cifi
87cb93a386Sopenharmony_ciif [[ $@ == *no_effects_deserialization* ]]; then
88cb93a386Sopenharmony_ci  # This saves about 60kb compressed.
89cb93a386Sopenharmony_ci  echo "disabling effects deserialization"
90cb93a386Sopenharmony_ci  GN_SKP_FLAGS="\"-DSK_DISABLE_EFFECT_DESERIALIZATION\","
91cb93a386Sopenharmony_cifi
92cb93a386Sopenharmony_ci
93cb93a386Sopenharmony_ciSKOTTIE_JS="--pre-js $BASE_DIR/skottie.js"
94cb93a386Sopenharmony_ciSKOTTIE_BINDINGS="$BASE_DIR/skottie_bindings.cpp"
95cb93a386Sopenharmony_ci
96cb93a386Sopenharmony_ciSKOTTIE_LIB="$BUILD_DIR/libskottie.a \
97cb93a386Sopenharmony_ci             $BUILD_DIR/libsksg.a"
98cb93a386Sopenharmony_ci
99cb93a386Sopenharmony_ciif [[ $@ == *no_skottie* ]]; then
100cb93a386Sopenharmony_ci  echo "Omitting Skottie"
101cb93a386Sopenharmony_ci  SKOTTIE_JS=""
102cb93a386Sopenharmony_ci  SKOTTIE_LIB=""
103cb93a386Sopenharmony_ci  SKOTTIE_BINDINGS=""
104cb93a386Sopenharmony_cifi
105cb93a386Sopenharmony_ci
106cb93a386Sopenharmony_ciGN_VIEWER="skia_use_expat=false"
107cb93a386Sopenharmony_ciVIEWER_BINDINGS=""
108cb93a386Sopenharmony_ciVIEWER_LIB=""
109cb93a386Sopenharmony_ci
110cb93a386Sopenharmony_ciif [[ $@ == *viewer* ]]; then
111cb93a386Sopenharmony_ci  echo "Including viewer"
112cb93a386Sopenharmony_ci  GN_VIEWER="skia_use_expat=true"
113cb93a386Sopenharmony_ci  VIEWER_BINDINGS="$BASE_DIR/viewer_bindings.cpp"
114cb93a386Sopenharmony_ci  VIEWER_LIB="$BUILD_DIR/libviewer_wasm.a"
115cb93a386Sopenharmony_ci  IS_OFFICIAL_BUILD="false"
116cb93a386Sopenharmony_cifi
117cb93a386Sopenharmony_ci
118cb93a386Sopenharmony_ciMANAGED_SKOTTIE_BINDINGS="\
119cb93a386Sopenharmony_ci  -DSK_INCLUDE_MANAGED_SKOTTIE=1 \
120cb93a386Sopenharmony_ci  modules/skottie/utils/SkottieUtils.cpp"
121cb93a386Sopenharmony_ciif [[ $@ == *no_managed_skottie* || $@ == *no_skottie* ]]; then
122cb93a386Sopenharmony_ci  echo "Omitting managed Skottie"
123cb93a386Sopenharmony_ci  MANAGED_SKOTTIE_BINDINGS="-DSK_INCLUDE_MANAGED_SKOTTIE=0"
124cb93a386Sopenharmony_cifi
125cb93a386Sopenharmony_ci
126cb93a386Sopenharmony_ciPARTICLES_JS="--pre-js $BASE_DIR/particles.js"
127cb93a386Sopenharmony_ciPARTICLES_BINDINGS="$BASE_DIR/particles_bindings.cpp"
128cb93a386Sopenharmony_ciPARTICLES_LIB="$BUILD_DIR/libparticles.a"
129cb93a386Sopenharmony_ci
130cb93a386Sopenharmony_ciif [[ $@ == *no_particles* ]]; then
131cb93a386Sopenharmony_ci  echo "Omitting Particles"
132cb93a386Sopenharmony_ci  PARTICLES_JS=""
133cb93a386Sopenharmony_ci  PARTICLES_BINDINGS=""
134cb93a386Sopenharmony_ci  PARTICLES_LIB=""
135cb93a386Sopenharmony_cifi
136cb93a386Sopenharmony_ci
137cb93a386Sopenharmony_ciif [[ $@ != *no_particles* || $@ != *no_skottie* ]] ; then
138cb93a386Sopenharmony_ci  PARTICLES_BINDINGS+=" modules/skresources/src/SkResources.cpp"
139cb93a386Sopenharmony_cifi
140cb93a386Sopenharmony_ci
141cb93a386Sopenharmony_ciWASM_PATHOPS="-DSK_INCLUDE_PATHOPS"
142cb93a386Sopenharmony_ciPATHOPS_JS="--pre-js $BASE_DIR/pathops.js"
143cb93a386Sopenharmony_ciif [[ $@ == *no_pathops* ]] ; then
144cb93a386Sopenharmony_ci  # This saves about 2kb compressed.
145cb93a386Sopenharmony_ci  WASM_PATHOPS=""
146cb93a386Sopenharmony_ci  PATHOPS_JS=""
147cb93a386Sopenharmony_cifi
148cb93a386Sopenharmony_ci
149cb93a386Sopenharmony_ciWASM_RT_SHADER="-DSK_INCLUDE_RUNTIME_EFFECT"
150cb93a386Sopenharmony_ciRT_SHADER_JS="--pre-js $BASE_DIR/rt_shader.js"
151cb93a386Sopenharmony_ciif [[ $@ == *no_rt_shader* ]] ; then
152cb93a386Sopenharmony_ci  WASM_RT_SHADER=""
153cb93a386Sopenharmony_ci  RT_SHADER_JS=""
154cb93a386Sopenharmony_cifi
155cb93a386Sopenharmony_ci
156cb93a386Sopenharmony_ciMATRIX_HELPER_JS="--pre-js $BASE_DIR/matrix.js"
157cb93a386Sopenharmony_ciif [[ $@ == *no_matrix* ]]; then
158cb93a386Sopenharmony_ci  echo "Omitting matrix helper code"
159cb93a386Sopenharmony_ci  MATRIX_HELPER_JS=""
160cb93a386Sopenharmony_cifi
161cb93a386Sopenharmony_ci
162cb93a386Sopenharmony_ciHTML_CANVAS_API="--pre-js $BASE_DIR/htmlcanvas/preamble.js \
163cb93a386Sopenharmony_ci--pre-js $BASE_DIR/htmlcanvas/util.js \
164cb93a386Sopenharmony_ci--pre-js $BASE_DIR/htmlcanvas/color.js \
165cb93a386Sopenharmony_ci--pre-js $BASE_DIR/htmlcanvas/font.js \
166cb93a386Sopenharmony_ci--pre-js $BASE_DIR/htmlcanvas/canvas2dcontext.js \
167cb93a386Sopenharmony_ci--pre-js $BASE_DIR/htmlcanvas/htmlcanvas.js \
168cb93a386Sopenharmony_ci--pre-js $BASE_DIR/htmlcanvas/imagedata.js \
169cb93a386Sopenharmony_ci--pre-js $BASE_DIR/htmlcanvas/lineargradient.js \
170cb93a386Sopenharmony_ci--pre-js $BASE_DIR/htmlcanvas/path2d.js \
171cb93a386Sopenharmony_ci--pre-js $BASE_DIR/htmlcanvas/pattern.js \
172cb93a386Sopenharmony_ci--pre-js $BASE_DIR/htmlcanvas/radialgradient.js \
173cb93a386Sopenharmony_ci--pre-js $BASE_DIR/htmlcanvas/postamble.js "
174cb93a386Sopenharmony_ciif [[ $@ == *no_canvas* || $@ == *no_matrix* ]]; then
175cb93a386Sopenharmony_ci  # Note: HTML Canvas bindings depend on the matrix helpers.
176cb93a386Sopenharmony_ci  echo "Omitting bindings for HTML Canvas API"
177cb93a386Sopenharmony_ci  HTML_CANVAS_API=""
178cb93a386Sopenharmony_cifi
179cb93a386Sopenharmony_ci
180cb93a386Sopenharmony_ciGN_FONT="skia_enable_fontmgr_custom_directory=false "
181cb93a386Sopenharmony_ciWOFF2_FONT="skia_use_freetype_woff2=true"
182cb93a386Sopenharmony_ciFONT_CFLAGS=""
183cb93a386Sopenharmony_ciBUILTIN_FONT=""
184cb93a386Sopenharmony_ciFONT_JS="--pre-js $BASE_DIR/font.js"
185cb93a386Sopenharmony_ciif [[ $@ == *no_font* ]]; then
186cb93a386Sopenharmony_ci  echo "Omitting the built-in font(s), font manager and all code dealing with fonts"
187cb93a386Sopenharmony_ci  FONT_CFLAGS="-DSK_NO_FONTS"
188cb93a386Sopenharmony_ci  WOFF2_FONT=""
189cb93a386Sopenharmony_ci  FONT_JS=""
190cb93a386Sopenharmony_ci  GN_FONT+="skia_enable_fontmgr_custom_embedded=false skia_enable_fontmgr_custom_empty=false"
191cb93a386Sopenharmony_cielif [[ $@ == *no_embedded_font* ]]; then
192cb93a386Sopenharmony_ci  echo "Omitting the built-in font(s)"
193cb93a386Sopenharmony_ci  GN_FONT+="skia_enable_fontmgr_custom_embedded=false skia_enable_fontmgr_custom_empty=true"
194cb93a386Sopenharmony_cielse
195cb93a386Sopenharmony_ci  # Generate the font's binary file (which is covered by .gitignore)
196cb93a386Sopenharmony_ci  python tools/embed_resources.py \
197cb93a386Sopenharmony_ci      --name SK_EMBEDDED_FONTS \
198cb93a386Sopenharmony_ci      --input $BASE_DIR/fonts/NotoMono-Regular.ttf \
199cb93a386Sopenharmony_ci      --output $BASE_DIR/fonts/NotoMono-Regular.ttf.cpp \
200cb93a386Sopenharmony_ci      --align 4
201cb93a386Sopenharmony_ci  BUILTIN_FONT="$BASE_DIR/fonts/NotoMono-Regular.ttf.cpp"
202cb93a386Sopenharmony_ci  GN_FONT+="skia_enable_fontmgr_custom_embedded=true skia_enable_fontmgr_custom_empty=false"
203cb93a386Sopenharmony_cifi
204cb93a386Sopenharmony_ci
205cb93a386Sopenharmony_ciif [[ $@ == *no_woff2* ]]; then
206cb93a386Sopenharmony_ci  WOFF2_FONT="skia_use_freetype_woff2=false"
207cb93a386Sopenharmony_cifi
208cb93a386Sopenharmony_ci
209cb93a386Sopenharmony_ciif [[ $@ == *no_alias_font* ]]; then
210cb93a386Sopenharmony_ciEXTRA_CFLAGS+="\"-DCANVASKIT_NO_ALIAS_FONT\","
211cb93a386Sopenharmony_ciFONT_CFLAGS+=" -DCANVASKIT_NO_ALIAS_FONT"
212cb93a386Sopenharmony_cifi
213cb93a386Sopenharmony_ci
214cb93a386Sopenharmony_ciGN_SHAPER="skia_use_icu=true skia_use_system_icu=false skia_use_harfbuzz=true skia_use_system_harfbuzz=false"
215cb93a386Sopenharmony_ciSHAPER_LIB="$BUILD_DIR/libskunicode.a \
216cb93a386Sopenharmony_ci            $BUILD_DIR/libharfbuzz.a \
217cb93a386Sopenharmony_ci            $BUILD_DIR/libicu.a"
218cb93a386Sopenharmony_ciif [[ $@ == *primitive_shaper* ]] || [[ $@ == *no_font* ]]; then
219cb93a386Sopenharmony_ci  echo "Using the primitive shaper instead of the harfbuzz/icu one"
220cb93a386Sopenharmony_ci  GN_SHAPER="skia_use_icu=false skia_use_harfbuzz=false"
221cb93a386Sopenharmony_ci  SHAPER_LIB=""
222cb93a386Sopenharmony_cifi
223cb93a386Sopenharmony_ci
224cb93a386Sopenharmony_ciPARAGRAPH_JS="--pre-js $BASE_DIR/paragraph.js"
225cb93a386Sopenharmony_ciPARAGRAPH_LIB="$BUILD_DIR/libskparagraph.a"
226cb93a386Sopenharmony_ciPARAGRAPH_BINDINGS="-DSK_INCLUDE_PARAGRAPH=1 \
227cb93a386Sopenharmony_ci  $BASE_DIR/paragraph_bindings.cpp \
228cb93a386Sopenharmony_ci  $BASE_DIR/paragraph_bindings_gen.cpp"
229cb93a386Sopenharmony_ci
230cb93a386Sopenharmony_ciif [[ $@ == *no_paragraph* ]] || [[ $@ == *primitive_shaper* ]] || [[ $@ == *no_font* ]]; then
231cb93a386Sopenharmony_ci  echo "Omitting paragraph (must have fonts and non-primitive shaper)"
232cb93a386Sopenharmony_ci  PARAGRAPH_JS=""
233cb93a386Sopenharmony_ci  PARAGRAPH_LIB=""
234cb93a386Sopenharmony_ci  PARAGRAPH_BINDINGS=""
235cb93a386Sopenharmony_cifi
236cb93a386Sopenharmony_ci
237cb93a386Sopenharmony_ciDO_DECODE="true"
238cb93a386Sopenharmony_ciif [[ $@ == *no_codecs* ]]; then
239cb93a386Sopenharmony_ci  echo "Omitting codecs"
240cb93a386Sopenharmony_ci  DO_DECODE="false"
241cb93a386Sopenharmony_ci  ENCODE_PNG="false"
242cb93a386Sopenharmony_ci  ENCODE_JPEG="false"
243cb93a386Sopenharmony_ci  ENCODE_WEBP="false"
244cb93a386Sopenharmony_cielse
245cb93a386Sopenharmony_ci
246cb93a386Sopenharmony_ci  ENCODE_PNG="true"
247cb93a386Sopenharmony_ci  if [[ $@ == *no_encode_png* ]]; then
248cb93a386Sopenharmony_ci    ENCODE_PNG="false"
249cb93a386Sopenharmony_ci  fi
250cb93a386Sopenharmony_ci
251cb93a386Sopenharmony_ci  ENCODE_JPEG="false"
252cb93a386Sopenharmony_ci  if [[ $@ == *force_encode_jpeg* ]]; then
253cb93a386Sopenharmony_ci    ENCODE_JPEG="true"
254cb93a386Sopenharmony_ci  fi
255cb93a386Sopenharmony_ci
256cb93a386Sopenharmony_ci  ENCODE_WEBP="false"
257cb93a386Sopenharmony_ci  if [[ $@ == *force_encode_webp* ]]; then
258cb93a386Sopenharmony_ci    ENCODE_WEBP="true"
259cb93a386Sopenharmony_ci  fi
260cb93a386Sopenharmony_ci
261cb93a386Sopenharmony_cifi # no_codecs
262cb93a386Sopenharmony_ci
263cb93a386Sopenharmony_ci# Turn off exiting while we check for ninja (which may not be on PATH)
264cb93a386Sopenharmony_ciset +e
265cb93a386Sopenharmony_ciNINJA=`which ninja`
266cb93a386Sopenharmony_ciif [[ -z $NINJA ]]; then
267cb93a386Sopenharmony_ci  git clone "https://chromium.googlesource.com/chromium/tools/depot_tools.git" --depth 1 $BUILD_DIR/depot_tools
268cb93a386Sopenharmony_ci  NINJA=$BUILD_DIR/depot_tools/ninja
269cb93a386Sopenharmony_cifi
270cb93a386Sopenharmony_ci# Re-enable error checking
271cb93a386Sopenharmony_ciset -e
272cb93a386Sopenharmony_ci
273cb93a386Sopenharmony_ci./bin/fetch-gn
274cb93a386Sopenharmony_ci
275cb93a386Sopenharmony_ciecho "Compiling bitcode"
276cb93a386Sopenharmony_ci
277cb93a386Sopenharmony_ci# Inspired by https://github.com/Zubnix/skia-wasm-port/blob/master/build_bindings.sh
278cb93a386Sopenharmony_ci./bin/gn gen ${BUILD_DIR} \
279cb93a386Sopenharmony_ci  --args="cc=\"${EMCC}\" \
280cb93a386Sopenharmony_ci  cxx=\"${EMCXX}\" \
281cb93a386Sopenharmony_ci  ar=\"${EMAR}\" \
282cb93a386Sopenharmony_ci  extra_cflags=[\"-s\", \"WARN_UNALIGNED=1\", \"-s\", \"MAIN_MODULE=1\",
283cb93a386Sopenharmony_ci    \"-DSKNX_NO_SIMD\", \"-DSK_DISABLE_AAA\",
284cb93a386Sopenharmony_ci    \"-DSK_FORCE_8_BYTE_ALIGNMENT\",
285cb93a386Sopenharmony_ci    ${GN_GPU_FLAGS}
286cb93a386Sopenharmony_ci    ${GN_SKP_FLAGS}
287cb93a386Sopenharmony_ci    ${EXTRA_CFLAGS}
288cb93a386Sopenharmony_ci  ] \
289cb93a386Sopenharmony_ci  is_debug=false \
290cb93a386Sopenharmony_ci  is_official_build=${IS_OFFICIAL_BUILD} \
291cb93a386Sopenharmony_ci  is_component_build=false \
292cb93a386Sopenharmony_ci  werror=true \
293cb93a386Sopenharmony_ci  target_cpu=\"wasm\" \
294cb93a386Sopenharmony_ci  \
295cb93a386Sopenharmony_ci  skia_use_angle=false \
296cb93a386Sopenharmony_ci  skia_use_dng_sdk=false \
297cb93a386Sopenharmony_ci  skia_use_webgl=true \
298cb93a386Sopenharmony_ci  skia_use_fontconfig=false \
299cb93a386Sopenharmony_ci  skia_use_freetype=true \
300cb93a386Sopenharmony_ci  skia_use_libheif=false \
301cb93a386Sopenharmony_ci  skia_use_libjpeg_turbo_decode=${DO_DECODE} \
302cb93a386Sopenharmony_ci  skia_use_libjpeg_turbo_encode=${ENCODE_JPEG} \
303cb93a386Sopenharmony_ci  skia_use_libpng_decode=${DO_DECODE} \
304cb93a386Sopenharmony_ci  skia_use_libpng_encode=${ENCODE_PNG} \
305cb93a386Sopenharmony_ci  skia_use_libwebp_decode=${DO_DECODE} \
306cb93a386Sopenharmony_ci  skia_use_libwebp_encode=${ENCODE_WEBP} \
307cb93a386Sopenharmony_ci  skia_use_lua=false \
308cb93a386Sopenharmony_ci  skia_use_piex=false \
309cb93a386Sopenharmony_ci  skia_use_system_freetype2=false \
310cb93a386Sopenharmony_ci  skia_use_system_libjpeg_turbo=false \
311cb93a386Sopenharmony_ci  skia_use_system_libpng=false \
312cb93a386Sopenharmony_ci  skia_use_system_libwebp=false \
313cb93a386Sopenharmony_ci  skia_use_system_zlib=false\
314cb93a386Sopenharmony_ci  skia_use_vulkan=false \
315cb93a386Sopenharmony_ci  skia_use_wuffs=true \
316cb93a386Sopenharmony_ci  skia_use_zlib=true \
317cb93a386Sopenharmony_ci  \
318cb93a386Sopenharmony_ci  ${GN_SHAPER} \
319cb93a386Sopenharmony_ci  ${GN_GPU} \
320cb93a386Sopenharmony_ci  ${GN_FONT} \
321cb93a386Sopenharmony_ci  ${WOFF2_FONT} \
322cb93a386Sopenharmony_ci  ${GN_VIEWER} \
323cb93a386Sopenharmony_ci  \
324cb93a386Sopenharmony_ci  skia_enable_skshaper=true \
325cb93a386Sopenharmony_ci  skia_enable_skparagraph=true \
326cb93a386Sopenharmony_ci  skia_enable_pdf=false"
327cb93a386Sopenharmony_ci
328cb93a386Sopenharmony_ci# Build all the libs we will need below
329cb93a386Sopenharmony_ciparse_targets() {
330cb93a386Sopenharmony_ci  for LIBPATH in $@; do
331cb93a386Sopenharmony_ci    basename $LIBPATH
332cb93a386Sopenharmony_ci  done
333cb93a386Sopenharmony_ci}
334cb93a386Sopenharmony_ci${NINJA} -C ${BUILD_DIR} libskia.a libskshaper.a \
335cb93a386Sopenharmony_ci  $(parse_targets $SKOTTIE_LIB $VIEWER_LIB $PARTICLES_LIB $SHAPER_LIB $PARAGRAPH_LIB)
336cb93a386Sopenharmony_ci
337cb93a386Sopenharmony_ciexport EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js "
338cb93a386Sopenharmony_ci
339cb93a386Sopenharmony_ciecho "Generating final wasm"
340cb93a386Sopenharmony_ci
341cb93a386Sopenharmony_ci# Disable '-s STRICT=1' outside of Linux until
342cb93a386Sopenharmony_ci# https://github.com/emscripten-core/emscripten/issues/12118 is resovled.
343cb93a386Sopenharmony_ciSTRICTNESS="-s STRICT=1"
344cb93a386Sopenharmony_ciif [[ `uname` != "Linux" ]]; then
345cb93a386Sopenharmony_ci  echo "Disabling '-s STRICT=1'. See: https://github.com/emscripten-core/emscripten/issues/12118"
346cb93a386Sopenharmony_ci  STRICTNESS=""
347cb93a386Sopenharmony_cifi
348cb93a386Sopenharmony_ci
349cb93a386Sopenharmony_ci# Emscripten prefers that the .a files go last in order, otherwise, it
350cb93a386Sopenharmony_ci# may drop symbols that it incorrectly thinks aren't used. One day,
351cb93a386Sopenharmony_ci# Emscripten will use LLD, which may relax this requirement.
352cb93a386Sopenharmony_ciEMCC_DEBUG=1 ${EMCXX} \
353cb93a386Sopenharmony_ci    $RELEASE_CONF \
354cb93a386Sopenharmony_ci    -I. \
355cb93a386Sopenharmony_ci    -Ithird_party/icu \
356cb93a386Sopenharmony_ci    -Ithird_party/skcms \
357cb93a386Sopenharmony_ci    -Ithird_party/externals/icu/source/common/ \
358cb93a386Sopenharmony_ci    -DSK_DISABLE_AAA \
359cb93a386Sopenharmony_ci    -DSK_FORCE_8_BYTE_ALIGNMENT \
360cb93a386Sopenharmony_ci    -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 \
361cb93a386Sopenharmony_ci    -fno-rtti \
362cb93a386Sopenharmony_ci    $WASM_GPU \
363cb93a386Sopenharmony_ci    $WASM_PATHOPS \
364cb93a386Sopenharmony_ci    $WASM_RT_SHADER \
365cb93a386Sopenharmony_ci    $WASM_SKP \
366cb93a386Sopenharmony_ci    $FONT_CFLAGS \
367cb93a386Sopenharmony_ci    -std=c++17 \
368cb93a386Sopenharmony_ci    --bind \
369cb93a386Sopenharmony_ci    --no-entry \
370cb93a386Sopenharmony_ci    --pre-js $BASE_DIR/preamble.js \
371cb93a386Sopenharmony_ci    --pre-js $BASE_DIR/color.js \
372cb93a386Sopenharmony_ci    --pre-js $BASE_DIR/memory.js \
373cb93a386Sopenharmony_ci    --pre-js $BASE_DIR/util.js \
374cb93a386Sopenharmony_ci    --pre-js $BASE_DIR/interface.js \
375cb93a386Sopenharmony_ci    $MATRIX_HELPER_JS \
376cb93a386Sopenharmony_ci    $PARAGRAPH_JS \
377cb93a386Sopenharmony_ci    $SKOTTIE_JS \
378cb93a386Sopenharmony_ci    $PARTICLES_JS \
379cb93a386Sopenharmony_ci    $PATHOPS_JS \
380cb93a386Sopenharmony_ci    $FONT_JS \
381cb93a386Sopenharmony_ci    $SKP_JS \
382cb93a386Sopenharmony_ci    $RT_SHADER_JS \
383cb93a386Sopenharmony_ci    $HTML_CANVAS_API \
384cb93a386Sopenharmony_ci    --pre-js $BASE_DIR/postamble.js \
385cb93a386Sopenharmony_ci    $BASE_DIR/canvaskit_bindings.cpp \
386cb93a386Sopenharmony_ci    $PARTICLES_BINDINGS \
387cb93a386Sopenharmony_ci    $SKOTTIE_BINDINGS \
388cb93a386Sopenharmony_ci    $VIEWER_BINDINGS \
389cb93a386Sopenharmony_ci    $MANAGED_SKOTTIE_BINDINGS \
390cb93a386Sopenharmony_ci    $PARAGRAPH_BINDINGS \
391cb93a386Sopenharmony_ci    $SKOTTIE_LIB \
392cb93a386Sopenharmony_ci    $VIEWER_LIB \
393cb93a386Sopenharmony_ci    $PARTICLES_LIB \
394cb93a386Sopenharmony_ci    $PARAGRAPH_LIB \
395cb93a386Sopenharmony_ci    $BUILD_DIR/libskshaper.a \
396cb93a386Sopenharmony_ci    $SHAPER_LIB \
397cb93a386Sopenharmony_ci    $BUILD_DIR/libskia.a \
398cb93a386Sopenharmony_ci    $BUILTIN_FONT \
399cb93a386Sopenharmony_ci    -s LLD_REPORT_UNDEFINED \
400cb93a386Sopenharmony_ci    -s ALLOW_MEMORY_GROWTH=1 \
401cb93a386Sopenharmony_ci    -s EXPORT_NAME="CanvasKitInit" \
402cb93a386Sopenharmony_ci    -s EXPORTED_FUNCTIONS=['_malloc','_free'] \
403cb93a386Sopenharmony_ci    -s FORCE_FILESYSTEM=0 \
404cb93a386Sopenharmony_ci    -s FILESYSTEM=0 \
405cb93a386Sopenharmony_ci    -s MODULARIZE=1 \
406cb93a386Sopenharmony_ci    -s NO_EXIT_RUNTIME=1 \
407cb93a386Sopenharmony_ci    -s INITIAL_MEMORY=128MB \
408cb93a386Sopenharmony_ci    -s WASM=1 \
409cb93a386Sopenharmony_ci    $STRICTNESS \
410cb93a386Sopenharmony_ci    -o $BUILD_DIR/canvaskit.js
411