• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 Google LLC
2#
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6
7set -ex
8
9BASE_DIR=`cd $(dirname ${BASH_SOURCE[0]}) && pwd`
10# This expects the environment variable EMSDK to be set
11if [[ ! -d $EMSDK ]]; then
12  echo "Be sure to set the EMSDK environment variable."
13  exit 1
14fi
15
16# Navigate to SKIA_HOME from where this file is located.
17pushd $BASE_DIR/../..
18
19source $EMSDK/emsdk_env.sh
20EMCC=`which emcc`
21EMCXX=`which em++`
22
23BUILD_DIR=${BUILD_DIR:="out/debugger_wasm"}
24mkdir -p $BUILD_DIR
25
26BUILTIN_FONT="$BASE_DIR/fonts/NotoMono-Regular.ttf.cpp"
27# Generate the font's binary file (which is covered by .gitignore)
28python tools/embed_resources.py \
29    --name SK_EMBEDDED_FONTS \
30    --input $BASE_DIR/fonts/NotoMono-Regular.ttf \
31    --output $BASE_DIR/fonts/NotoMono-Regular.ttf.cpp \
32    --align 4
33
34NINJA=`which ninja`
35
36./bin/fetch-gn
37
38echo "Compiling bitcode"
39
40./bin/gn gen ${BUILD_DIR} \
41  --args="cc=\"${EMCC}\" \
42  cxx=\"${EMCXX}\" \
43  extra_cflags_cc=[\"-frtti\"] \
44  extra_cflags=[\"-s\",\"USE_FREETYPE=1\",\"-s\",\"USE_LIBPNG=1\", \"-s\", \"WARN_UNALIGNED=1\",
45    \"-DSKNX_NO_SIMD\", \"-DSK_DISABLE_AAA\", \"-DSK_DISABLE_DAA\"
46  ] \
47  is_debug=false \
48  is_official_build=true \
49  is_component_build=false \
50  target_cpu=\"wasm\" \
51  \
52  skia_use_angle = false \
53  skia_use_dng_sdk=false \
54  skia_use_egl=true \
55  skia_use_expat=false \
56  skia_use_fontconfig=false \
57  skia_use_freetype=true \
58  skia_use_libheif=false \
59  skia_use_libjpeg_turbo=true \
60  skia_use_libpng=true \
61  skia_use_libwebp=true \
62  skia_use_wuffs=true \
63  skia_use_lua=false \
64  skia_use_piex=false \
65  skia_use_system_libpng=true \
66  skia_use_system_freetype2=true \
67  skia_use_system_libjpeg_turbo = false \
68  skia_use_system_libwebp=false \
69  skia_use_vulkan=false \
70  skia_use_zlib=true \
71  skia_enable_gpu=true \
72  skia_enable_tools=false \
73  skia_enable_skshaper=false \
74  skia_enable_ccpr=false \
75  skia_enable_nvpr=false \
76  skia_enable_skpicture=true \
77  skia_enable_fontmgr_empty=false \
78  skia_enable_pdf=false"
79
80# Build all the libs, we'll link the appropriate ones down below
81${NINJA} -C ${BUILD_DIR} libskia.a libdebugcanvas.a
82
83export EMCC_CLOSURE_ARGS="--externs $BASE_DIR/externs.js "
84
85echo "Generating final wasm"
86
87# Emscripten prefers that the .a files go last in order, otherwise, it
88# may drop symbols that it incorrectly thinks aren't used. One day,
89# Emscripten will use LLD, which may relax this requirement.
90${EMCXX} \
91    --closure 1 \
92    -Iexperimental \
93    -Iinclude/c \
94    -Iinclude/codec \
95    -Iinclude/config \
96    -Iinclude/core \
97    -Iinclude/effects \
98    -Iinclude/gpu \
99    -Iinclude/gpu/gl \
100    -Iinclude/pathops \
101    -Iinclude/private \
102    -Iinclude/utils/ \
103    -Isrc/core/ \
104    -Isrc/gpu/ \
105    -Isrc/sfnt/ \
106    -Isrc/shaders/ \
107    -Isrc/utils/ \
108    -Ithird_party/icu \
109    -Itools \
110    -Itools/debugger \
111    -DSK_DISABLE_AAA \
112    -DSK_DISABLE_DAA \
113    -std=c++14 \
114    --pre-js $BASE_DIR/cpu.js \
115    --post-js $BASE_DIR/ready.js \
116    --bind \
117    $BASE_DIR/fonts/NotoMono-Regular.ttf.cpp \
118    $BASE_DIR/debugger_bindings.cpp \
119    $BUILD_DIR/libdebugcanvas.a \
120    $BUILD_DIR/libskia.a \
121    -s ALLOW_MEMORY_GROWTH=1 \
122    -s EXPORT_NAME="DebuggerInit" \
123    -s FORCE_FILESYSTEM=0 \
124    -s MODULARIZE=1 \
125    -s NO_EXIT_RUNTIME=1 \
126    -s STRICT=1 \
127    -s TOTAL_MEMORY=128MB \
128    -s USE_FREETYPE=1 \
129    -s USE_LIBPNG=1 \
130    -s WARN_UNALIGNED=1 \
131    -s WASM=1 \
132    -o $BUILD_DIR/debugger.js
133
134# TODO(nifong): write unit tests
135