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 | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 13 | |
| 14 | # This expects the environment variable EMSDK to be set |
| 15 | if [[ ! -d $EMSDK ]]; then |
| 16 | echo "Be sure to set the EMSDK environment variable." |
| 17 | exit 1 |
| 18 | fi |
| 19 | |
| 20 | # Navigate to SKIA_HOME from where this file is located. |
| 21 | pushd $BASE_DIR/../.. |
| 22 | |
Kevin Lubick | 30cc00c | 2018-08-03 10:26:00 -0400 | [diff] [blame] | 23 | echo "Putting output in $BUILD_DIR (pwd = `pwd`)" |
| 24 | |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 25 | # Run this from $SKIA_HOME, not from the directory this file is in. |
| 26 | if [[ ! -d ./src ]]; then |
| 27 | echo "Cannot locate Skia source. Is the source checkout okay? Exiting." |
| 28 | exit 1 |
| 29 | fi |
| 30 | |
| 31 | if [[ $@ == *help* ]]; then |
| 32 | echo "By default, this script builds a production WASM build of PathKit." |
| 33 | echo "" |
Kevin Lubick | 30cc00c | 2018-08-03 10:26:00 -0400 | [diff] [blame] | 34 | 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 Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 36 | echo "This script takes several optional parameters:" |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 37 | echo " test = Make a build suitable for running tests or profiling" |
| 38 | echo " debug = Make a build suitable for debugging (defines SK_DEBUG)" |
Kevin Lubick | 30cc00c | 2018-08-03 10:26:00 -0400 | [diff] [blame] | 39 | echo " asm.js = Build for asm.js instead of WASM (very experimental)" |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 40 | 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 |
| 43 | fi |
| 44 | |
| 45 | |
| 46 | # Use -O0 for larger builds (but generally quicker) |
| 47 | # Use -Oz for (much slower, but smaller/faster) production builds |
Kevin Lubick | 11194ab | 2018-08-17 13:52:56 -0400 | [diff] [blame] | 48 | export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js " |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 49 | RELEASE_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. |
| 53 | EXTRA_CFLAGS="\"-DSK_RELEASE\"" |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 54 | if [[ $@ == *test* ]]; then |
| 55 | echo "Building a Testing/Profiling build" |
| 56 | RELEASE_CONF="-O2 --profiling -DPATHKIT_TESTING -DSK_RELEASE" |
| 57 | elif [[ $@ == *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 Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 61 | EXTRA_CFLAGS="\"-DSK_DEBUG\"" |
Kevin Lubick | f14a3c0 | 2018-08-22 09:35:32 -0400 | [diff] [blame] | 62 | 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] | 63 | fi |
| 64 | |
| 65 | WASM_CONF="-s WASM=1" |
| 66 | if [[ $@ == *asm.js* ]]; then |
| 67 | echo "Building with asm.js instead of WASM" |
Kevin Lubick | f14a3c0 | 2018-08-22 09:35:32 -0400 | [diff] [blame] | 68 | WASM_CONF="-s WASM=0 -s ALLOW_MEMORY_GROWTH=1" |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 69 | fi |
| 70 | |
| 71 | OUTPUT="-o $BUILD_DIR/pathkit.js" |
Kevin Lubick | 8e9750d | 2018-10-09 09:36:35 -0400 | [diff] [blame] | 72 | |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 73 | source $EMSDK/emsdk_env.sh |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 74 | EMCC=`which emcc` |
| 75 | EMCXX=`which em++` |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 76 | |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 77 | |
Kevin Lubick | 8e9750d | 2018-10-09 09:36:35 -0400 | [diff] [blame] | 78 | # Turn off exiting while we check for ninja (which may not be on PATH) |
| 79 | set +e |
| 80 | NINJA=`which ninja` |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 81 | if [[ -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 |
| 84 | fi |
Kevin Lubick | 8e9750d | 2018-10-09 09:36:35 -0400 | [diff] [blame] | 85 | # Re-enable error checking |
| 86 | set -e |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 87 | |
| 88 | echo "Compiling bitcode" |
| 89 | |
| 90 | ./bin/fetch-gn |
| 91 | ./bin/gn gen ${BUILD_DIR} \ |
| 92 | --args="cc=\"${EMCC}\" \ |
| 93 | cxx=\"${EMCXX}\" \ |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 94 | extra_cflags=[\"-DSK_DISABLE_READBUFFER=1\",\"-s\", \"WARN_UNALIGNED=1\", |
| 95 | ${EXTRA_CFLAGS} |
| 96 | ] \ |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 97 | is_debug=false \ |
| 98 | is_official_build=true \ |
| 99 | is_component_build=false \ |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 100 | target_cpu=\"wasm\" " |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 101 | |
| 102 | ${NINJA} -C ${BUILD_DIR} libpathkit.a |
| 103 | |
| 104 | echo "Generating WASM" |
| 105 | |
Kevin Lubick | 8e9750d | 2018-10-09 09:36:35 -0400 | [diff] [blame] | 106 | ${EMCXX} $RELEASE_CONF -std=c++14 \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 107 | -Iinclude/config \ |
| 108 | -Iinclude/core \ |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 109 | -Iinclude/effects \ |
| 110 | -Iinclude/gpu \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 111 | -Iinclude/pathops \ |
| 112 | -Iinclude/private \ |
| 113 | -Iinclude/utils \ |
| 114 | -Isrc/core \ |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 115 | -Isrc/gpu \ |
| 116 | -Isrc/shaders \ |
| 117 | -Isrc/opts \ |
| 118 | -Isrc/utils \ |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 119 | -std=c++14 \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 120 | --bind \ |
Kevin Lubick | 644d8e7 | 2018-08-09 13:58:04 -0400 | [diff] [blame] | 121 | --pre-js $BASE_DIR/helper.js \ |
Kevin Lubick | 11194ab | 2018-08-17 13:52:56 -0400 | [diff] [blame] | 122 | --pre-js $BASE_DIR/chaining.js \ |
Kevin Lubick | 275eaff | 2019-01-04 14:38:29 -0500 | [diff] [blame] | 123 | --post-js $BASE_DIR/ready.js \ |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 124 | -DSK_DISABLE_READBUFFER=1 \ |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 125 | -fno-rtti -fno-exceptions -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 126 | $WASM_CONF \ |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 127 | -s BINARYEN_IGNORE_IMPLICIT_TRAPS=1 \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 128 | -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 Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 134 | -s STRICT=1 \ |
Kevin Lubick | e805b24 | 2018-10-10 14:55:01 -0400 | [diff] [blame] | 135 | -s WARN_UNALIGNED=1 \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 136 | $OUTPUT \ |
| 137 | $BASE_DIR/pathkit_wasm_bindings.cpp \ |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame] | 138 | ${BUILD_DIR}/libpathkit.a |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 139 | |
| 140 | if [[ $@ == *serve* ]]; then |
| 141 | pushd $BUILD_DIR |
| 142 | python serve.py |
| 143 | fi |
| 144 | |