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 | 11194ab | 2018-08-17 13:52:56 -0400 | [diff] [blame] | 46 | export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js " |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame^] | 47 | RELEASE_CONF="-Oz --closure 1 -s EVAL_CTORS=1 --llvm-lto 3 -s ELIMINATE_DUPLICATE_FUNCTIONS=1 -DSK_RELEASE" |
| 48 | # It is very important for the -DSK_RELEASE/-DSK_DEBUG to match on the libskia.a, otherwise |
| 49 | # things like SKDEBUGCODE are sometimes compiled in and sometimes not, which can cause headaches |
| 50 | # like sizeof() mismatching between .cpp files and .h files. |
| 51 | EXTRA_CFLAGS="\"-DSK_RELEASE\"" |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 52 | if [[ $@ == *test* ]]; then |
| 53 | echo "Building a Testing/Profiling build" |
| 54 | RELEASE_CONF="-O2 --profiling -DPATHKIT_TESTING -DSK_RELEASE" |
| 55 | elif [[ $@ == *debug* ]]; then |
| 56 | echo "Building a Debug build" |
| 57 | # -g4 creates source maps that can apparently let you see the C++ code |
| 58 | # in the browser's debugger. |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame^] | 59 | EXTRA_CFLAGS="\"-DSK_DEBUG\"" |
Kevin Lubick | f14a3c0 | 2018-08-22 09:35:32 -0400 | [diff] [blame] | 60 | 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] | 61 | fi |
| 62 | |
| 63 | WASM_CONF="-s WASM=1" |
| 64 | if [[ $@ == *asm.js* ]]; then |
| 65 | echo "Building with asm.js instead of WASM" |
Kevin Lubick | f14a3c0 | 2018-08-22 09:35:32 -0400 | [diff] [blame] | 66 | WASM_CONF="-s WASM=0 -s ALLOW_MEMORY_GROWTH=1" |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 67 | fi |
| 68 | |
| 69 | OUTPUT="-o $BUILD_DIR/pathkit.js" |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 70 | source $EMSDK/emsdk_env.sh |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame^] | 71 | NINJA=`which ninja` |
| 72 | EMCC=`which emcc` |
| 73 | EMCXX=`which em++` |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 74 | |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 75 | |
| 76 | mkdir -p $BUILD_DIR |
| 77 | |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame^] | 78 | if [[ -z $NINJA ]]; then |
| 79 | git clone "https://chromium.googlesource.com/chromium/tools/depot_tools.git" --depth 1 $BUILD_DIR/depot_tools |
| 80 | NINJA=$BUILD_DIR/depot_tools/ninja |
| 81 | fi |
| 82 | |
| 83 | set -ex |
| 84 | |
| 85 | echo "Compiling bitcode" |
| 86 | |
| 87 | ./bin/fetch-gn |
| 88 | ./bin/gn gen ${BUILD_DIR} \ |
| 89 | --args="cc=\"${EMCC}\" \ |
| 90 | cxx=\"${EMCXX}\" \ |
| 91 | extra_cflags=[\"-DSK_DISABLE_READBUFFER=1\",${EXTRA_CFLAGS}] \ |
| 92 | is_debug=false \ |
| 93 | is_official_build=true \ |
| 94 | is_component_build=false \ |
| 95 | target_cpu=\"wasm\" \ |
| 96 | \ |
| 97 | skia_use_egl=false \ |
| 98 | skia_use_vulkan=false \ |
| 99 | skia_use_libwebp=false \ |
| 100 | skia_use_libpng=false \ |
| 101 | skia_use_lua=false \ |
| 102 | skia_use_dng_sdk=false \ |
| 103 | skia_use_fontconfig=false \ |
| 104 | skia_use_libjpeg_turbo=false \ |
| 105 | skia_use_libheif=false \ |
| 106 | skia_use_expat=false \ |
| 107 | skia_use_vulkan=false \ |
| 108 | skia_use_freetype=false \ |
| 109 | skia_use_icu=false \ |
| 110 | skia_use_expat=false \ |
| 111 | skia_use_piex=false \ |
| 112 | skia_use_zlib=false \ |
| 113 | \ |
| 114 | skia_enable_gpu=false \ |
| 115 | skia_enable_fontmgr_empty=true \ |
| 116 | skia_enable_pdf=false" |
| 117 | |
| 118 | ${NINJA} -C ${BUILD_DIR} libpathkit.a |
| 119 | |
| 120 | echo "Generating WASM" |
| 121 | |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 122 | em++ $RELEASE_CONF -std=c++14 \ |
| 123 | -Iinclude/config \ |
| 124 | -Iinclude/core \ |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 125 | -Iinclude/effects \ |
| 126 | -Iinclude/gpu \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 127 | -Iinclude/pathops \ |
| 128 | -Iinclude/private \ |
| 129 | -Iinclude/utils \ |
| 130 | -Isrc/core \ |
Kevin Lubick | 97d6d98 | 2018-08-10 15:53:16 -0400 | [diff] [blame] | 131 | -Isrc/gpu \ |
| 132 | -Isrc/shaders \ |
| 133 | -Isrc/opts \ |
| 134 | -Isrc/utils \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 135 | --bind \ |
Kevin Lubick | 644d8e7 | 2018-08-09 13:58:04 -0400 | [diff] [blame] | 136 | --pre-js $BASE_DIR/helper.js \ |
Kevin Lubick | 11194ab | 2018-08-17 13:52:56 -0400 | [diff] [blame] | 137 | --pre-js $BASE_DIR/chaining.js \ |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame^] | 138 | -DSK_DISABLE_READBUFFER=1 \ |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 139 | -fno-rtti -fno-exceptions -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 140 | $WASM_CONF \ |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 141 | -s BINARYEN_IGNORE_IMPLICIT_TRAPS=1 \ |
Kevin Lubick | 217056c | 2018-09-20 17:39:31 -0400 | [diff] [blame] | 142 | -s ERROR_ON_MISSING_LIBRARIES=1 \ |
| 143 | -s ERROR_ON_UNDEFINED_SYMBOLS=1 \ |
| 144 | -s EXPORT_NAME="PathKitInit" \ |
| 145 | -s MODULARIZE=1 \ |
| 146 | -s NO_EXIT_RUNTIME=1 \ |
| 147 | -s NO_FILESYSTEM=1 \ |
Kevin Lubick | 641bf87 | 2018-08-06 14:49:39 -0400 | [diff] [blame] | 148 | -s STRICT=1 \ |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 149 | $OUTPUT \ |
| 150 | $BASE_DIR/pathkit_wasm_bindings.cpp \ |
Kevin Lubick | cbcff38 | 2018-10-02 09:02:18 -0400 | [diff] [blame^] | 151 | ${BUILD_DIR}/libpathkit.a |
Kevin Lubick | e1b36fe | 2018-08-02 11:30:33 -0400 | [diff] [blame] | 152 | |
| 153 | if [[ $@ == *serve* ]]; then |
| 154 | pushd $BUILD_DIR |
| 155 | python serve.py |
| 156 | fi |
| 157 | |