blob: e019de1159c40d41ce5587f97538d03dbd43196c [file] [log] [blame]
Kevin Lubicke1b36fe2018-08-02 11:30:33 -04001#!/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
Kevin Lubick8e9750d2018-10-09 09:36:35 -04007set -ex
Kevin Lubicke1b36fe2018-08-02 11:30:33 -04008
9BASE_DIR=`cd $(dirname ${BASH_SOURCE[0]}) && pwd`
10HTML_SHELL=$BASE_DIR/shell.html
Kevin Lubick30cc00c2018-08-03 10:26:00 -040011BUILD_DIR=${BUILD_DIR:="out/pathkit"}
Kevin Lubick8e9750d2018-10-09 09:36:35 -040012mkdir -p $BUILD_DIR
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040013
14# This expects the environment variable EMSDK to be set
15if [[ ! -d $EMSDK ]]; then
16 echo "Be sure to set the EMSDK environment variable."
17 exit 1
18fi
19
20# Navigate to SKIA_HOME from where this file is located.
21pushd $BASE_DIR/../..
22
Kevin Lubick30cc00c2018-08-03 10:26:00 -040023echo "Putting output in $BUILD_DIR (pwd = `pwd`)"
24
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040025# Run this from $SKIA_HOME, not from the directory this file is in.
26if [[ ! -d ./src ]]; then
27 echo "Cannot locate Skia source. Is the source checkout okay? Exiting."
28 exit 1
29fi
30
31if [[ $@ == *help* ]]; then
32 echo "By default, this script builds a production WASM build of PathKit."
33 echo ""
Kevin Lubick30cc00c2018-08-03 10:26:00 -040034 echo "It is put in ${BUILD_DIR}, configured by the BUILD_DIR environment"
35 echo "variable. Additionally, the EMSDK environment variable must be set."
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040036 echo "This script takes several optional parameters:"
Kevin Lubick641bf872018-08-06 14:49:39 -040037 echo " test = Make a build suitable for running tests or profiling"
38 echo " debug = Make a build suitable for debugging (defines SK_DEBUG)"
Kevin Lubick30cc00c2018-08-03 10:26:00 -040039 echo " asm.js = Build for asm.js instead of WASM (very experimental)"
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040040 echo " serve = starts a webserver allowing a user to navigate to"
41 echo " localhost:8000/pathkit.html to view the demo page."
42 exit 0
43fi
44
45
46# Use -O0 for larger builds (but generally quicker)
47# Use -Oz for (much slower, but smaller/faster) production builds
Kevin Lubick11194ab2018-08-17 13:52:56 -040048export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js "
Kevin Lubickcbcff382018-10-02 09:02:18 -040049RELEASE_CONF="-Oz --closure 1 -s EVAL_CTORS=1 --llvm-lto 3 -s ELIMINATE_DUPLICATE_FUNCTIONS=1 -DSK_RELEASE"
50# It is very important for the -DSK_RELEASE/-DSK_DEBUG to match on the libskia.a, otherwise
51# things like SKDEBUGCODE are sometimes compiled in and sometimes not, which can cause headaches
52# like sizeof() mismatching between .cpp files and .h files.
53EXTRA_CFLAGS="\"-DSK_RELEASE\""
Kevin Lubick641bf872018-08-06 14:49:39 -040054if [[ $@ == *test* ]]; then
55 echo "Building a Testing/Profiling build"
56 RELEASE_CONF="-O2 --profiling -DPATHKIT_TESTING -DSK_RELEASE"
57elif [[ $@ == *debug* ]]; then
58 echo "Building a Debug build"
59 # -g4 creates source maps that can apparently let you see the C++ code
60 # in the browser's debugger.
Kevin Lubickcbcff382018-10-02 09:02:18 -040061 EXTRA_CFLAGS="\"-DSK_DEBUG\""
Kevin Lubickf14a3c02018-08-22 09:35:32 -040062 RELEASE_CONF="-O0 --js-opts 0 -s SAFE_HEAP=1 -s ASSERTIONS=1 -g4 -DPATHKIT_TESTING -DSK_DEBUG"
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040063fi
64
65WASM_CONF="-s WASM=1"
66if [[ $@ == *asm.js* ]]; then
67 echo "Building with asm.js instead of WASM"
Kevin Lubickf14a3c02018-08-22 09:35:32 -040068 WASM_CONF="-s WASM=0 -s ALLOW_MEMORY_GROWTH=1"
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040069fi
70
71OUTPUT="-o $BUILD_DIR/pathkit.js"
Kevin Lubick8e9750d2018-10-09 09:36:35 -040072
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040073source $EMSDK/emsdk_env.sh
Kevin Lubickcbcff382018-10-02 09:02:18 -040074EMCC=`which emcc`
75EMCXX=`which em++`
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040076
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040077
Kevin Lubick8e9750d2018-10-09 09:36:35 -040078# Turn off exiting while we check for ninja (which may not be on PATH)
79set +e
80NINJA=`which ninja`
Kevin Lubickcbcff382018-10-02 09:02:18 -040081if [[ -z $NINJA ]]; then
82 git clone "https://chromium.googlesource.com/chromium/tools/depot_tools.git" --depth 1 $BUILD_DIR/depot_tools
83 NINJA=$BUILD_DIR/depot_tools/ninja
84fi
Kevin Lubick8e9750d2018-10-09 09:36:35 -040085# Re-enable error checking
86set -e
Kevin Lubickcbcff382018-10-02 09:02:18 -040087
88echo "Compiling bitcode"
89
90./bin/fetch-gn
91./bin/gn gen ${BUILD_DIR} \
92 --args="cc=\"${EMCC}\" \
93 cxx=\"${EMCXX}\" \
Kevin Lubicke805b242018-10-10 14:55:01 -040094 extra_cflags=[\"-DSK_DISABLE_READBUFFER=1\",\"-s\", \"WARN_UNALIGNED=1\",
95 ${EXTRA_CFLAGS}
96 ] \
Kevin Lubickcbcff382018-10-02 09:02:18 -040097 is_debug=false \
98 is_official_build=true \
99 is_component_build=false \
Kevin Lubicke805b242018-10-10 14:55:01 -0400100 target_cpu=\"wasm\" "
Kevin Lubickcbcff382018-10-02 09:02:18 -0400101
102${NINJA} -C ${BUILD_DIR} libpathkit.a
103
104echo "Generating WASM"
105
Kevin Lubick8e9750d2018-10-09 09:36:35 -0400106${EMCXX} $RELEASE_CONF -std=c++14 \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400107-Iinclude/config \
108-Iinclude/core \
Kevin Lubick97d6d982018-08-10 15:53:16 -0400109-Iinclude/effects \
110-Iinclude/gpu \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400111-Iinclude/pathops \
112-Iinclude/private \
113-Iinclude/utils \
114-Isrc/core \
Kevin Lubick97d6d982018-08-10 15:53:16 -0400115-Isrc/gpu \
116-Isrc/shaders \
117-Isrc/opts \
118-Isrc/utils \
Kevin Lubicke805b242018-10-10 14:55:01 -0400119-std=c++14 \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400120--bind \
Kevin Lubick644d8e72018-08-09 13:58:04 -0400121--pre-js $BASE_DIR/helper.js \
Kevin Lubick11194ab2018-08-17 13:52:56 -0400122--pre-js $BASE_DIR/chaining.js \
Kevin Lubick275eaff2019-01-04 14:38:29 -0500123--post-js $BASE_DIR/ready.js \
Kevin Lubickcbcff382018-10-02 09:02:18 -0400124-DSK_DISABLE_READBUFFER=1 \
Kevin Lubick641bf872018-08-06 14:49:39 -0400125-fno-rtti -fno-exceptions -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400126$WASM_CONF \
Kevin Lubick641bf872018-08-06 14:49:39 -0400127-s BINARYEN_IGNORE_IMPLICIT_TRAPS=1 \
Kevin Lubick217056c2018-09-20 17:39:31 -0400128-s ERROR_ON_MISSING_LIBRARIES=1 \
129-s ERROR_ON_UNDEFINED_SYMBOLS=1 \
130-s EXPORT_NAME="PathKitInit" \
131-s MODULARIZE=1 \
132-s NO_EXIT_RUNTIME=1 \
133-s NO_FILESYSTEM=1 \
Kevin Lubick641bf872018-08-06 14:49:39 -0400134-s STRICT=1 \
Kevin Lubicke805b242018-10-10 14:55:01 -0400135-s WARN_UNALIGNED=1 \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400136$OUTPUT \
137$BASE_DIR/pathkit_wasm_bindings.cpp \
Kevin Lubickcbcff382018-10-02 09:02:18 -0400138${BUILD_DIR}/libpathkit.a
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400139
140if [[ $@ == *serve* ]]; then
141 pushd $BUILD_DIR
142 python serve.py
143fi
144