0039874105
In this CL, I forked compile.sh and created a new gm_bindings.cpp. I also moved viewer.html into wasm_tools and created a gmtests.html for testing out the bindings locally. Right now there is only one gm file compiled in. I plan in a followup CL to have some way to generate the list of cpp files that need to be compiled in from gms.gni. I was unable to get it to work with simply linking the lib_gm.gni, probably due to the same issue with Registry that csmartdalton@ ran into when adding viewer.html and the associated bindings. Suggested reviewing order: - gmtests.html to get a sense of how the test flow works. - gm_bindings.cpp to make sure I setup the contexts/GMs correctly. - compile_gm.sh to see how the gms are compiled in. - The remaining files in any order. When I tested this locally, the bleed_downscale digest was exactly the same (pixel for pixel, byte for byte) as a known digest in Gold, so I'm fairly confident in how things work. Change-Id: I2babef848ca60f7db74e4adf27b8952a66bdeee1 Bug: skia:10812 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322956 Reviewed-by: Chris Dalton <csmartdalton@google.com> Commit-Queue: Kevin Lubick <kjlubick@google.com>
189 lines
5.5 KiB
Bash
Executable File
189 lines
5.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# Copyright 2020 Google LLC
|
|
#
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
set -ex
|
|
|
|
BASE_DIR=`cd $(dirname ${BASH_SOURCE[0]}) && pwd`
|
|
# This expects the environment variable EMSDK to be set
|
|
if [[ ! -d $EMSDK ]]; then
|
|
cat >&2 << "EOF"
|
|
Be sure to set the EMSDK environment variable to the location of Emscripten SDK:
|
|
|
|
https://emscripten.org/docs/getting_started/downloads.html
|
|
EOF
|
|
exit 1
|
|
fi
|
|
|
|
# Navigate to SKIA_HOME from where this file is located.
|
|
pushd $BASE_DIR/../..
|
|
|
|
source $EMSDK/emsdk_env.sh
|
|
EMCC=`which emcc`
|
|
EMCXX=`which em++`
|
|
EMAR=`which emar`
|
|
|
|
RELEASE_CONF="-O3 -DSK_RELEASE --pre-js $BASE_DIR/release.js \
|
|
-DGR_GL_CHECK_ALLOC_WITH_GET_ERROR=0 -DGR_TEST_UTILS"
|
|
EXTRA_CFLAGS="\"-DSK_RELEASE\", \"-DGR_GL_CHECK_ALLOC_WITH_GET_ERROR=0\", \"-DGR_TEST_UTILS\", "
|
|
IS_OFFICIAL_BUILD="false"
|
|
|
|
BUILD_DIR=${BUILD_DIR:="out/wasm_gm_tests"}
|
|
|
|
mkdir -p $BUILD_DIR
|
|
# sometimes the .a files keep old symbols around - cleaning them out makes sure
|
|
# we get a fresh build.
|
|
rm -f $BUILD_DIR/*.a
|
|
|
|
GN_GPU="skia_enable_gpu=true skia_gl_standard = \"webgl\""
|
|
GN_GPU_FLAGS="\"-DSK_DISABLE_LEGACY_SHADERCONTEXT\","
|
|
WASM_GPU="-lGL -DSK_SUPPORT_GPU=1 -DSK_GL \
|
|
-DSK_DISABLE_LEGACY_SHADERCONTEXT --pre-js $BASE_DIR/cpu.js --pre-js $BASE_DIR/gpu.js\
|
|
-s USE_WEBGL2=1"
|
|
|
|
GM_LIB="$BUILD_DIR/libgm_wasm.a"
|
|
|
|
GN_FONT="skia_enable_fontmgr_custom_directory=false "
|
|
BUILTIN_FONT="$BASE_DIR/fonts/NotoMono-Regular.ttf.cpp"
|
|
# Generate the font's binary file (which is covered by .gitignore)
|
|
python tools/embed_resources.py \
|
|
--name SK_EMBEDDED_FONTS \
|
|
--input $BASE_DIR/fonts/NotoMono-Regular.ttf \
|
|
--output $BASE_DIR/fonts/NotoMono-Regular.ttf.cpp \
|
|
--align 4
|
|
GN_FONT+="skia_enable_fontmgr_custom_embedded=true skia_enable_fontmgr_custom_empty=false"
|
|
|
|
|
|
GN_SHAPER="skia_use_icu=true skia_use_system_icu=false skia_use_harfbuzz=true skia_use_system_harfbuzz=false"
|
|
#SHAPER_LIB="$BUILD_DIR/libharfbuzz.a $BUILD_DIR/libicu.a"
|
|
SHAPER_LIB=""
|
|
|
|
DO_DECODE="true"
|
|
ENCODE_PNG="true"
|
|
ENCODE_JPEG="false"
|
|
ENCODE_WEBP="false"
|
|
|
|
# Turn off exiting while we check for ninja (which may not be on PATH)
|
|
set +e
|
|
NINJA=`which ninja`
|
|
if [[ -z $NINJA ]]; then
|
|
git clone "https://chromium.googlesource.com/chromium/tools/depot_tools.git" --depth 1 $BUILD_DIR/depot_tools
|
|
NINJA=$BUILD_DIR/depot_tools/ninja
|
|
fi
|
|
# Re-enable error checking
|
|
set -e
|
|
|
|
./bin/fetch-gn
|
|
|
|
echo "Compiling bitcode"
|
|
|
|
# With emsdk 2.0.0 we get a false positive on tautological-value-range-compare. This appears to be
|
|
# fixed in the emsdk 2.0.4 toolchain. Disable the warning while we maintain support for 2.0.0.
|
|
EXTRA_CFLAGS+="\"-Wno-tautological-value-range-compare\","
|
|
|
|
# Inspired by https://github.com/Zubnix/skia-wasm-port/blob/master/build_bindings.sh
|
|
./bin/gn gen ${BUILD_DIR} \
|
|
--args="cc=\"${EMCC}\" \
|
|
cxx=\"${EMCXX}\" \
|
|
ar=\"${EMAR}\" \
|
|
extra_cflags_cc=[\"-frtti\"] \
|
|
extra_cflags=[\"-s\", \"WARN_UNALIGNED=1\", \"-s\", \"MAIN_MODULE=1\",
|
|
\"-DSKNX_NO_SIMD\", \"-DSK_DISABLE_AAA\",
|
|
\"-DSK_FORCE_8_BYTE_ALIGNMENT\",
|
|
${GN_GPU_FLAGS}
|
|
${EXTRA_CFLAGS}
|
|
] \
|
|
is_debug=false \
|
|
is_official_build=${IS_OFFICIAL_BUILD} \
|
|
is_component_build=false \
|
|
werror=true \
|
|
target_cpu=\"wasm\" \
|
|
\
|
|
skia_use_angle=false \
|
|
skia_use_dng_sdk=false \
|
|
skia_use_webgl=true \
|
|
skia_use_fontconfig=false \
|
|
skia_use_freetype=true \
|
|
skia_use_libheif=false \
|
|
skia_use_libjpeg_turbo_decode=${DO_DECODE} \
|
|
skia_use_libjpeg_turbo_encode=${ENCODE_JPEG} \
|
|
skia_use_libpng_decode=${DO_DECODE} \
|
|
skia_use_libpng_encode=${ENCODE_PNG} \
|
|
skia_use_libwebp_decode=${DO_DECODE} \
|
|
skia_use_libwebp_encode=${ENCODE_WEBP} \
|
|
skia_use_lua=false \
|
|
skia_use_piex=false \
|
|
skia_use_system_freetype2=false \
|
|
skia_use_system_libjpeg_turbo=false \
|
|
skia_use_system_libpng=false \
|
|
skia_use_system_libwebp=false \
|
|
skia_use_system_zlib=false\
|
|
skia_use_vulkan=false \
|
|
skia_use_wuffs=true \
|
|
skia_use_zlib=true \
|
|
\
|
|
${GN_SHAPER} \
|
|
${GN_GPU} \
|
|
${GN_FONT} \
|
|
skia_use_expat=false \
|
|
skia_enable_ccpr=false \
|
|
\
|
|
skia_enable_skshaper=true \
|
|
skia_enable_nvpr=false \
|
|
skia_enable_skparagraph=true \
|
|
skia_enable_pdf=false"
|
|
|
|
# Build all the libs we will need below
|
|
parse_targets() {
|
|
for LIBPATH in $@; do
|
|
basename $LIBPATH
|
|
done
|
|
}
|
|
${NINJA} -C ${BUILD_DIR} libskia.a libskshaper.a \
|
|
$(parse_targets $SHAPER_LIB $GM_LIB)
|
|
|
|
echo "Generating final wasm"
|
|
|
|
# Disable '-s STRICT=1' outside of Linux until
|
|
# https://github.com/emscripten-core/emscripten/issues/12118 is resovled.
|
|
STRICTNESS="-s STRICT=1"
|
|
if [[ `uname` != "Linux" ]]; then
|
|
echo "Disabling '-s STRICT=1'. See: https://github.com/emscripten-core/emscripten/issues/12118"
|
|
STRICTNESS=""
|
|
fi
|
|
|
|
# Emscripten prefers that the .a files go last in order, otherwise, it
|
|
# may drop symbols that it incorrectly thinks aren't used. One day,
|
|
# Emscripten will use LLD, which may relax this requirement.
|
|
EMCC_DEBUG=1 ${EMCXX} \
|
|
$RELEASE_CONF \
|
|
-I. \
|
|
-DSK_DISABLE_AAA \
|
|
-DSK_FORCE_8_BYTE_ALIGNMENT \
|
|
$WASM_GPU \
|
|
-std=c++17 \
|
|
--bind \
|
|
--no-entry \
|
|
--pre-js $BASE_DIR/gm.js \
|
|
$BASE_DIR/gm_bindings.cpp \
|
|
gm/bleed.cpp \
|
|
gm/gm.cpp \
|
|
$GM_LIB \
|
|
$BUILD_DIR/libskshaper.a \
|
|
$SHAPER_LIB \
|
|
$BUILD_DIR/libskia.a \
|
|
$BUILTIN_FONT \
|
|
-s LLD_REPORT_UNDEFINED \
|
|
-s ALLOW_MEMORY_GROWTH=1 \
|
|
-s EXPORT_NAME="InitWasmGMTests" \
|
|
-s FORCE_FILESYSTEM=0 \
|
|
-s FILESYSTEM=0 \
|
|
-s MODULARIZE=1 \
|
|
-s NO_EXIT_RUNTIME=1 \
|
|
-s INITIAL_MEMORY=128MB \
|
|
-s WASM=1 \
|
|
$STRICTNESS \
|
|
-o $BUILD_DIR/wasm_gm_tests.js
|