Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 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 | |
Kevin Lubick | 8e9750d | 2018-10-09 09:36:35 -0400 | [diff] [blame] | 7 | set -ex |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 8 | |
| 9 | BASE_DIR=`cd $(dirname ${BASH_SOURCE[0]}) && pwd` |
| 10 | HTML_SHELL=$BASE_DIR/shell.html |
Kevin Lubick | 30cc00c | 2018-08-03 10:26:00 -0400 | [diff] [blame] | 11 | BUILD_DIR=${BUILD_DIR:="out/pathkit"} |
Kevin Lubick | 8e9750d | 2018-10-09 09:36:35 -0400 | [diff] [blame] | 12 | mkdir -p $BUILD_DIR |
Kevin Lubick | f76da63 | 2020-01-28 10:39:56 -0500 | [diff] [blame^] | 13 | # sometimes the .a files keep old symbols around - cleaning them out makes sure |
| 14 | # we get a fresh build. |
| 15 | rm -f $BUILD_DIR/*.a |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 16 | |
| 17 | # This expects the environment variable EMSDK to be set |
| 18 | if [[ ! -d $EMSDK ]]; then |
| 19 | echo "Be sure to set the EMSDK environment variable." |
| 20 | exit 1 |
| 21 | fi |
| 22 | |
| 23 | # Navigate to SKIA_HOME from where this file is located. |
| 24 | pushd $BASE_DIR/../.. |
| 25 | |
Kevin Lubick | 30cc00c | 2018-08-03 10:26:00 -0400 | [diff] [blame] | 26 | echo "Putting output in $BUILD_DIR (pwd = `pwd`)" |
| 27 | |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 28 | # Run this from $SKIA_HOME, not from the directory this file is in. |
| 29 | if [[ ! -d ./src ]]; then |
| 30 | echo "Cannot locate Skia source. Is the source checkout okay? Exiting." |
| 31 | exit 1 |
| 32 | fi |
| 33 | |
| 34 | if [[ $@ == *help* ]]; then |
| 35 | echo "By default, this script builds a production WASM build of PathKit." |
| 36 | echo "" |
Kevin Lubick | 30cc00c | 2018-08-03 10:26:00 -0400 | [diff] [blame] | 37 | echo "It is put in ${BUILD_DIR}, configured by the BUILD_DIR environment" |
| 38 | echo "variable. Additionally, the EMSDK environment variable must be set." |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 39 | echo "This script takes several optional parameters:" |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 40 | echo " test = Make a build suitable for running tests or profiling" |
| 41 | echo " debug = Make a build suitable for debugging (defines SK_DEBUG)" |
Kevin Lubick | 30cc00c | 2018-08-03 10:26:00 -0400 | [diff] [blame] | 42 | echo " asm.js = Build for asm.js instead of WASM (very experimental)" |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 43 | echo " serve = starts a webserver allowing a user to navigate to" |
| 44 | echo " localhost:8000/pathkit.html to view the demo page." |
| 45 | exit 0 |
| 46 | fi |
| 47 | |
| 48 | |
| 49 | # Use -O0 for larger builds (but generally quicker) |
| 50 | # Use -Oz for (much slower, but smaller/faster) production builds |
Kevin Lubick | 11194ab | 2018-08-17 13:52:56 -0400 | [diff] [blame] | 51 | export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js " |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 52 | RELEASE_CONF="-Oz --closure 1 -s EVAL_CTORS=1 --llvm-lto 3 -s ELIMINATE_DUPLICATE_FUNCTIONS=1 -DSK_RELEASE" |
| 53 | # It is very important for the -DSK_RELEASE/-DSK_DEBUG to match on the libskia.a, otherwise |
| 54 | # things like SKDEBUGCODE are sometimes compiled in and sometimes not, which can cause headaches |
| 55 | # like sizeof() mismatching between .cpp files and .h files. |
| 56 | EXTRA_CFLAGS="\"-DSK_RELEASE\"" |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 57 | if [[ $@ == *test* ]]; then |
| 58 | echo "Building a Testing/Profiling build" |
| 59 | RELEASE_CONF="-O2 --profiling -DPATHKIT_TESTING -DSK_RELEASE" |
| 60 | elif [[ $@ == *debug* ]]; then |
| 61 | echo "Building a Debug build" |
| 62 | # -g4 creates source maps that can apparently let you see the C++ code |
| 63 | # in the browser's debugger. |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 64 | EXTRA_CFLAGS="\"-DSK_DEBUG\"" |
Kevin Lubick | f14a3c0 | 2018-08-22 09:35:32 -0400 | [diff] [blame] | 65 | RELEASE_CONF="-O0 --js-opts 0 -s SAFE_HEAP=1 -s ASSERTIONS=1 -g4 -DPATHKIT_TESTING -DSK_DEBUG" |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 66 | fi |
| 67 | |
| 68 | WASM_CONF="-s WASM=1" |
| 69 | if [[ $@ == *asm.js* ]]; then |
| 70 | echo "Building with asm.js instead of WASM" |
Kevin Lubick | f14a3c0 | 2018-08-22 09:35:32 -0400 | [diff] [blame] | 71 | WASM_CONF="-s WASM=0 -s ALLOW_MEMORY_GROWTH=1" |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 72 | fi |
| 73 | |
| 74 | OUTPUT="-o $BUILD_DIR/pathkit.js" |
Kevin Lubick | 8e9750d | 2018-10-09 09:36:35 -0400 | [diff] [blame] | 75 | |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 76 | source $EMSDK/emsdk_env.sh |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 77 | EMCC=`which emcc` |
| 78 | EMCXX=`which em++` |
Kevin Lubick | f76da63 | 2020-01-28 10:39:56 -0500 | [diff] [blame^] | 79 | EMAR=`which emar` |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 80 | |
Kevin Lubick | 8e9750d | 2018-10-09 09:36:35 -0400 | [diff] [blame] | 81 | # Turn off exiting while we check for ninja (which may not be on PATH) |
| 82 | set +e |
| 83 | NINJA=`which ninja` |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 84 | if [[ -z $NINJA ]]; then |
| 85 | git clone "https://chromium.googlesource.com/chromium/tools/depot_tools.git" --depth 1 $BUILD_DIR/depot_tools |
| 86 | NINJA=$BUILD_DIR/depot_tools/ninja |
| 87 | fi |
Kevin Lubick | 8e9750d | 2018-10-09 09:36:35 -0400 | [diff] [blame] | 88 | # Re-enable error checking |
| 89 | set -e |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 90 | |
| 91 | echo "Compiling bitcode" |
| 92 | |
| 93 | ./bin/fetch-gn |
| 94 | ./bin/gn gen ${BUILD_DIR} \ |
| 95 | --args="cc=\"${EMCC}\" \ |
| 96 | cxx=\"${EMCXX}\" \ |
Kevin Lubick | f76da63 | 2020-01-28 10:39:56 -0500 | [diff] [blame^] | 97 | ar=\"${EMAR}\" \ |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 98 | extra_cflags=[\"-DSK_DISABLE_READBUFFER=1\",\"-s\", \"WARN_UNALIGNED=1\", |
Kevin Lubick | f76da63 | 2020-01-28 10:39:56 -0500 | [diff] [blame^] | 99 | \"-s\", \"MAIN_MODULE=1\", |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 100 | ${EXTRA_CFLAGS} |
| 101 | ] \ |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 102 | is_debug=false \ |
| 103 | is_official_build=true \ |
| 104 | is_component_build=false \ |
Mike Klein | ba201ae | 2019-04-23 07:38:07 -0500 | [diff] [blame] | 105 | werror=true \ |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 106 | target_cpu=\"wasm\" " |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 107 | |
| 108 | ${NINJA} -C ${BUILD_DIR} libpathkit.a |
| 109 | |
| 110 | echo "Generating WASM" |
| 111 | |
Kevin Lubick | f76da63 | 2020-01-28 10:39:56 -0500 | [diff] [blame^] | 112 | ${EMCXX} $RELEASE_CONF -std=c++17 \ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 113 | -I. \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 114 | --bind \ |
Kevin Lubick | 644d8e7 | 2018-08-09 13:58:04 -0400 | [diff] [blame] | 115 | --pre-js $BASE_DIR/helper.js \ |
Kevin Lubick | 11194ab | 2018-08-17 13:52:56 -0400 | [diff] [blame] | 116 | --pre-js $BASE_DIR/chaining.js \ |
Kevin Lubick | 275eaff | 2019-01-04 14:38:29 -0500 | [diff] [blame] | 117 | --post-js $BASE_DIR/ready.js \ |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 118 | -DSK_DISABLE_READBUFFER=1 \ |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 119 | -fno-rtti -fno-exceptions -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 120 | $WASM_CONF \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 121 | -s ERROR_ON_UNDEFINED_SYMBOLS=1 \ |
| 122 | -s EXPORT_NAME="PathKitInit" \ |
| 123 | -s MODULARIZE=1 \ |
| 124 | -s NO_EXIT_RUNTIME=1 \ |
| 125 | -s NO_FILESYSTEM=1 \ |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 126 | -s STRICT=1 \ |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 127 | -s WARN_UNALIGNED=1 \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 128 | $OUTPUT \ |
| 129 | $BASE_DIR/pathkit_wasm_bindings.cpp \ |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 130 | ${BUILD_DIR}/libpathkit.a |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 131 | |
| 132 | if [[ $@ == *serve* ]]; then |
| 133 | pushd $BUILD_DIR |
| 134 | python serve.py |
| 135 | fi |
| 136 | |