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 | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame^] | 46 | RELEASE_CONF="-Oz --closure 1 -s EVAL_CTORS=1" |
| 47 | if [[ $@ == *test* ]]; then |
| 48 | echo "Building a Testing/Profiling build" |
| 49 | RELEASE_CONF="-O2 --profiling -DPATHKIT_TESTING -DSK_RELEASE" |
| 50 | elif [[ $@ == *debug* ]]; then |
| 51 | echo "Building a Debug build" |
| 52 | # -g4 creates source maps that can apparently let you see the C++ code |
| 53 | # in the browser's debugger. |
| 54 | 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] | 55 | fi |
| 56 | |
| 57 | WASM_CONF="-s WASM=1" |
| 58 | if [[ $@ == *asm.js* ]]; then |
| 59 | echo "Building with asm.js instead of WASM" |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame^] | 60 | 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] | 61 | fi |
| 62 | |
| 63 | OUTPUT="-o $BUILD_DIR/pathkit.js" |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 64 | source $EMSDK/emsdk_env.sh |
| 65 | |
| 66 | echo "Compiling" |
| 67 | |
| 68 | set -e |
| 69 | |
| 70 | mkdir -p $BUILD_DIR |
| 71 | |
| 72 | em++ $RELEASE_CONF -std=c++14 \ |
| 73 | -Iinclude/config \ |
| 74 | -Iinclude/core \ |
| 75 | -Iinclude/gpu \ |
| 76 | -Iinclude/pathops \ |
| 77 | -Iinclude/private \ |
| 78 | -Iinclude/utils \ |
| 79 | -Isrc/core \ |
| 80 | -Isrc/gpu \ |
| 81 | -Isrc/shaders \ |
| 82 | -Isrc/opts \ |
| 83 | --bind \ |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame^] | 84 | -fno-rtti -fno-exceptions -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 85 | $WASM_CONF \ |
| 86 | -s MODULARIZE=1 \ |
| 87 | -s EXPORT_NAME="PathKitInit" \ |
| 88 | -s NO_EXIT_RUNTIME=1 \ |
| 89 | -s ERROR_ON_UNDEFINED_SYMBOLS=1 \ |
| 90 | -s ERROR_ON_MISSING_LIBRARIES=1 \ |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame^] | 91 | -s NO_FILESYSTEM=1 \ |
| 92 | -s BINARYEN_IGNORE_IMPLICIT_TRAPS=1 \ |
| 93 | -s STRICT=1 \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 94 | $OUTPUT \ |
| 95 | $BASE_DIR/pathkit_wasm_bindings.cpp \ |
| 96 | src/core/SkAnalyticEdge.cpp \ |
| 97 | src/core/SkArenaAlloc.cpp \ |
| 98 | src/core/SkBlitter.cpp \ |
| 99 | src/core/SkCoverageDelta.cpp \ |
| 100 | src/core/SkEdge.cpp \ |
| 101 | src/core/SkEdgeBuilder.cpp \ |
| 102 | src/core/SkEdgeClipper.cpp \ |
| 103 | src/core/SkFDot6Constants.cpp \ |
| 104 | src/core/SkGeometry.cpp \ |
| 105 | src/core/SkLineClipper.cpp \ |
| 106 | src/core/SkMallocPixelRef.cpp \ |
| 107 | src/core/SkMath.cpp \ |
| 108 | src/core/SkMatrix.cpp \ |
| 109 | src/core/SkOpts.cpp \ |
| 110 | src/core/SkPath.cpp \ |
| 111 | src/core/SkPathRef.cpp \ |
| 112 | src/core/SkPoint.cpp \ |
| 113 | src/core/SkRect.cpp \ |
| 114 | src/core/SkRegion.cpp \ |
| 115 | src/core/SkRegion_path.cpp \ |
| 116 | src/core/SkScan_Path.cpp \ |
| 117 | src/core/SkStream.cpp \ |
| 118 | src/core/SkString.cpp \ |
| 119 | src/core/SkStringUtils.cpp \ |
| 120 | src/core/SkUtils.cpp \ |
| 121 | src/pathops/*.cpp \ |
| 122 | src/ports/SkDebug_stdio.cpp \ |
| 123 | src/ports/SkMemory_malloc.cpp \ |
| 124 | src/utils/SkParse.cpp \ |
Kevin Lubick | b3d0e3e | 2018-08-03 12:24:06 -0400 | [diff] [blame] | 125 | src/utils/SkParsePath.cpp \ |
| 126 | src/utils/SkUTF.cpp |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 127 | |
| 128 | if [[ $@ == *serve* ]]; then |
| 129 | pushd $BUILD_DIR |
| 130 | python serve.py |
| 131 | fi |
| 132 | |