blob: d4f90ed4000244432a4856d30ec5567e3d216472 [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
Kevin Lubick8e9750d2018-10-09 09:36:35 -04007set -ex
Kevin Lubicke1b36fe2018-08-02 11:30:33 -04008
9BASE_DIR=`cd $(dirname ${BASH_SOURCE[0]}) && pwd`
10HTML_SHELL=$BASE_DIR/shell.html
Kevin Lubick30cc00c2018-08-03 10:26:00 -040011BUILD_DIR=${BUILD_DIR:="out/pathkit"}
Kevin Lubick8e9750d2018-10-09 09:36:35 -040012mkdir -p $BUILD_DIR
Kevin Lubickf76da632020-01-28 10:39:56 -050013# sometimes the .a files keep old symbols around - cleaning them out makes sure
14# we get a fresh build.
15rm -f $BUILD_DIR/*.a
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040016
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
Kevin Lubick30cc00c2018-08-03 10:26:00 -040026echo "Putting output in $BUILD_DIR (pwd = `pwd`)"
27
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040028# 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 ""
Kevin Lubick30cc00c2018-08-03 10:26:00 -040037 echo "It is put in ${BUILD_DIR}, configured by the BUILD_DIR environment"
38 echo "variable. Additionally, the EMSDK environment variable must be set."
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040039 echo "This script takes several optional parameters:"
Kevin Lubick641bf872018-08-06 14:49:39 -040040 echo " test = Make a build suitable for running tests or profiling"
41 echo " debug = Make a build suitable for debugging (defines SK_DEBUG)"
Kevin Lubick30cc00c2018-08-03 10:26:00 -040042 echo " asm.js = Build for asm.js instead of WASM (very experimental)"
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040043 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
Kevin Lubick11194ab2018-08-17 13:52:56 -040051export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js "
Kevin Lubick102dbf92022-02-01 08:08:47 -050052RELEASE_CONF="-Oz --closure 1 -DSK_RELEASE"
Kevin Lubickcbcff382018-10-02 09:02:18 -040053# 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\""
Kevin Lubick641bf872018-08-06 14:49:39 -040057if [[ $@ == *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"
Kevin Lubickcbcff382018-10-02 09:02:18 -040062 EXTRA_CFLAGS="\"-DSK_DEBUG\""
Kevin Lubick102dbf92022-02-01 08:08:47 -050063 RELEASE_CONF="-O0 --js-opts 0 -sSAFE_HEAP=1 -sASSERTIONS=1 -g3 -DPATHKIT_TESTING -DSK_DEBUG"
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040064fi
65
Kevin Lubick102dbf92022-02-01 08:08:47 -050066WASM_CONF="-sWASM=1"
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040067if [[ $@ == *asm.js* ]]; then
68 echo "Building with asm.js instead of WASM"
Kevin Lubick102dbf92022-02-01 08:08:47 -050069 WASM_CONF="-sWASM=0 -sALLOW_MEMORY_GROWTH=1"
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040070fi
71
72OUTPUT="-o $BUILD_DIR/pathkit.js"
Kevin Lubick8e9750d2018-10-09 09:36:35 -040073
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040074source $EMSDK/emsdk_env.sh
Kevin Lubickcbcff382018-10-02 09:02:18 -040075EMCXX=`which em++`
Kevin Lubicke1b36fe2018-08-02 11:30:33 -040076
Kevin Lubick6f65f062022-11-28 12:27:21 -050077./bin/fetch-ninja
78NINJA=third_party/ninja/ninja
Kevin Lubickcbcff382018-10-02 09:02:18 -040079
80echo "Compiling bitcode"
81
82./bin/fetch-gn
Kevin Lubick6f65f062022-11-28 12:27:21 -050083
Kevin Lubickcbcff382018-10-02 09:02:18 -040084./bin/gn gen ${BUILD_DIR} \
Kevin Lubickc13cd642022-02-14 15:08:12 -050085 --args="skia_emsdk_dir=\"${EMSDK}\" \
Kevin Lubick102dbf92022-02-01 08:08:47 -050086 extra_cflags=[
87 \"-sMAIN_MODULE=1\",
Kevin Lubicke805b242018-10-10 14:55:01 -040088 ${EXTRA_CFLAGS}
89 ] \
Kevin Lubickcbcff382018-10-02 09:02:18 -040090 is_debug=false \
91 is_official_build=true \
Kevin Lubickb33e4642023-04-25 15:11:49 -040092 is_trivial_abi=true \
Kevin Lubickcbcff382018-10-02 09:02:18 -040093 is_component_build=false \
Mike Kleinba201ae2019-04-23 07:38:07 -050094 werror=true \
Kevin Lubicke805b242018-10-10 14:55:01 -040095 target_cpu=\"wasm\" "
Kevin Lubickcbcff382018-10-02 09:02:18 -040096
97${NINJA} -C ${BUILD_DIR} libpathkit.a
98
99echo "Generating WASM"
100
Kevin Lubickf76da632020-01-28 10:39:56 -0500101${EMCXX} $RELEASE_CONF -std=c++17 \
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500102-I. \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400103--bind \
Kevin Lubickd1285b12020-05-21 09:59:44 -0400104--no-entry \
Kevin Lubick644d8e72018-08-09 13:58:04 -0400105--pre-js $BASE_DIR/helper.js \
Kevin Lubick11194ab2018-08-17 13:52:56 -0400106--pre-js $BASE_DIR/chaining.js \
Kevin Lubick641bf872018-08-06 14:49:39 -0400107-fno-rtti -fno-exceptions -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 \
Kevin Lubickb33e4642023-04-25 15:11:49 -0400108"-DSK_TRIVIAL_ABI=[[clang::trivial_abi]]" \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400109$WASM_CONF \
Kevin Lubick102dbf92022-02-01 08:08:47 -0500110-sERROR_ON_UNDEFINED_SYMBOLS=1 \
111-sEXPORT_NAME="PathKitInit" \
112-sMODULARIZE=1 \
113-sNO_EXIT_RUNTIME=1 \
114-sNO_FILESYSTEM=1 \
115-sDYNAMIC_EXECUTION=0 \
Kevin Lubickb59e38d2022-02-03 10:39:05 -0500116-sINITIAL_MEMORY=32MB \
117-sALLOW_MEMORY_GROWTH=1 \
Kevin Lubick102dbf92022-02-01 08:08:47 -0500118-sSTRICT=1 \
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400119$OUTPUT \
120$BASE_DIR/pathkit_wasm_bindings.cpp \
Kevin Lubickcbcff382018-10-02 09:02:18 -0400121${BUILD_DIR}/libpathkit.a
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400122
Kevin Lubicke1b36fe2018-08-02 11:30:33 -0400123