# Note: Build V8 from source as the upstream does not provide enough
# binaries for the architectures we support.
abinfo "Patching rusty_v8 ..."
pushd "$SRCDIR"/../rusty_v8
ab_apply_patches "$SRCDIR"/autobuild/patches/*.deferred
popd

abinfo "Setting up environment for rusty_v8 ..."
CLANG_VERSION=$(clang --version | sed -n 's/clang version //p' | cut -d. -f1)

# Flags for building v8; inspired by app-web/chromium.
__GN_ARGS=(
    'chrome_pgo_phase=0'
    'fatal_linker_warnings=false'
    'treat_warnings_as_errors=false'
    'v8_enable_temporal_support=false'
    'is_debug=false'
    'use_sysroot=false'
    "clang_version=\"${CLANG_VERSION}\""
    'clang_base_path="/usr"'
    "custom_toolchain=\"//build/toolchain/linux/unbundle:default\""
    "host_toolchain=\"//build/toolchain/linux/unbundle:default\""
)

export GN_ARGS="${__GN_ARGS[@]}"
export GN="/usr/bin/gn"
export AR="/usr/bin/llvm-ar"
export NM="/usr/bin/llvm-nm"
export BUILD_AR="/usr/bin/llvm-ar"
export BUILD_NM="/usr/bin/llvm-nm"
export NINJA="/usr/bin/ninja"
export PYTHON="/usr/bin/python3"
export CLANG_BASE_PATH="/usr"
export V8_FROM_SOURCE=1
