blob: 8956b7bb2d28940bb6ed79cda550dba2b15a96e4 [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 Lubickcbcff382018-10-02 09:02:18 -040047RELEASE_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.
51EXTRA_CFLAGS="\"-DSK_RELEASE\""
Kevin Lubick641bf872018-08-06 14:49:39 -040052if [[ $@ == *test* ]]; then
53 echo "Building a Testing/Profiling build"
54 RELEASE_CONF="-O2 --profiling -DPATHKIT_TESTING -DSK_RELEASE"
55elif [[ $@ == *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 Lubickcbcff382018-10-02 09:02:18 -040059 EXTRA_CFLAGS="\"-DSK_DEBUG\""
Kevin Lubickf14a3c02018-08-22 09:35:32 -040060 RELEASE_CONF="-O0 --js-opts 0 -s SAFE_HEAP=1 -s ASSERTIONS=1 -g4 -DPATHKIT_TESTING -DSK_DEBUG"
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040061fi
62
63WASM_CONF="-s WASM=1"
64if [[ $@ == *asm.js* ]]; then
65 echo "Building with asm.js instead of WASM"
Kevin Lubickf14a3c02018-08-22 09:35:32 -040066 WASM_CONF="-s WASM=0 -s ALLOW_MEMORY_GROWTH=1"
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040067fi
68
69OUTPUT="-o $BUILD_DIR/pathkit.js"
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040070source $EMSDK/emsdk_env.sh
Kevin Lubickcbcff382018-10-02 09:02:18 -040071NINJA=`which ninja`
72EMCC=`which emcc`
73EMCXX=`which em++`
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040074
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040075
76mkdir -p $BUILD_DIR
77
Kevin Lubickcbcff382018-10-02 09:02:18 -040078if [[ -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
81fi
82
83set -ex
84
85echo "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
120echo "Generating WASM"
121
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400122em++ $RELEASE_CONF -std=c++14 \
123-Iinclude/config \
124-Iinclude/core \
Kevin Lubick97d6d982018-08-10 15:53:16 -0400125-Iinclude/effects \
126-Iinclude/gpu \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400127-Iinclude/pathops \
128-Iinclude/private \
129-Iinclude/utils \
130-Isrc/core \
Kevin Lubick97d6d982018-08-10 15:53:16 -0400131-Isrc/gpu \
132-Isrc/shaders \
133-Isrc/opts \
134-Isrc/utils \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400135--bind \
Kevin Lubick644d8e72018-08-09 13:58:04 -0400136--pre-js $BASE_DIR/helper.js \
Kevin Lubick11194ab2018-08-17 13:52:56 -0400137--pre-js $BASE_DIR/chaining.js \
Kevin Lubickcbcff382018-10-02 09:02:18 -0400138-DSK_DISABLE_READBUFFER=1 \
Kevin Lubick641bf872018-08-06 14:49:39 -0400139-fno-rtti -fno-exceptions -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400140$WASM_CONF \
Kevin Lubick641bf872018-08-06 14:49:39 -0400141-s BINARYEN_IGNORE_IMPLICIT_TRAPS=1 \
Kevin Lubick217056c2018-09-20 17:39:31 -0400142-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 Lubick641bf872018-08-06 14:49:39 -0400148-s STRICT=1 \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400149$OUTPUT \
150$BASE_DIR/pathkit_wasm_bindings.cpp \
Kevin Lubickcbcff382018-10-02 09:02:18 -0400151${BUILD_DIR}/libpathkit.a
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400152
153if [[ $@ == *serve* ]]; then
154 pushd $BUILD_DIR
155 python serve.py
156fi
157