1#!/bin/bash 2# Copyright 2019 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 7 8set -ex 9 10BASE_DIR=`cd $(dirname ${BASH_SOURCE[0]}) && pwd` 11# This expects the environment variable EMSDK to be set 12if [[ ! -d $EMSDK ]]; then 13 echo "Be sure to set the EMSDK environment variable." 14 exit 1 15fi 16 17# Navigate to SKIA_HOME from where this file is located. 18pushd $BASE_DIR/../.. 19 20source $EMSDK/emsdk_env.sh 21EMCC=`which emcc` 22EMCXX=`which em++` 23EMAR=`which emar` 24 25if [[ $@ == *debug* ]]; then 26 echo "Building a Debug build" 27 EXTRA_CFLAGS="\"-DSK_DEBUG\"," 28 RELEASE_CONF="-O0 --js-opts 0 -sDEMANGLE_SUPPORT=1 -sASSERTIONS=1 -sGL_ASSERTIONS=1 -g3 \ 29 --source-map-base /node_modules/debugger/bin/ -DSK_DEBUG" 30 BUILD_DIR=${BUILD_DIR:="out/debugger_wasm_debug"} 31else 32 echo "Building a Release build" 33 EXTRA_CFLAGS="\"-DSK_RELEASE\"," 34 RELEASE_CONF="-Oz --closure 1 --llvm-lto 3 -DSK_RELEASE" 35 BUILD_DIR=${BUILD_DIR:="out/debugger_wasm"} 36fi 37 38mkdir -p $BUILD_DIR 39# sometimes the .a files keep old symbols around - cleaning them out makes sure 40# we get a fresh build. 41rm -f $BUILD_DIR/*.a 42 43BUILTIN_FONT="$BASE_DIR/fonts/NotoMono-Regular.ttf.cpp" 44# Generate the font's binary file (which is covered by .gitignore) 45python tools/embed_resources.py \ 46 --name SK_EMBEDDED_FONTS \ 47 --input $BASE_DIR/fonts/NotoMono-Regular.ttf \ 48 --output $BASE_DIR/fonts/NotoMono-Regular.ttf.cpp \ 49 --align 4 50 51WASM_GPU="-lEGL -lGL -lGLESv2 -DSK_SUPPORT_GPU=1 -DSK_GL -DSK_ENABLE_DUMP_GPU \ 52 -DSK_DISABLE_LEGACY_SHADERCONTEXT --pre-js $BASE_DIR/cpu.js --pre-js $BASE_DIR/gpu.js" 53 54# Turn off exiting while we check for ninja (which may not be on PATH) 55set +e 56NINJA=`which ninja` 57if [[ -z $NINJA ]]; then 58 git clone "https://chromium.googlesource.com/chromium/tools/depot_tools.git" --depth 1 $BUILD_DIR/depot_tools 59 NINJA=$BUILD_DIR/depot_tools/ninja 60fi 61# Re-enable error checking 62set -e 63 64./bin/fetch-gn 65 66echo "Compiling bitcode" 67 68./bin/gn gen ${BUILD_DIR} \ 69 --args="cc=\"${EMCC}\" \ 70 cxx=\"${EMCXX}\" \ 71 ar=\"${EMAR}\" \ 72 extra_cflags_cc=[\"-frtti\"] \ 73 extra_cflags=[\"-sMAIN_MODULE=1\", 74 \"-DSKNX_NO_SIMD\", \"-DSK_DISABLE_AAA\", 75 \"-DSK_FORCE_8_BYTE_ALIGNMENT\", 76 \"-DSK_ENABLE_DUMP_GPU\", \"-DSK_DISABLE_LEGACY_SHADERCONTEXT\", 77 ${EXTRA_CFLAGS} 78 ] \ 79 is_debug=false \ 80 is_official_build=true \ 81 is_component_build=false \ 82 werror=true \ 83 target_cpu=\"wasm\" \ 84 \ 85 skia_use_angle=false \ 86 skia_use_dng_sdk=false \ 87 skia_use_webgl=true \ 88 skia_use_expat=false \ 89 skia_use_fontconfig=false \ 90 skia_use_freetype=true \ 91 skia_use_libheif=false \ 92 skia_use_libjpeg_turbo_decode=true \ 93 skia_use_libjpeg_turbo_encode=false \ 94 skia_use_libpng_decode=true \ 95 skia_use_libpng_encode=false \ 96 skia_use_libwebp_decode=true \ 97 skia_use_libwebp_encode=false \ 98 skia_use_wuffs=true \ 99 skia_use_lua=false \ 100 skia_use_piex=false \ 101 skia_use_system_libpng=false \ 102 skia_use_system_freetype2=false \ 103 skia_use_system_libjpeg_turbo = false \ 104 skia_use_system_libwebp=false \ 105 skia_use_system_zlib=false\ 106 skia_use_vulkan=false \ 107 skia_use_zlib=true \ 108 skia_enable_gpu=true \ 109 skia_gl_standard=\"webgl\" \ 110 skia_enable_tools=false \ 111 skia_enable_skshaper=false \ 112 skia_enable_fontmgr_custom_directory=false \ 113 skia_enable_fontmgr_custom_embedded=true \ 114 skia_enable_fontmgr_custom_empty=false \ 115 skia_enable_pdf=false" 116 117# Build all the libs, we'll link the appropriate ones down below 118${NINJA} -C ${BUILD_DIR} libskia.a libdebugcanvas.a 119 120export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js " 121 122echo "Generating final wasm" 123 124# Emscripten prefers that the .a files go last in order, otherwise, it 125# may drop symbols that it incorrectly thinks aren't used. One day, 126# Emscripten will use LLD, which may relax this requirement. 127EMCC_DEBUG=1 ${EMCXX} \ 128 $RELEASE_CONF \ 129 -I. \ 130 -Ithird_party/icu \ 131 -Ithird_party/skcms \ 132 -DSK_DISABLE_AAA \ 133 -DSK_FORCE_8_BYTE_ALIGNMENT \ 134 -std=c++17 \ 135 $WASM_GPU \ 136 --pre-js $BASE_DIR/helper.js \ 137 --bind \ 138 --no-entry \ 139 $BASE_DIR/fonts/NotoMono-Regular.ttf.cpp \ 140 $BASE_DIR/debugger_bindings.cpp \ 141 $BUILD_DIR/libdebugcanvas.a \ 142 $BUILD_DIR/libskia.a \ 143 -sALLOW_MEMORY_GROWTH=1 \ 144 -sEXPORT_NAME="DebuggerInit" \ 145 -sFORCE_FILESYSTEM=0 \ 146 -sFILESYSTEM=0 \ 147 -sMODULARIZE=1 \ 148 -sNO_EXIT_RUNTIME=1 \ 149 -sSTRICT=1 \ 150 -sINITIAL_MEMORY=128MB \ 151 -sWASM=1 \ 152 -sUSE_WEBGL2=1 \ 153 -o $BUILD_DIR/debugger.js 154