# Common Bazel settings for this workspace.

common --enable_bzlmod
common --enable_platform_specific_config
common --color=yes
common --heap_dump_on_oom
common:linux --host_platform=//platforms:local_linux_gnu
common:windows --host_platform=//platforms:local_windows_msvc
common --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
common --repo_env=BAZEL_NO_APPLE_CPP_TOOLCHAIN=1
common --@llvm//config:experimental_stub_libgcc_s=True

# Track source directory inputs used by rules_js/npm packages.
startup --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1

build --java_language_version=17
build --java_runtime_version=remotejdk_17
build --tool_java_language_version=17
build --tool_java_runtime_version=remotejdk_17

build --action_env=PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin

# Give me dem stack traces
build --verbose_failures
build --keep_going
build --show_result=20
build --noremote_upload_local_results
build --sandbox_default_allow_network=false
build --incompatible_default_to_explicit_init_py
build --enable_runfiles
test --test_output=errors
test --test_verbose_timeout_warnings

build --experimental_platform_in_output_dir
build --remote_cache_compression
build --legacy_important_outputs
build --remote_build_event_upload=minimal
build --noslim_profile
build --experimental_profile_include_target_label
build --experimental_profile_include_primary_output
common --bes_upload_mode=fully_async
common --noincompatible_no_implicit_watch_label

# Bazel will create symlinks from the workspace directory to output artifacts.
# Build results will be placed in a directory called "dist/bin"
# Other directories will be created like "dist/testlogs"
# Be aware that this will still create a bazel-out symlink in
# your project directory, which you must exclude from version control and your
# editor's search path.
# To disable the symlinks altogether (including bazel-out) you can use
# build --symlink_prefix=/
# however this makes it harder to find outputs.

# Support for debugging NodeJS tests
# Add the Bazel option `--config=debug` to enable this
# --compilation_mode=dbg
#     Rules may change their build outputs if the compilation mode is set to dbg. For example,
#     mininfiers such as terser may make their output more human readable when this is set. Rules will pass `COMPILATION_MODE`
#     to `nodejs_binary` executables via the actions.run env attribute.
#     See https://docs.bazel.build/versions/master/user-manual.html#flag--compilation_mode for more details.
test:debug --define=VERBOSE_LOGS=1
run:debug --define=VERBOSE_LOGS=1
run:debug -- --node_options=--inspect-brk
test:debug --test_output=streamed
test:debug --test_strategy=exclusive
test:debug --test_timeout=9999
test:debug --nocache_test_results
# The following option will change the build output of certain rules such as terser and may not be desirable in all cases
build:debug --compilation_mode=dbg

run --incompatible_strict_action_env

# Increase heap size
build --define=NODE_OPTIONS=--max-old-space-size=4096
build --build_metadata=REPO_URL=https://github.com/formatjs/formatjs.git

# gazelle_ts links a Rust rlib into Gazelle through Go/cgo. LLVM's Linux
# toolchain cannot link that as PIE, but Rust's musl release binary is
# static-pie, so keep no-pie scoped to Go linker flags instead of --linkopt.
build:linux --@rules_go//go/config:gc_linkopts=-extldflags,-no-pie

# BuildBuddy RBE GH Actions Config
# https://www.buildbuddy.io/docs/rbe-github-actions
build:ci --build_metadata=ROLE=CI
build:ci --build_metadata=VISIBILITY=PUBLIC
build:ci --config=rbe
build:ci --remote_upload_local_results
build:bb-workflow --build_metadata=ROLE=BB_WORKFLOW
build:bb-workflow --build_metadata=VISIBILITY=PUBLIC
build:bb-workflow --config=rbe
build:rbe --bes_backend=grpcs://formatjs.buildbuddy.io
build:rbe --bes_results_url=https://formatjs.buildbuddy.io/invocation/
build:rbe --define=EXECUTOR=rbe
build:rbe --extra_execution_platforms=//platforms:buildbuddy_linux_x86_64_gnu
build:rbe --@rules_go//go/config:gc_linkopts=-extldflags,-no-pie
build:rbe --jobs=50
build:rbe --platforms=//platforms:buildbuddy_linux_x86_64_gnu
build:rbe --remote_cache=grpcs://formatjs.buildbuddy.io
build:rbe --remote_executor=grpcs://formatjs.buildbuddy.io
build:rbe --remote_timeout=10m

# Keep the old config name as an alias for existing local workflows.
build:remote --config=rbe

# BuildBuddy config for macOS CI - remote cache only, no RBE
build:ci-darwin --build_metadata=ROLE=CI
build:ci-darwin --build_metadata=VISIBILITY=PUBLIC
build:ci-darwin --bes_backend=grpcs://formatjs.buildbuddy.io
build:ci-darwin --bes_results_url=https://formatjs.buildbuddy.io/invocation/
build:ci-darwin --remote_cache=grpcs://formatjs.buildbuddy.io
build:ci-darwin --remote_upload_local_results

# honor the setting of `skipLibCheck` in the tsconfig.json file
build --@aspect_rules_ts//ts:skipLibCheck=honor_tsconfig
fetch --@aspect_rules_ts//ts:skipLibCheck=honor_tsconfig
query --@aspect_rules_ts//ts:skipLibCheck=honor_tsconfig

# Use "tsc" as the transpiler when ts_project has no `transpiler` set.
build --@aspect_rules_ts//ts:default_to_tsc_transpiler
fetch --@aspect_rules_ts//ts:default_to_tsc_transpiler
query --@aspect_rules_ts//ts:default_to_tsc_transpiler

# Load any settings specific to the current user.
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
# This needs to be last statement in this
# config, as the user configuration should be able to overwrite flags from this file.
# See https://docs.bazel.build/versions/master/best-practices.html#bazelrc
# (Note that we use .bazelrc.user so the file appears next to .bazelrc in directory listing,
# rather than user.bazelrc as suggested in the Bazel docs)
try-import %workspace%/.bazelrc.user
