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