# Note: Build V8 from source as the upstream does not provide enough
# binaries for the architectures we support.
abinfo "Setting up environment for rusty_v8 ..."
CLANG_VERSION=$(clang --version | sed -n 's/clang version //p' | cut -d. -f1)
__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 NINJA="/usr/bin/ninja"
export PYTHON="/usr/bin/python3"
export CLANG_BASE_PATH="/usr"
export V8_FROM_SOURCE=1

# FIXME:
# [...]/codex/codex-rs/linux-sandbox/../vendor/bubblewrap/bind-mount.c:398:(.text.bind_mount+0x7c): relocation truncated to fit: R_LARCH_B26 against symbol `mount@@GLIBC_2.36' defined in .text section in /usr/lib/libc.so.6
# /usr/bin/ld: [...]/codex/codex-rs/target/release/deps/rustceh2GWY/libcodex_linux_sandbox-fc6385a7043f333c.rlib(2b80fc795abff254-bind-mount.o): relocation R_LARCH_B26 overflow 0xfffffffff7646140 
if ab_match_arch loongarch64 || \
   ab_match_arch loongarch64_nosimd; then
    export RUSTFLAGS="${RUSTFLAGS} -Ccode-model=medium"
fi
