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 | |
| 7 | |
| 8 | BASE_DIR=`cd $(dirname ${BASH_SOURCE[0]}) && pwd` |
| 9 | HTML_SHELL=$BASE_DIR/shell.html |
Kevin Lubick | 30cc00c | 2018-08-03 10:26:00 -0400 | [diff] [blame] | 10 | BUILD_DIR=${BUILD_DIR:="out/pathkit"} |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 11 | |
| 12 | # This expects the environment variable EMSDK to be set |
| 13 | if [[ ! -d $EMSDK ]]; then |
| 14 | echo "Be sure to set the EMSDK environment variable." |
| 15 | exit 1 |
| 16 | fi |
| 17 | |
| 18 | # Navigate to SKIA_HOME from where this file is located. |
| 19 | pushd $BASE_DIR/../.. |
| 20 | |
Kevin Lubick | 30cc00c | 2018-08-03 10:26:00 -0400 | [diff] [blame] | 21 | echo "Putting output in $BUILD_DIR (pwd = `pwd`)" |
| 22 | |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 23 | # Run this from $SKIA_HOME, not from the directory this file is in. |
| 24 | if [[ ! -d ./src ]]; then |
| 25 | echo "Cannot locate Skia source. Is the source checkout okay? Exiting." |
| 26 | exit 1 |
| 27 | fi |
| 28 | |
| 29 | if [[ $@ == *help* ]]; then |
| 30 | echo "By default, this script builds a production WASM build of PathKit." |
| 31 | echo "" |
Kevin Lubick | 30cc00c | 2018-08-03 10:26:00 -0400 | [diff] [blame] | 32 | echo "It is put in ${BUILD_DIR}, configured by the BUILD_DIR environment" |
| 33 | echo "variable. Additionally, the EMSDK environment variable must be set." |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 34 | echo "This script takes several optional parameters:" |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 35 | echo " test = Make a build suitable for running tests or profiling" |
| 36 | echo " debug = Make a build suitable for debugging (defines SK_DEBUG)" |
Kevin Lubick | 30cc00c | 2018-08-03 10:26:00 -0400 | [diff] [blame] | 37 | echo " asm.js = Build for asm.js instead of WASM (very experimental)" |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 38 | echo " serve = starts a webserver allowing a user to navigate to" |
| 39 | echo " localhost:8000/pathkit.html to view the demo page." |
| 40 | exit 0 |
| 41 | fi |
| 42 | |
| 43 | |
| 44 | # Use -O0 for larger builds (but generally quicker) |
| 45 | # Use -Oz for (much slower, but smaller/faster) production builds |
Kevin Lubick | 644d8e7 | 2018-08-09 13:58:04 -0400 | [diff] [blame] | 46 | export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/helper_externs.js " |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 47 | RELEASE_CONF="-Oz --closure 1 -s EVAL_CTORS=1 --llvm-lto 3" |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 48 | if [[ $@ == *test* ]]; then |
| 49 | echo "Building a Testing/Profiling build" |
| 50 | RELEASE_CONF="-O2 --profiling -DPATHKIT_TESTING -DSK_RELEASE" |
| 51 | elif [[ $@ == *debug* ]]; then |
| 52 | echo "Building a Debug build" |
| 53 | # -g4 creates source maps that can apparently let you see the C++ code |
| 54 | # in the browser's debugger. |
| 55 | RELEASE_CONF="-O0 -s SAFE_HEAP=1 -s ASSERTIONS=1 -s DEMANGLE_SUPPORT=1 -g4 -DPATHKIT_TESTING -DSK_DEBUG" |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 56 | fi |
| 57 | |
| 58 | WASM_CONF="-s WASM=1" |
| 59 | if [[ $@ == *asm.js* ]]; then |
| 60 | echo "Building with asm.js instead of WASM" |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 61 | WASM_CONF="-s WASM=0 -s ALLOW_MEMORY_GROWTH=1 --separate-asm -s ELIMINATE_DUPLICATE_FUNCTIONS=1" |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 62 | fi |
| 63 | |
| 64 | OUTPUT="-o $BUILD_DIR/pathkit.js" |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 65 | source $EMSDK/emsdk_env.sh |
| 66 | |
| 67 | echo "Compiling" |
| 68 | |
| 69 | set -e |
| 70 | |
| 71 | mkdir -p $BUILD_DIR |
| 72 | |
| 73 | em++ $RELEASE_CONF -std=c++14 \ |
| 74 | -Iinclude/config \ |
| 75 | -Iinclude/core \ |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 76 | -Iinclude/effects \ |
| 77 | -Iinclude/gpu \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 78 | -Iinclude/pathops \ |
| 79 | -Iinclude/private \ |
| 80 | -Iinclude/utils \ |
| 81 | -Isrc/core \ |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 82 | -Isrc/gpu \ |
| 83 | -Isrc/shaders \ |
| 84 | -Isrc/opts \ |
| 85 | -Isrc/utils \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 86 | --bind \ |
Kevin Lubick | 644d8e7 | 2018-08-09 13:58:04 -0400 | [diff] [blame] | 87 | --pre-js $BASE_DIR/helper.js \ |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 88 | -DWEB_ASSEMBLY=1 \ |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 89 | -fno-rtti -fno-exceptions -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 90 | $WASM_CONF \ |
| 91 | -s MODULARIZE=1 \ |
| 92 | -s EXPORT_NAME="PathKitInit" \ |
| 93 | -s NO_EXIT_RUNTIME=1 \ |
| 94 | -s ERROR_ON_UNDEFINED_SYMBOLS=1 \ |
| 95 | -s ERROR_ON_MISSING_LIBRARIES=1 \ |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 96 | -s NO_FILESYSTEM=1 \ |
| 97 | -s BINARYEN_IGNORE_IMPLICIT_TRAPS=1 \ |
| 98 | -s STRICT=1 \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 99 | $OUTPUT \ |
| 100 | $BASE_DIR/pathkit_wasm_bindings.cpp \ |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 101 | src/core/SkAnalyticEdge.cpp \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 102 | src/core/SkArenaAlloc.cpp \ |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 103 | src/core/SkEdge.cpp \ |
| 104 | src/core/SkEdgeBuilder.cpp \ |
| 105 | src/core/SkEdgeClipper.cpp \ |
| 106 | src/core/SkFDot6Constants.cpp \ |
| 107 | src/core/SkFlattenable.cpp \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 108 | src/core/SkGeometry.cpp \ |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 109 | src/core/SkLineClipper.cpp \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 110 | src/core/SkMallocPixelRef.cpp \ |
| 111 | src/core/SkMath.cpp \ |
| 112 | src/core/SkMatrix.cpp \ |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 113 | src/core/SkOpts.cpp \ |
| 114 | src/core/SkPaint.cpp \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 115 | src/core/SkPath.cpp \ |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 116 | src/core/SkPathEffect.cpp \ |
| 117 | src/core/SkPathMeasure.cpp \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 118 | src/core/SkPathRef.cpp \ |
| 119 | src/core/SkPoint.cpp \ |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 120 | src/core/SkRRect.cpp \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 121 | src/core/SkRect.cpp \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 122 | src/core/SkStream.cpp \ |
| 123 | src/core/SkString.cpp \ |
| 124 | src/core/SkStringUtils.cpp \ |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 125 | src/core/SkStroke.cpp \ |
| 126 | src/core/SkStrokeRec.cpp \ |
| 127 | src/core/SkStrokerPriv.cpp \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 128 | src/core/SkUtils.cpp \ |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 129 | src/effects/SkDashPathEffect.cpp \ |
| 130 | src/effects/SkTrimPathEffect.cpp \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 131 | src/pathops/*.cpp \ |
| 132 | src/ports/SkDebug_stdio.cpp \ |
| 133 | src/ports/SkMemory_malloc.cpp \ |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 134 | src/utils/SkDashPath.cpp \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 135 | src/utils/SkParse.cpp \ |
Kevin Lubick | b3d0e3e | 2018-08-03 12:24:06 -0400 | [diff] [blame] | 136 | src/utils/SkParsePath.cpp \ |
| 137 | src/utils/SkUTF.cpp |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 138 | |
| 139 | if [[ $@ == *serve* ]]; then |
| 140 | pushd $BUILD_DIR |
| 141 | python serve.py |
| 142 | fi |
| 143 | |