blob: 9507f809bfb00cc331d2ebccda171acdd6538e3f [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 Lubick11194ab2018-08-17 13:52:56 -040046export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js "
Kevin Lubick97d6d982018-08-10 15:53:16 -040047RELEASE_CONF="-Oz --closure 1 -s EVAL_CTORS=1 --llvm-lto 3"
Kevin Lubick641bf872018-08-06 14:49:39 -040048if [[ $@ == *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 Lubick97d6d982018-08-10 15:53:16 -040076-Iinclude/effects \
77-Iinclude/gpu \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040078-Iinclude/pathops \
79-Iinclude/private \
80-Iinclude/utils \
81-Isrc/core \
Kevin Lubick97d6d982018-08-10 15:53:16 -040082-Isrc/gpu \
83-Isrc/shaders \
84-Isrc/opts \
85-Isrc/utils \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040086--bind \
Kevin Lubick644d8e72018-08-09 13:58:04 -040087--pre-js $BASE_DIR/helper.js \
Kevin Lubick11194ab2018-08-17 13:52:56 -040088--pre-js $BASE_DIR/chaining.js \
Kevin Lubick97d6d982018-08-10 15:53:16 -040089-DWEB_ASSEMBLY=1 \
Kevin Lubick641bf872018-08-06 14:49:39 -040090-fno-rtti -fno-exceptions -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040091$WASM_CONF \
92-s MODULARIZE=1 \
93-s EXPORT_NAME="PathKitInit" \
94-s NO_EXIT_RUNTIME=1 \
95-s ERROR_ON_UNDEFINED_SYMBOLS=1 \
96-s ERROR_ON_MISSING_LIBRARIES=1 \
Kevin Lubick641bf872018-08-06 14:49:39 -040097-s NO_FILESYSTEM=1 \
98-s BINARYEN_IGNORE_IMPLICIT_TRAPS=1 \
99-s STRICT=1 \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400100$OUTPUT \
101$BASE_DIR/pathkit_wasm_bindings.cpp \
Kevin Lubick97d6d982018-08-10 15:53:16 -0400102src/core/SkAnalyticEdge.cpp \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400103src/core/SkArenaAlloc.cpp \
Kevin Lubick97d6d982018-08-10 15:53:16 -0400104src/core/SkEdge.cpp \
105src/core/SkEdgeBuilder.cpp \
106src/core/SkEdgeClipper.cpp \
107src/core/SkFDot6Constants.cpp \
108src/core/SkFlattenable.cpp \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400109src/core/SkGeometry.cpp \
Kevin Lubick97d6d982018-08-10 15:53:16 -0400110src/core/SkLineClipper.cpp \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400111src/core/SkMallocPixelRef.cpp \
112src/core/SkMath.cpp \
113src/core/SkMatrix.cpp \
Kevin Lubick97d6d982018-08-10 15:53:16 -0400114src/core/SkOpts.cpp \
115src/core/SkPaint.cpp \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400116src/core/SkPath.cpp \
Kevin Lubick97d6d982018-08-10 15:53:16 -0400117src/core/SkPathEffect.cpp \
118src/core/SkPathMeasure.cpp \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400119src/core/SkPathRef.cpp \
120src/core/SkPoint.cpp \
Kevin Lubick97d6d982018-08-10 15:53:16 -0400121src/core/SkRRect.cpp \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400122src/core/SkRect.cpp \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400123src/core/SkStream.cpp \
124src/core/SkString.cpp \
125src/core/SkStringUtils.cpp \
Kevin Lubick97d6d982018-08-10 15:53:16 -0400126src/core/SkStroke.cpp \
127src/core/SkStrokeRec.cpp \
128src/core/SkStrokerPriv.cpp \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400129src/core/SkUtils.cpp \
Kevin Lubick97d6d982018-08-10 15:53:16 -0400130src/effects/SkDashPathEffect.cpp \
131src/effects/SkTrimPathEffect.cpp \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400132src/pathops/*.cpp \
133src/ports/SkDebug_stdio.cpp \
134src/ports/SkMemory_malloc.cpp \
Kevin Lubick97d6d982018-08-10 15:53:16 -0400135src/utils/SkDashPath.cpp \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400136src/utils/SkParse.cpp \
Kevin Lubickb3d0e3e2018-08-03 12:24:06 -0400137src/utils/SkParsePath.cpp \
138src/utils/SkUTF.cpp
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400139
140if [[ $@ == *serve* ]]; then
141 pushd $BUILD_DIR
142 python serve.py
143fi
144