• 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++`
23EMAR=`which emar`
24
25if [[ $@ == *debug* ]]; then
26  echo "Building a Debug build"
27  EXTRA_CFLAGS="\"-DSK_DEBUG\","
28  RELEASE_CONF="-O0 --js-opts 0 -s DEMANGLE_SUPPORT=1 -s ASSERTIONS=1 -s GL_ASSERTIONS=1 -g3 \
29                --source-map-base /node_modules/debugger/bin/ -DSK_DEBUG"
30  BUILD_DIR=${BUILD_DIR:="out/debugger_wasm_debug"}
31else
32  echo "Building a Release build"
33  EXTRA_CFLAGS="\"-DSK_RELEASE\","
34  RELEASE_CONF="-Oz --closure 1 --llvm-lto 3 -DSK_RELEASE"
35  BUILD_DIR=${BUILD_DIR:="out/debugger_wasm"}
36fi
37
38mkdir -p $BUILD_DIR
39# sometimes the .a files keep old symbols around - cleaning them out makes sure
40# we get a fresh build.
41rm -f $BUILD_DIR/*.a
42
43BUILTIN_FONT="$BASE_DIR/fonts/NotoMono-Regular.ttf.cpp"
44# Generate the font's binary file (which is covered by .gitignore)
45python tools/embed_resources.py \
46    --name SK_EMBEDDED_FONTS \
47    --input $BASE_DIR/fonts/NotoMono-Regular.ttf \
48    --output $BASE_DIR/fonts/NotoMono-Regular.ttf.cpp \
49    --align 4
50
51GN_GPU_FLAGS="\"-DSK_DISABLE_LEGACY_SHADERCONTEXT\","
52WASM_GPU="-lEGL -lGL -lGLESv2 -DSK_SUPPORT_GPU=1 -DSK_GL \
53          -DSK_DISABLE_LEGACY_SHADERCONTEXT --pre-js $BASE_DIR/cpu.js --pre-js $BASE_DIR/gpu.js"
54
55# Turn off exiting while we check for ninja (which may not be on PATH)
56set +e
57NINJA=`which ninja`
58if [[ -z $NINJA ]]; then
59  git clone "https://chromium.googlesource.com/chromium/tools/depot_tools.git" --depth 1 $BUILD_DIR/depot_tools
60  NINJA=$BUILD_DIR/depot_tools/ninja
61fi
62# Re-enable error checking
63set -e
64
65./bin/fetch-gn
66
67echo "Compiling bitcode"
68
69./bin/gn gen ${BUILD_DIR} \
70  --args="cc=\"${EMCC}\" \
71  cxx=\"${EMCXX}\" \
72  ar=\"${EMAR}\" \
73  extra_cflags_cc=[\"-frtti\"] \
74  extra_cflags=[\"-s\", \"MAIN_MODULE=1\",
75    \"-DSKNX_NO_SIMD\", \"-DSK_DISABLE_AAA\",
76    \"-DSK_FORCE_8_BYTE_ALIGNMENT\",
77    ${GN_GPU_FLAGS}
78    ${EXTRA_CFLAGS}
79  ] \
80  is_debug=false \
81  is_official_build=true \
82  is_component_build=false \
83  werror=true \
84  target_cpu=\"wasm\" \
85  \
86  skia_use_angle=false \
87  skia_use_dng_sdk=false \
88  skia_use_webgl=true \
89  skia_use_expat=false \
90  skia_use_fontconfig=false \
91  skia_use_freetype=true \
92  skia_use_libheif=false \
93  skia_use_libjpeg_turbo_decode=true \
94  skia_use_libjpeg_turbo_encode=false \
95  skia_use_libpng_decode=true \
96  skia_use_libpng_encode=false \
97  skia_use_libwebp_decode=true \
98  skia_use_libwebp_encode=false \
99  skia_use_wuffs=true \
100  skia_use_lua=false \
101  skia_use_piex=false \
102  skia_use_system_libpng=false \
103  skia_use_system_freetype2=false \
104  skia_use_system_libjpeg_turbo = false \
105  skia_use_system_libwebp=false \
106  skia_use_system_zlib=false\
107  skia_use_vulkan=false \
108  skia_use_zlib=true \
109  skia_enable_gpu=true \
110  skia_gl_standard=\"webgl\" \
111  skia_enable_tools=false \
112  skia_enable_skshaper=false \
113  skia_enable_fontmgr_custom_directory=false \
114  skia_enable_fontmgr_custom_embedded=true \
115  skia_enable_fontmgr_custom_empty=false \
116  skia_enable_pdf=false"
117
118# Build all the libs, we'll link the appropriate ones down below
119${NINJA} -C ${BUILD_DIR} libskia.a libdebugcanvas.a
120
121export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js "
122
123echo "Generating final wasm"
124
125# Emscripten prefers that the .a files go last in order, otherwise, it
126# may drop symbols that it incorrectly thinks aren't used. One day,
127# Emscripten will use LLD, which may relax this requirement.
128EMCC_DEBUG=1 ${EMCXX} \
129    $RELEASE_CONF \
130    -I. \
131    -Ithird_party/icu \
132    -Ithird_party/skcms \
133    -DSK_DISABLE_AAA \
134    -DSK_FORCE_8_BYTE_ALIGNMENT \
135    -std=c++17 \
136    $WASM_GPU \
137    --pre-js $BASE_DIR/helper.js \
138    --bind \
139    --no-entry \
140    $BASE_DIR/fonts/NotoMono-Regular.ttf.cpp \
141    $BASE_DIR/debugger_bindings.cpp \
142    $BUILD_DIR/libdebugcanvas.a \
143    $BUILD_DIR/libskia.a \
144    -s ALLOW_MEMORY_GROWTH=1 \
145    -s EXPORT_NAME="DebuggerInit" \
146    -s FORCE_FILESYSTEM=0 \
147    -s FILESYSTEM=0 \
148    -s MODULARIZE=1 \
149    -s NO_EXIT_RUNTIME=1 \
150    -s STRICT=1 \
151    -s INITIAL_MEMORY=128MB \
152    -s WASM=1 \
153    -s USE_WEBGL2=1 \
154    -o $BUILD_DIR/debugger.js
155