• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright 2019 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
8set -ex
9
10BASE_DIR=`cd $(dirname ${BASH_SOURCE[0]}) && pwd`
11# This expects the environment variable EMSDK to be set
12if [[ ! -d $EMSDK ]]; then
13  echo "Be sure to set the EMSDK environment variable."
14  exit 1
15fi
16
17# Navigate to SKIA_HOME from where this file is located.
18pushd $BASE_DIR/../..
19
20source $EMSDK/emsdk_env.sh
21EMCC=`which emcc`
22EMCXX=`which em++`
23
24if [[ $@ == *debug* ]]; then
25  echo "Building a Debug build"
26  EXTRA_CFLAGS="\"-DSK_DEBUG\","
27  RELEASE_CONF="-O0 --js-opts 0 -s DEMANGLE_SUPPORT=1 -s ASSERTIONS=1 -s GL_ASSERTIONS=1 -g4 \
28                --source-map-base /node_modules/debugger/bin/ -DSK_DEBUG"
29  BUILD_DIR=${BUILD_DIR:="out/debugger_wasm_debug"}
30else
31  echo "Building a Release build"
32  EXTRA_CFLAGS="\"-DSK_RELEASE\", \"-DGR_GL_CHECK_ALLOC_WITH_GET_ERROR=0\","
33  RELEASE_CONF="-Oz --closure 1 --llvm-lto 3 -DSK_RELEASE -DGR_GL_CHECK_ALLOC_WITH_GET_ERROR=0"
34  BUILD_DIR=${BUILD_DIR:="out/debugger_wasm"}
35fi
36
37mkdir -p $BUILD_DIR
38
39BUILTIN_FONT="$BASE_DIR/fonts/NotoMono-Regular.ttf.cpp"
40# Generate the font's binary file (which is covered by .gitignore)
41python tools/embed_resources.py \
42    --name SK_EMBEDDED_FONTS \
43    --input $BASE_DIR/fonts/NotoMono-Regular.ttf \
44    --output $BASE_DIR/fonts/NotoMono-Regular.ttf.cpp \
45    --align 4
46
47GN_GPU_FLAGS="\"-DSK_DISABLE_LEGACY_SHADERCONTEXT\","
48WASM_GPU="-lEGL -lGLESv2 -DSK_SUPPORT_GPU=1 \
49          -DSK_DISABLE_LEGACY_SHADERCONTEXT --pre-js $BASE_DIR/cpu.js --pre-js $BASE_DIR/gpu.js"
50
51# Turn off exiting while we check for ninja (which may not be on PATH)
52set +e
53NINJA=`which ninja`
54if [[ -z $NINJA ]]; then
55  git clone "https://chromium.googlesource.com/chromium/tools/depot_tools.git" --depth 1 $BUILD_DIR/depot_tools
56  NINJA=$BUILD_DIR/depot_tools/ninja
57fi
58# Re-enable error checking
59set -e
60
61./bin/fetch-gn
62
63echo "Compiling bitcode"
64
65./bin/gn gen ${BUILD_DIR} \
66  --args="cc=\"${EMCC}\" \
67  cxx=\"${EMCXX}\" \
68  extra_cflags_cc=[\"-frtti\"] \
69  extra_cflags=[\"-s\",\"USE_FREETYPE=1\",\"-s\",\"USE_LIBPNG=1\", \"-s\", \"WARN_UNALIGNED=1\",
70    \"-DSKNX_NO_SIMD\", \"-DSK_DISABLE_AAA\",
71    ${GN_GPU_FLAGS}
72    ${EXTRA_CFLAGS}
73  ] \
74  is_debug=false \
75  is_official_build=true \
76  is_component_build=false \
77  werror=true \
78  target_cpu=\"wasm\" \
79  \
80  skia_use_angle = false \
81  skia_use_dng_sdk=false \
82  skia_use_egl=true \
83  skia_use_expat=false \
84  skia_use_fontconfig=false \
85  skia_use_freetype=true \
86  skia_use_libheif=false \
87  skia_use_libjpeg_turbo=true \
88  skia_use_libpng=true \
89  skia_use_libwebp=true \
90  skia_use_wuffs=true \
91  skia_use_lua=false \
92  skia_use_piex=false \
93  skia_use_system_libpng=true \
94  skia_use_system_freetype2=true \
95  skia_use_system_libjpeg_turbo = false \
96  skia_use_system_libwebp=false \
97  skia_use_vulkan=false \
98  skia_use_zlib=true \
99  skia_enable_gpu=true \
100  skia_enable_tools=false \
101  skia_enable_skshaper=false \
102  skia_enable_ccpr=false \
103  skia_enable_nvpr=false \
104  skia_enable_fontmgr_empty=false \
105  skia_enable_pdf=false"
106
107# Build all the libs, we'll link the appropriate ones down below
108${NINJA} -C ${BUILD_DIR} libskia.a libdebugcanvas.a
109
110export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js "
111
112echo "Generating final debugger wasm and javascript"
113
114# Emscripten prefers that the .a files go last in order, otherwise, it
115# may drop symbols that it incorrectly thinks aren't used. One day,
116# Emscripten will use LLD, which may relax this requirement.
117${EMCXX} \
118    $RELEASE_CONF \
119    -I. \
120    -Ithird_party/icu \
121    -Ithird_party/skcms \
122    -DSK_DISABLE_AAA \
123    -std=c++17 \
124    $WASM_GPU \
125    --pre-js $BASE_DIR/helper.js \
126    --post-js $BASE_DIR/ready.js \
127    --bind \
128    $BASE_DIR/fonts/NotoMono-Regular.ttf.cpp \
129    $BASE_DIR/debugger_bindings.cpp \
130    $BUILD_DIR/libdebugcanvas.a \
131    $BUILD_DIR/libskia.a \
132    -s ALLOW_MEMORY_GROWTH=1 \
133    -s EXPORT_NAME="DebuggerInit" \
134    -s FORCE_FILESYSTEM=0 \
135    -s MODULARIZE=1 \
136    -s NO_EXIT_RUNTIME=1 \
137    -s STRICT=1 \
138    -s TOTAL_MEMORY=128MB \
139    -s USE_FREETYPE=1 \
140    -s USE_LIBPNG=1 \
141    -s WARN_UNALIGNED=1 \
142    -s WASM=1 \
143    -s USE_WEBGL2=1 \
144    -o $BUILD_DIR/debugger.js
145
146# TODO(nifong): write unit tests
147