blob: 2f66588cc04cb55db04c3162eaa5240926bce489 [file] [log] [blame]
Kevin Lubicke1b36fe2018-08-02 11:30:33 -04001#!/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
8BASE_DIR=`cd $(dirname ${BASH_SOURCE[0]}) && pwd`
9HTML_SHELL=$BASE_DIR/shell.html
Kevin Lubick30cc00c2018-08-03 10:26:00 -040010BUILD_DIR=${BUILD_DIR:="out/pathkit"}
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040011
12# This expects the environment variable EMSDK to be set
13if [[ ! -d $EMSDK ]]; then
14 echo "Be sure to set the EMSDK environment variable."
15 exit 1
16fi
17
18# Navigate to SKIA_HOME from where this file is located.
19pushd $BASE_DIR/../..
20
Kevin Lubick30cc00c2018-08-03 10:26:00 -040021echo "Putting output in $BUILD_DIR (pwd = `pwd`)"
22
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040023# Run this from $SKIA_HOME, not from the directory this file is in.
24if [[ ! -d ./src ]]; then
25 echo "Cannot locate Skia source. Is the source checkout okay? Exiting."
26 exit 1
27fi
28
29if [[ $@ == *help* ]]; then
30 echo "By default, this script builds a production WASM build of PathKit."
31 echo ""
Kevin Lubick30cc00c2018-08-03 10:26:00 -040032 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 Lubicke1b36fe2018-08-02 11:30:33 -040034 echo "This script takes several optional parameters:"
Kevin Lubick641bf872018-08-06 14:49:39 -040035 echo " test = Make a build suitable for running tests or profiling"
36 echo " debug = Make a build suitable for debugging (defines SK_DEBUG)"
Kevin Lubick30cc00c2018-08-03 10:26:00 -040037 echo " asm.js = Build for asm.js instead of WASM (very experimental)"
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040038 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
41fi
42
43
44# Use -O0 for larger builds (but generally quicker)
45# Use -Oz for (much slower, but smaller/faster) production builds
Kevin Lubick644d8e72018-08-09 13:58:04 -040046export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/helper_externs.js "
Kevin Lubick641bf872018-08-06 14:49:39 -040047RELEASE_CONF="-Oz --closure 1 -s EVAL_CTORS=1"
48if [[ $@ == *test* ]]; then
49 echo "Building a Testing/Profiling build"
50 RELEASE_CONF="-O2 --profiling -DPATHKIT_TESTING -DSK_RELEASE"
51elif [[ $@ == *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 Lubicke1b36fe2018-08-02 11:30:33 -040056fi
57
58WASM_CONF="-s WASM=1"
59if [[ $@ == *asm.js* ]]; then
60 echo "Building with asm.js instead of WASM"
Kevin Lubick641bf872018-08-06 14:49:39 -040061 WASM_CONF="-s WASM=0 -s ALLOW_MEMORY_GROWTH=1 --separate-asm -s ELIMINATE_DUPLICATE_FUNCTIONS=1"
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040062fi
63
64OUTPUT="-o $BUILD_DIR/pathkit.js"
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040065source $EMSDK/emsdk_env.sh
66
67echo "Compiling"
68
69set -e
70
71mkdir -p $BUILD_DIR
72
73em++ $RELEASE_CONF -std=c++14 \
74-Iinclude/config \
75-Iinclude/core \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040076-Iinclude/pathops \
77-Iinclude/private \
78-Iinclude/utils \
79-Isrc/core \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040080--bind \
Kevin Lubick644d8e72018-08-09 13:58:04 -040081--pre-js $BASE_DIR/helper.js \
Kevin Lubick641bf872018-08-06 14:49:39 -040082-fno-rtti -fno-exceptions -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040083$WASM_CONF \
84-s MODULARIZE=1 \
85-s EXPORT_NAME="PathKitInit" \
86-s NO_EXIT_RUNTIME=1 \
87-s ERROR_ON_UNDEFINED_SYMBOLS=1 \
88-s ERROR_ON_MISSING_LIBRARIES=1 \
Kevin Lubick641bf872018-08-06 14:49:39 -040089-s NO_FILESYSTEM=1 \
90-s BINARYEN_IGNORE_IMPLICIT_TRAPS=1 \
91-s STRICT=1 \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040092$OUTPUT \
93$BASE_DIR/pathkit_wasm_bindings.cpp \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040094src/core/SkArenaAlloc.cpp \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040095src/core/SkGeometry.cpp \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040096src/core/SkMallocPixelRef.cpp \
97src/core/SkMath.cpp \
98src/core/SkMatrix.cpp \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040099src/core/SkPath.cpp \
100src/core/SkPathRef.cpp \
101src/core/SkPoint.cpp \
102src/core/SkRect.cpp \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400103src/core/SkStream.cpp \
104src/core/SkString.cpp \
105src/core/SkStringUtils.cpp \
106src/core/SkUtils.cpp \
107src/pathops/*.cpp \
108src/ports/SkDebug_stdio.cpp \
109src/ports/SkMemory_malloc.cpp \
110src/utils/SkParse.cpp \
Kevin Lubickb3d0e3e2018-08-03 12:24:06 -0400111src/utils/SkParsePath.cpp \
112src/utils/SkUTF.cpp
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400113
114if [[ $@ == *serve* ]]; then
115 pushd $BUILD_DIR
116 python serve.py
117fi
118