1#!/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 9# Navigate to SKIA_HOME from where this file is located. 10BASE_DIR=`cd $(dirname ${BASH_SOURCE[0]}) && pwd` 11pushd $BASE_DIR/../.. 12./bin/fetch-gn 13 14IS_OFFICIAL_BUILD="true" 15IS_DEBUG="false" 16FORCE_TRACING="false" 17PROFILE_BUILD="false" 18# Tracing will be disabled in release/profiling unless this flag is seen. Tracing will 19# be on debug builds always. 20if [[ $@ != *force_tracing* ]] ; then 21 FORCE_TRACING="true" 22fi 23 24if [[ $@ == *debug_build* ]]; then 25 echo "Building a Debug build" 26 IS_DEBUG="true" 27 IS_OFFICIAL_BUILD="false" 28 BUILD_DIR=${BUILD_DIR:="out/canvaskit_wasm_debug"} 29elif [[ $@ == *profiling* ]]; then 30 echo "Building a build for profiling" 31 PROFILE_BUILD="true" 32 BUILD_DIR=${BUILD_DIR:="out/canvaskit_wasm_profile"} 33else 34 BUILD_DIR=${BUILD_DIR:="out/canvaskit_wasm"} 35fi 36 37mkdir -p $BUILD_DIR 38# sometimes the .a files keep old symbols around - cleaning them out makes sure 39# we get a fresh build. 40rm -f $BUILD_DIR/*.a 41 42ENABLE_GANESH="true" 43ENABLE_GRAPHITE="false" 44ENABLE_WEBGL="false" 45ENABLE_WEBGPU="false" 46if [[ $@ == *cpu* ]]; then 47 echo "Using the CPU backend instead of the GPU backend" 48 ENABLE_GANESH="false" 49elif [[ $@ == *webgpu* ]]; then 50 echo "Using WebGPU instead of WebGL" 51 ENABLE_WEBGPU="true" 52 ENABLE_GRAPHITE="true" 53 ENABLE_GANESH="false" 54else 55 ENABLE_WEBGL="true" 56fi 57 58SERIALIZE_SKP="true" 59if [[ $@ == *no_skp_serialization* ]]; then 60 # This saves about 20kb compressed. 61 echo "disabling SKP serialization" 62 SERIALIZE_SKP="false" 63fi 64DESERIALIZE_EFFECTS="true" 65if [[ $@ == *no_effects_deserialization* ]]; then 66 # This saves about 60kb compressed. 67 echo "disabling effects deserialization" 68 DESERIALIZE_EFFECTS="false" 69fi 70 71ENABLE_SKOTTIE="true" 72if [[ $@ == *no_skottie* ]]; then 73 echo "Omitting Skottie" 74 ENABLE_SKOTTIE="false" 75fi 76 77INCLUDE_VIEWER="false" 78USE_EXPAT="false" 79if [[ $@ == *viewer* ]]; then 80 echo "Including viewer" 81 INCLUDE_VIEWER="true" 82 USE_EXPAT="true" 83 IS_OFFICIAL_BUILD="false" 84fi 85 86ENABLE_PATHOPS="true" 87if [[ $@ == *no_pathops* ]] ; then 88 # This saves about 2kb compressed. 89 echo "Omitting PathOps" 90 ENABLE_PATHOPS="false" 91fi 92 93ENABLE_MATRIX="true" 94if [[ $@ == *no_matrix* ]]; then 95 echo "Omitting matrix helper code" 96 ENABLE_MATRIX="false" 97fi 98 99ENABLE_CANVAS="true" 100if [[ $@ == *no_canvas* || $@ == *no_matrix* ]]; then 101 # Note: HTML Canvas bindings depend on the matrix helpers. 102 echo "Omitting bindings for HTML Canvas API" 103 ENABLE_CANVAS="false" 104fi 105 106GN_FONT="skia_enable_fontmgr_custom_directory=false " 107WOFF2_FONT="skia_use_freetype_woff2=true" 108ENABLE_FONT="true" 109ENABLE_EMBEDDED_FONT="true" 110if [[ $@ == *no_font* ]]; then 111 echo "Omitting the built-in font(s), font manager and all code dealing with fonts" 112 ENABLE_FONT="false" 113 ENABLE_EMBEDDED_FONT="false" 114 GN_FONT+="skia_enable_fontmgr_custom_embedded=false skia_enable_fontmgr_custom_empty=false " 115else 116 if [[ $@ == *no_embedded_font* ]]; then 117 echo "Omitting the built-in font(s)" 118 ENABLE_EMBEDDED_FONT="false" 119 fi 120 # Generate the font's binary file (which is covered by .gitignore) 121 GN_FONT+="skia_enable_fontmgr_custom_embedded=true skia_enable_fontmgr_custom_empty=true " 122fi 123 124if [[ $@ == *no_woff2* ]]; then 125 WOFF2_FONT="skia_use_freetype_woff2=false" 126fi 127 128ENABLE_ALIAS_FONT="true" 129if [[ $@ == *no_alias_font* ]]; then 130 ENABLE_ALIAS_FONT="false" 131fi 132 133LEGACY_DRAW_VERTICES="false" 134if [[ $@ == *legacy_draw_vertices* ]]; then 135 LEGACY_DRAW_VERTICES="true" 136fi 137 138DEBUGGER_ENABLED="false" 139if [[ $@ == *enable_debugger* ]]; then 140 DEBUGGER_ENABLED="true" 141fi 142 143GN_SHAPER="skia_use_icu=true skia_use_client_icu=false skia_use_libgrapheme=false skia_use_icu4x=false skia_use_system_icu=false skia_use_harfbuzz=true skia_use_system_harfbuzz=false" 144if [[ $@ == *primitive_shaper* ]] || [[ $@ == *no_font* ]]; then 145 echo "Using the primitive shaper instead of the harfbuzz/icu one" 146 GN_SHAPER="skia_use_icu=false skia_use_harfbuzz=false" 147fi 148 149if [[ $@ == *client_unicode* ]] ; then 150 echo "Using the client-provided skunicode data and harfbuz instead of the icu-provided data" 151 GN_SHAPER="skia_use_icu=false skia_use_client_icu=true skia_use_libgrapheme=false skia_use_icu4x=false skia_use_harfbuzz=true skia_use_system_harfbuzz=false" 152fi 153 154ENABLE_PARAGRAPH="true" 155if [[ $@ == *no_paragraph* ]] || [[ $@ == *primitive_shaper* ]] || [[ $@ == *no_font* ]]; then 156 echo "Omitting paragraph (must have fonts and non-primitive shaper)" 157 ENABLE_PARAGRAPH="false" 158fi 159 160DO_DECODE="true" 161if [[ $@ == *no_codecs* ]]; then 162 echo "Omitting codecs" 163 DO_DECODE="false" 164 ENCODE_JPEG="false" 165 ENCODE_PNG="false" 166 ENCODE_WEBP="false" 167 NO_ENCODE_JPEG="true" 168 NO_ENCODE_PNG="true" 169 NO_ENCODE_WEBP="true" 170else 171 172 ENCODE_PNG="true" 173 NO_ENCODE_PNG="false" 174 if [[ $@ == *no_encode_png* ]]; then 175 ENCODE_PNG="false" 176 NO_ENCODE_PNG="true" 177 fi 178 179 ENCODE_JPEG="true" 180 NO_ENCODE_JPEG="false" 181 if [[ $@ == *no_encode_jpeg* ]]; then 182 ENCODE_JPEG="false" 183 NO_ENCODE_JPEG="true" 184 fi 185 186 ENCODE_WEBP="true" 187 NO_ENCODE_WEBP="false" 188 if [[ $@ == *no_encode_webp* ]]; then 189 ENCODE_WEBP="false" 190 NO_ENCODE_WEBP="true" 191 fi 192 193fi # no_codecs 194 195./bin/fetch-ninja 196NINJA=third_party/ninja/ninja 197 198echo "Compiling" 199 200./bin/gn gen ${BUILD_DIR} \ 201 --args="is_debug=${IS_DEBUG} \ 202 is_official_build=${IS_OFFICIAL_BUILD} \ 203 is_component_build=false \ 204 is_trivial_abi=true \ 205 werror=true \ 206 target_cpu=\"wasm\" \ 207 \ 208 skia_use_angle=false \ 209 skia_use_dng_sdk=false \ 210 skia_use_dawn=${ENABLE_WEBGPU} \ 211 skia_use_webgl=${ENABLE_WEBGL} \ 212 skia_use_webgpu=${ENABLE_WEBGPU} \ 213 skia_use_expat=${USE_EXPAT} \ 214 skia_use_fontconfig=false \ 215 skia_use_freetype=true \ 216 skia_use_libheif=false \ 217 skia_use_libjpeg_turbo_decode=${DO_DECODE} \ 218 skia_use_libjpeg_turbo_encode=${ENCODE_JPEG} \ 219 skia_use_no_jpeg_encode=${NO_ENCODE_JPEG} \ 220 skia_use_libpng_decode=${DO_DECODE} \ 221 skia_use_libpng_encode=${ENCODE_PNG} \ 222 skia_use_no_png_encode=${NO_ENCODE_PNG} \ 223 skia_use_libwebp_decode=${DO_DECODE} \ 224 skia_use_libwebp_encode=${ENCODE_WEBP} \ 225 skia_use_no_webp_encode=${NO_ENCODE_WEBP} \ 226 skia_use_lua=false \ 227 skia_use_piex=false \ 228 skia_use_system_freetype2=false \ 229 skia_use_system_libjpeg_turbo=false \ 230 skia_use_system_libpng=false \ 231 skia_use_system_libwebp=false \ 232 skia_use_system_zlib=false\ 233 skia_use_vulkan=false \ 234 skia_use_wuffs=true \ 235 skia_use_zlib=true \ 236 skia_enable_ganesh=${ENABLE_GANESH} \ 237 skia_enable_graphite=${ENABLE_GRAPHITE} \ 238 skia_build_for_debugger=${DEBUGGER_ENABLED} \ 239 skia_enable_skottie=${ENABLE_SKOTTIE} \ 240 \ 241 ${GN_SHAPER} \ 242 ${GN_FONT} \ 243 ${WOFF2_FONT} \ 244 \ 245 skia_enable_skshaper=true \ 246 skia_enable_skparagraph=true \ 247 skia_enable_pdf=false \ 248 skia_canvaskit_enable_rt_shader=true \ 249 skia_canvaskit_force_tracing=${FORCE_TRACING} \ 250 skia_canvaskit_profile_build=${PROFILE_BUILD} \ 251 skia_canvaskit_enable_skp_serialization=${SERIALIZE_SKP} \ 252 skia_canvaskit_enable_effects_deserialization=${DESERIALIZE_EFFECTS} \ 253 skia_canvaskit_include_viewer=${INCLUDE_VIEWER} \ 254 skia_canvaskit_enable_pathops=${ENABLE_PATHOPS} \ 255 skia_canvaskit_enable_matrix_helper=${ENABLE_MATRIX} \ 256 skia_canvaskit_enable_canvas_bindings=${ENABLE_CANVAS} \ 257 skia_canvaskit_enable_font=${ENABLE_FONT} \ 258 skia_canvaskit_enable_embedded_font=${ENABLE_EMBEDDED_FONT} \ 259 skia_canvaskit_enable_alias_font=${ENABLE_ALIAS_FONT} \ 260 skia_canvaskit_legacy_draw_vertices_blend_mode=${LEGACY_DRAW_VERTICES} \ 261 skia_canvaskit_enable_debugger=${DEBUGGER_ENABLED} \ 262 skia_canvaskit_enable_paragraph=${ENABLE_PARAGRAPH} \ 263 skia_canvaskit_enable_webgl=${ENABLE_WEBGL} \ 264 skia_canvaskit_enable_webgpu=${ENABLE_WEBGPU}" 265 266${NINJA} -C ${BUILD_DIR} canvaskit.js 267