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