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_ciHTML_SHELL=$BASE_DIR/shell.html 11cb93a386Sopenharmony_ciBUILD_DIR=${BUILD_DIR:="out/pathkit"} 12cb93a386Sopenharmony_cimkdir -p $BUILD_DIR 13cb93a386Sopenharmony_ci# sometimes the .a files keep old symbols around - cleaning them out makes sure 14cb93a386Sopenharmony_ci# we get a fresh build. 15cb93a386Sopenharmony_cirm -f $BUILD_DIR/*.a 16cb93a386Sopenharmony_ci 17cb93a386Sopenharmony_ci# This expects the environment variable EMSDK to be set 18cb93a386Sopenharmony_ciif [[ ! -d $EMSDK ]]; then 19cb93a386Sopenharmony_ci echo "Be sure to set the EMSDK environment variable." 20cb93a386Sopenharmony_ci exit 1 21cb93a386Sopenharmony_cifi 22cb93a386Sopenharmony_ci 23cb93a386Sopenharmony_ci# Navigate to SKIA_HOME from where this file is located. 24cb93a386Sopenharmony_cipushd $BASE_DIR/../.. 25cb93a386Sopenharmony_ci 26cb93a386Sopenharmony_ciecho "Putting output in $BUILD_DIR (pwd = `pwd`)" 27cb93a386Sopenharmony_ci 28cb93a386Sopenharmony_ci# Run this from $SKIA_HOME, not from the directory this file is in. 29cb93a386Sopenharmony_ciif [[ ! -d ./src ]]; then 30cb93a386Sopenharmony_ci echo "Cannot locate Skia source. Is the source checkout okay? Exiting." 31cb93a386Sopenharmony_ci exit 1 32cb93a386Sopenharmony_cifi 33cb93a386Sopenharmony_ci 34cb93a386Sopenharmony_ciif [[ $@ == *help* ]]; then 35cb93a386Sopenharmony_ci echo "By default, this script builds a production WASM build of PathKit." 36cb93a386Sopenharmony_ci echo "" 37cb93a386Sopenharmony_ci echo "It is put in ${BUILD_DIR}, configured by the BUILD_DIR environment" 38cb93a386Sopenharmony_ci echo "variable. Additionally, the EMSDK environment variable must be set." 39cb93a386Sopenharmony_ci echo "This script takes several optional parameters:" 40cb93a386Sopenharmony_ci echo " test = Make a build suitable for running tests or profiling" 41cb93a386Sopenharmony_ci echo " debug = Make a build suitable for debugging (defines SK_DEBUG)" 42cb93a386Sopenharmony_ci echo " asm.js = Build for asm.js instead of WASM (very experimental)" 43cb93a386Sopenharmony_ci echo " serve = starts a webserver allowing a user to navigate to" 44cb93a386Sopenharmony_ci echo " localhost:8000/pathkit.html to view the demo page." 45cb93a386Sopenharmony_ci exit 0 46cb93a386Sopenharmony_cifi 47cb93a386Sopenharmony_ci 48cb93a386Sopenharmony_ci 49cb93a386Sopenharmony_ci# Use -O0 for larger builds (but generally quicker) 50cb93a386Sopenharmony_ci# Use -Oz for (much slower, but smaller/faster) production builds 51cb93a386Sopenharmony_ciexport EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js " 52cb93a386Sopenharmony_ciRELEASE_CONF="-Oz --closure 1 -s EVAL_CTORS=1 -DSK_RELEASE" 53cb93a386Sopenharmony_ci# It is very important for the -DSK_RELEASE/-DSK_DEBUG to match on the libskia.a, otherwise 54cb93a386Sopenharmony_ci# things like SKDEBUGCODE are sometimes compiled in and sometimes not, which can cause headaches 55cb93a386Sopenharmony_ci# like sizeof() mismatching between .cpp files and .h files. 56cb93a386Sopenharmony_ciEXTRA_CFLAGS="\"-DSK_RELEASE\"" 57cb93a386Sopenharmony_ciif [[ $@ == *test* ]]; then 58cb93a386Sopenharmony_ci echo "Building a Testing/Profiling build" 59cb93a386Sopenharmony_ci RELEASE_CONF="-O2 --profiling -DPATHKIT_TESTING -DSK_RELEASE" 60cb93a386Sopenharmony_cielif [[ $@ == *debug* ]]; then 61cb93a386Sopenharmony_ci echo "Building a Debug build" 62cb93a386Sopenharmony_ci EXTRA_CFLAGS="\"-DSK_DEBUG\"" 63cb93a386Sopenharmony_ci RELEASE_CONF="-O0 --js-opts 0 -s SAFE_HEAP=1 -s ASSERTIONS=1 -g3 -DPATHKIT_TESTING -DSK_DEBUG" 64cb93a386Sopenharmony_cifi 65cb93a386Sopenharmony_ci 66cb93a386Sopenharmony_ciWASM_CONF="-s WASM=1" 67cb93a386Sopenharmony_ciif [[ $@ == *asm.js* ]]; then 68cb93a386Sopenharmony_ci echo "Building with asm.js instead of WASM" 69cb93a386Sopenharmony_ci WASM_CONF="-s WASM=0 -s ALLOW_MEMORY_GROWTH=1" 70cb93a386Sopenharmony_cifi 71cb93a386Sopenharmony_ci 72cb93a386Sopenharmony_ciOUTPUT="-o $BUILD_DIR/pathkit.js" 73cb93a386Sopenharmony_ci 74cb93a386Sopenharmony_cisource $EMSDK/emsdk_env.sh 75cb93a386Sopenharmony_ciEMCC=`which emcc` 76cb93a386Sopenharmony_ciEMCXX=`which em++` 77cb93a386Sopenharmony_ciEMAR=`which emar` 78cb93a386Sopenharmony_ci 79cb93a386Sopenharmony_ci# Turn off exiting while we check for ninja (which may not be on PATH) 80cb93a386Sopenharmony_ciset +e 81cb93a386Sopenharmony_ciNINJA=`which ninja` 82cb93a386Sopenharmony_ciif [[ -z $NINJA ]]; then 83cb93a386Sopenharmony_ci git clone "https://chromium.googlesource.com/chromium/tools/depot_tools.git" --depth 1 $BUILD_DIR/depot_tools 84cb93a386Sopenharmony_ci NINJA=$BUILD_DIR/depot_tools/ninja 85cb93a386Sopenharmony_cifi 86cb93a386Sopenharmony_ci# Re-enable error checking 87cb93a386Sopenharmony_ciset -e 88cb93a386Sopenharmony_ci 89cb93a386Sopenharmony_ciecho "Compiling bitcode" 90cb93a386Sopenharmony_ci 91cb93a386Sopenharmony_ci./bin/fetch-gn 92cb93a386Sopenharmony_ci./bin/gn gen ${BUILD_DIR} \ 93cb93a386Sopenharmony_ci --args="cc=\"${EMCC}\" \ 94cb93a386Sopenharmony_ci cxx=\"${EMCXX}\" \ 95cb93a386Sopenharmony_ci ar=\"${EMAR}\" \ 96cb93a386Sopenharmony_ci extra_cflags=[\"-s\", \"WARN_UNALIGNED=1\", 97cb93a386Sopenharmony_ci \"-s\", \"MAIN_MODULE=1\", 98cb93a386Sopenharmony_ci ${EXTRA_CFLAGS} 99cb93a386Sopenharmony_ci ] \ 100cb93a386Sopenharmony_ci is_debug=false \ 101cb93a386Sopenharmony_ci is_official_build=true \ 102cb93a386Sopenharmony_ci is_component_build=false \ 103cb93a386Sopenharmony_ci werror=true \ 104cb93a386Sopenharmony_ci target_cpu=\"wasm\" " 105cb93a386Sopenharmony_ci 106cb93a386Sopenharmony_ci${NINJA} -C ${BUILD_DIR} libpathkit.a 107cb93a386Sopenharmony_ci 108cb93a386Sopenharmony_ciecho "Generating WASM" 109cb93a386Sopenharmony_ci 110cb93a386Sopenharmony_ci${EMCXX} $RELEASE_CONF -std=c++17 \ 111cb93a386Sopenharmony_ci-I. \ 112cb93a386Sopenharmony_ci--bind \ 113cb93a386Sopenharmony_ci--no-entry \ 114cb93a386Sopenharmony_ci--pre-js $BASE_DIR/helper.js \ 115cb93a386Sopenharmony_ci--pre-js $BASE_DIR/chaining.js \ 116cb93a386Sopenharmony_ci-fno-rtti -fno-exceptions -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 \ 117cb93a386Sopenharmony_ci$WASM_CONF \ 118cb93a386Sopenharmony_ci-s ERROR_ON_UNDEFINED_SYMBOLS=1 \ 119cb93a386Sopenharmony_ci-s EXPORT_NAME="PathKitInit" \ 120cb93a386Sopenharmony_ci-s MODULARIZE=1 \ 121cb93a386Sopenharmony_ci-s NO_EXIT_RUNTIME=1 \ 122cb93a386Sopenharmony_ci-s NO_FILESYSTEM=1 \ 123cb93a386Sopenharmony_ci-s STRICT=1 \ 124cb93a386Sopenharmony_ci$OUTPUT \ 125cb93a386Sopenharmony_ci$BASE_DIR/pathkit_wasm_bindings.cpp \ 126cb93a386Sopenharmony_ci${BUILD_DIR}/libpathkit.a 127cb93a386Sopenharmony_ci 128cb93a386Sopenharmony_ci 129