• 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# sometimes the .a files keep old symbols around - cleaning them out makes sure
14# we get a fresh build.
15rm -f $BUILD_DIR/*.a
16
17# This expects the environment variable EMSDK to be set
18if [[ ! -d $EMSDK ]]; then
19  echo "Be sure to set the EMSDK environment variable."
20  exit 1
21fi
22
23# Navigate to SKIA_HOME from where this file is located.
24pushd $BASE_DIR/../..
25
26echo "Putting output in $BUILD_DIR (pwd = `pwd`)"
27
28# Run this from $SKIA_HOME, not from the directory this file is in.
29if [[ ! -d ./src ]]; then
30  echo "Cannot locate Skia source. Is the source checkout okay? Exiting."
31  exit 1
32fi
33
34if [[ $@ == *help* ]]; then
35  echo "By default, this script builds a production WASM build of PathKit."
36  echo ""
37  echo "It is put in ${BUILD_DIR}, configured by the BUILD_DIR environment"
38  echo "variable. Additionally, the EMSDK environment variable must be set."
39  echo "This script takes several optional parameters:"
40  echo "  test = Make a build suitable for running tests or profiling"
41  echo "  debug = Make a build suitable for debugging (defines SK_DEBUG)"
42  echo "  asm.js = Build for asm.js instead of WASM (very experimental)"
43  echo "  serve = starts a webserver allowing a user to navigate to"
44  echo "          localhost:8000/pathkit.html to view the demo page."
45  exit 0
46fi
47
48
49# Use -O0 for larger builds (but generally quicker)
50# Use -Oz for (much slower, but smaller/faster) production builds
51export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js "
52RELEASE_CONF="-Oz --closure 1 -DSK_RELEASE"
53# It is very important for the -DSK_RELEASE/-DSK_DEBUG to match on the libskia.a, otherwise
54# things like SKDEBUGCODE are sometimes compiled in and sometimes not, which can cause headaches
55# like sizeof() mismatching between .cpp files and .h files.
56EXTRA_CFLAGS="\"-DSK_RELEASE\""
57if [[ $@ == *test* ]]; then
58  echo "Building a Testing/Profiling build"
59  RELEASE_CONF="-O2 --profiling -DPATHKIT_TESTING -DSK_RELEASE"
60elif [[ $@ == *debug* ]]; then
61  echo "Building a Debug build"
62  EXTRA_CFLAGS="\"-DSK_DEBUG\""
63  RELEASE_CONF="-O0 --js-opts 0 -sSAFE_HEAP=1 -sASSERTIONS=1 -g3 -DPATHKIT_TESTING -DSK_DEBUG"
64fi
65
66WASM_CONF="-sWASM=1"
67if [[ $@ == *asm.js* ]]; then
68  echo "Building with asm.js instead of WASM"
69  WASM_CONF="-sWASM=0 -sALLOW_MEMORY_GROWTH=1"
70fi
71
72OUTPUT="-o $BUILD_DIR/pathkit.js"
73
74source $EMSDK/emsdk_env.sh
75EMCXX=`which em++`
76
77# Turn off exiting while we check for ninja (which may not be on PATH)
78set +e
79NINJA=`which ninja`
80if [[ -z $NINJA ]]; then
81  git clone "https://chromium.googlesource.com/chromium/tools/depot_tools.git" --depth 1 $BUILD_DIR/depot_tools
82  NINJA=$BUILD_DIR/depot_tools/ninja
83fi
84# Re-enable error checking
85set -e
86
87echo "Compiling bitcode"
88
89./bin/fetch-gn
90./bin/gn gen ${BUILD_DIR} \
91  --args="skia_emsdk_dir=\"${EMSDK}\" \
92  extra_cflags=[
93    \"-sMAIN_MODULE=1\",
94    ${EXTRA_CFLAGS}
95  ] \
96  is_debug=false \
97  is_official_build=true \
98  is_component_build=false \
99  werror=true \
100  target_cpu=\"wasm\" "
101
102${NINJA} -C ${BUILD_DIR} libpathkit.a
103
104echo "Generating WASM"
105
106${EMCXX} $RELEASE_CONF -std=c++17 \
107-I. \
108--bind \
109--no-entry \
110--pre-js $BASE_DIR/helper.js \
111--pre-js $BASE_DIR/chaining.js \
112-fno-rtti -fno-exceptions -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 \
113$WASM_CONF \
114-sERROR_ON_UNDEFINED_SYMBOLS=1 \
115-sEXPORT_NAME="PathKitInit" \
116-sMODULARIZE=1 \
117-sNO_EXIT_RUNTIME=1 \
118-sNO_FILESYSTEM=1 \
119-sDYNAMIC_EXECUTION=0 \
120-sINITIAL_MEMORY=32MB \
121-sALLOW_MEMORY_GROWTH=1 \
122-sSTRICT=1 \
123$OUTPUT \
124$BASE_DIR/pathkit_wasm_bindings.cpp \
125${BUILD_DIR}/libpathkit.a
126
127
128