blob: 3eb910f55a06561c4f9c2206f07917c5cdfee203 [file] [log] [blame]
#!/bin/bash
#
# Copyright 2022 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Builds and copies artifacts for the Flutter embedder from your
# local source of the Flutter Engine repository.
#
# Usage:
# build_and_copy_engine_artifacts.sh
#
# Arguments:
# --goma: Uses goma to accelerate the Flutter Engine build.
# For Googlers only, sorry. :(
#
# All other arguments are forwarded to Flutter Engine's GN.
set -e # Fail on any error.
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/helpers.sh || exit $?
ensure-embedder-dir
ensure-engine-dir
# Parse arguments.
goma=0
goma_flags=""
ninja_cmd="ninja"
cpu="x64"
extra_gn_args=()
while [[ $# -gt 0 ]]; do
case $1 in
--goma)
goma=1
goma_flags="--goma"
ninja_cmd="autoninja"
shift # past argument
;;
--cpu)
shift # past argument
cpu="$1"
shift # past value
;;
*)
extra_gn_args+=("$1") # forward argument
shift # past argument
;;
esac
done
all_gn_args="--fuchsia --embedder-for-target --unopt ${goma_flags} ${extra_gn_args[@]} --fuchsia-cpu ${cpu}"
echo-info "Building the debug Flutter Engine embedding for Fuchsia (libflutter_engine.so) for ${cpu}..."
echo-info "... GN args: ${all_gn_args}"
"${embedder_engine_dir}"/flutter/tools/gn ${all_gn_args}
debug_out_dir="${embedder_engine_dir}"/out/fuchsia_debug_unopt_${cpu}
"${embedder_depot_tools}"/"${ninja_cmd}" -C "${debug_out_dir}"
echo-info "Copying debug Flutter Engine artifacts to ${FUCHSIA_EMBEDDER_DIR}/src/embedder/engine/debug_${cpu}..."
cp "${debug_out_dir}"/so.unstripped/libflutter_engine.so "${FUCHSIA_EMBEDDER_DIR}"/src/embedder/engine/debug_${cpu}/libflutter_engine.so
echo-info "Copying embedder.h to ${FUCHSIA_EMBEDDER_DIR}/src/embedder/engine..."
cp "${embedder_engine_dir}"/flutter/shell/platform/embedder/embedder.h "${FUCHSIA_EMBEDDER_DIR}"/src/embedder/engine
# TODO(akbiggs): Maybe copy debug symbols to the embedder repo so we get them
# without having to do an engine build ourselves. Or just always build
# libflutter_engine.so instead of checking it in.
echo-info "Registering debug symbols with ffx..."
"${FUCHSIA_EMBEDDER_DIR}"/tools/ffx debug symbol-index add "${debug_out_dir}"/.build-id --build-dir "${debug_out_dir}"