| # This file is licensed under the Apache License v2.0 with LLVM Exceptions. | |
| # See https://llvm.org/LICENSE.txt for license information. | |
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
| ############################################################################### | |
| # Common flags that apply to all configurations. | |
| # Use sparingly for things common to all compilers and platforms. | |
| ############################################################################### | |
| common --enable_bzlmod --noenable_workspace | |
| # Force the runfiles layout without the legacy `external/<repo>/...` mirror, | |
| # to match the Bazel 9+ default once --legacy_external_runfiles is removed. | |
| # All lit_expand_template callers use `File.short_path` (`../<repo>/...` | |
| # form) so no target relies on the legacy layout. | |
| common --nolegacy_external_runfiles | |
| # Prevent automatic __init__.py generation from confusing some lit tests. | |
| common --incompatible_default_to_explicit_init_py | |
| # Prevent invalid caching if input files are modified during a build. | |
| build --guard_against_concurrent_changes | |
| # Automatically enable --config=(linux|macos|windows) based on the host | |
| build --enable_platform_specific_config | |
| # Don't require a system python to run py_binary targets | |
| common --@rules_python//python/config_settings:bootstrap_impl=script | |
| # In opt mode, bazel by default builds both PIC and non-PIC object files for | |
| # tests vs binaries. We don't need this feature and it slows down opt builds | |
| # considerably. | |
| # TODO: Remove platform specifics we're on bazel 7.x https://github.com/bazelbuild/bazel/issues/12439 | |
| # Apple platforms always enable pic so this flag is unnecessary anyways | |
| build:linux --force_pic | |
| build:windows --force_pic | |
| # Shared objects take up more space. With fast linkers and binaries that aren't | |
| # super large, the benefits of shared objects are minimal. | |
| build --dynamic_mode=off | |
| # Rely on compiler flags to compile with debug info/strip rather than stripping | |
| # based on compilation_mode. | |
| build --strip=never | |
| # Add layering check to all projects. | |
| build --features=layering_check | |
| # Opt out of legacy lax behavior implicitly exporting files that are rule inputs | |
| # with default visibility. | |
| # See: https://bazel.build/reference/be/functions#exports_files | |
| build --incompatible_no_implicit_file_export | |
| # Enable so downstream users can flip this flag globally, this should | |
| # eventually become the default | |
| common --incompatible_disallow_empty_glob | |
| # Ensure config settings appropriately set visibility | |
| common --incompatible_config_setting_private_default_visibility | |
| # Avoid the legacy use of `cfg = "host"`. `cfg = "exec"` should be used in all | |
| # of these cases. | |
| common --incompatible_disable_starlark_host_transitions | |
| # Avoid the use of native Bazel rules that are planned to be exported into | |
| # independent repositories. | |
| common --incompatible_disable_native_repo_rules | |
| common --incompatible_autoload_externally= | |
| # Disable network access in sandboxes by default. | |
| build --sandbox_default_allow_network=false | |
| # Disabling runfiles links drastically increases performance in slow disk IO | |
| # situations Do not build runfile trees by default. If an execution strategy | |
| # relies on runfile symlink tree, the tree is created on-demand. See: | |
| # https://github.com/bazelbuild/bazel/issues/6627 and | |
| # https://github.com/bazelbuild/bazel/commit/03246077f948f2790a83520e7dccc2625650e6df | |
| build --build_runfile_links=false | |
| # Enable header processing to verify that header-only libraries are | |
| # self-contained (for sub-projects that enable "parse_headers" feature). | |
| # See https://bazel.build/docs/bazel-and-cpp#toolchain-features | |
| build --process_headers_in_dependencies | |
| ############################################################################### | |
| # Options for "generic_clang" builds: these options should generally apply to | |
| # builds using a Clang-based compiler, and default to the `clang` executable on | |
| # the `PATH`. While these are provided for convenience and may serve as a | |
| # reference, it would be preferable for users to configure an explicit C++ | |
| # toolchain instead of relying on `.bazelrc` files. | |
| ############################################################################### | |
| # Set the default compiler to the `clang` binary on the `PATH`. | |
| build:generic_clang --repo_env=CC=clang | |
| # C++17 standard version is required. | |
| build:generic_clang --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 | |
| # Use `-Wall` for Clang. | |
| build:generic_clang --copt=-Wall --host_copt=-Wall | |
| # The Clang available on MacOS has a warning that isn't clean on MLIR code. The | |
| # warning doesn't show up with more recent Clangs, so just disable for now. | |
| build:generic_clang --cxxopt=-Wno-range-loop-analysis --host_cxxopt=-Wno-range-loop-analysis | |
| # Build errors are not a helpful way to enforce deprecation in-repo and it is | |
| # not the point of the Bazel build to catch usage of deprecated APIs. | |
| build:generic_clang --copt=-Wno-deprecated --host_copt=-Wno-deprecated | |
| # lld links faster than other linkers. Assume that anybody using clang also has | |
| # lld available. | |
| build:generic_clang --linkopt=-fuse-ld=lld --host_linkopt=-fuse-ld=lld | |
| ############################################################################### | |
| # Options for "generic_gcc" builds: these options should generally apply to | |
| # builds using a GCC-based compiler, and default to the `gcc` executable on | |
| # the `PATH`. While these are provided for convenience and may serve as a | |
| # reference, it would be preferable for users to configure an explicit C++ | |
| # toolchain instead of relying on `.bazelrc` files. | |
| ############################################################################### | |
| # Set the default compiler to the `gcc` binary on the `PATH`. | |
| build:generic_gcc --repo_env=CC=gcc | |
| # C++17 standard version is required. | |
| build:generic_gcc --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 | |
| # Build errors are not a helpful way to enforce deprecation in-repo and it is | |
| # not the point of the Bazel build to catch usage of deprecated APIs. | |
| build:generic_gcc --copt=-Wno-deprecated --host_copt=-Wno-deprecated | |
| # Disable GCC warnings that are noisy and/or false positives on LLVM code. | |
| # These need to be global as some code triggering these is in header files. | |
| build:generic_gcc --copt=-Wno-unused-parameter --host_copt=-Wno-unused-parameter | |
| build:generic_gcc --copt=-Wno-comment --host_copt=-Wno-comment | |
| build:generic_gcc --cxxopt=-Wno-class-memaccess --host_cxxopt=-Wno-class-memaccess | |
| build:generic_gcc --copt=-Wno-maybe-uninitialized --host_copt=-Wno-maybe-uninitialized | |
| build:generic_gcc --copt=-Wno-misleading-indentation --host_copt=-Wno-misleading-indentation | |
| ############################################################################### | |
| # Generic Windows flags common to both MSVC and Clang. | |
| ############################################################################### | |
| # C++17 standard version is required. | |
| build:windows --cxxopt=/std:c++17 --host_cxxopt=/std:c++17 | |
| # Other generic dialect flags. | |
| build:windows --copt=/Zc:strictStrings --host_copt=/Zc:strictStrings | |
| build:windows --copt=/Oi --host_copt=/Oi | |
| build:windows --cxxopt=/Zc:rvalueCast --host_cxxopt=/Zc:rvalueCast | |
| # Use the more flexible bigobj format for C++ files that have lots of symbols. | |
| build:windows --cxxopt=/bigobj --host_cxxopt=/bigobj | |
| ############################################################################### | |
| # Windows specific flags for building with MSVC. | |
| ############################################################################### | |
| build:msvc --config=windows | |
| # Match LLVM's default MSVC conformance flags. Unlike the other flags here, | |
| # /Zc:__cplusplus only applies to C++ compilations. | |
| build:msvc --copt=/Zc:inline --host_copt=/Zc:inline | |
| build:msvc --cxxopt=/Zc:__cplusplus --host_cxxopt=/Zc:__cplusplus | |
| build:msvc --copt=/permissive- --host_copt=/permissive- | |
| # CMake enables the conforming preprocessor for cl.exe, but not clang-cl. | |
| build:msvc --copt=/Zc:preprocessor --host_copt=/Zc:preprocessor | |
| build:msvc --copt=/WX --host_copt=/WX # Treat warnings as errors... | |
| # ...but disable the ones that are violated | |
| build:msvc --copt=/wd4141 --host_copt=/wd4141 # inline used more than once | |
| build:msvc --copt=/wd4244 --host_copt=/wd4244 # conversion type -> type | |
| build:msvc --copt=/wd4267 --host_copt=/wd4267 # conversion size_t -> type | |
| build:msvc --copt=/wd4273 --host_copt=/wd4273 # multiple definitions with different dllimport | |
| build:msvc --copt=/wd4319 --host_copt=/wd4319 # zero-extending after complement | |
| build:msvc --copt=/wd4624 --host_copt=/wd4624 # destructor was implicitly defined as deleted | |
| build:msvc --copt=/wd4804 --host_copt=/wd4804 # comparisons between bool and int | |
| build:msvc --copt=/wd4805 --host_copt=/wd4805 # comparisons between bool and int | |
| build:msvc --linkopt=/WX --host_linkopt=/WX # Treat warnings as errors... | |
| # ...but disable the ones that are violated. | |
| build:msvc --linkopt=/IGNORE:4001 --host_linkopt=/IGNORE:4001 # no object files | |
| ############################################################################### | |
| # Options for Windows `clang-cl` builds. | |
| ############################################################################### | |
| # We just start with the baseline Windows config as `clang-cl` doesn't accept | |
| # some of the generic Clang flags. | |
| build:clang-cl --config=windows | |
| # Switch from MSVC to the `clang-cl` compiler. | |
| build:clang-cl --compiler=clang-cl | |
| # Match the conformance flags CMake applies to clang-cl. /Zc:preprocessor is | |
| # intentionally only part of the MSVC configuration above. | |
| build:clang-cl --copt=/Zc:inline --host_copt=/Zc:inline | |
| build:clang-cl --cxxopt=/Zc:__cplusplus --host_cxxopt=/Zc:__cplusplus | |
| build:clang-cl --copt=/permissive- --host_copt=/permissive- | |
| # Use Clang's internal warning flags instead of the ones that sometimes map | |
| # through to MSVC's flags. | |
| build:clang-cl --copt=/clang:-Wall --host_copt=/clang:-Wall | |
| build:clang-cl --copt=/clang:-Werror --host_copt=/clang:-Werror | |
| # This doesn't appear to be enforced by any upstream bot. | |
| build:clang-cl --copt=/clang:-Wno-unused --host_copt=/clang:-Wno-unused | |
| # There appears to be an unused constant in GoogleTest on Windows. | |
| build:clang-cl --copt=/clang:-Wno-unused-const-variable --host_copt=/clang:-Wno-unused-const-variable | |
| # Disable some warnings hit even with `clang-cl` in Clang's own code. | |
| build:clang-cl --copt=/clang:-Wno-inconsistent-dllimport --host_copt=/clang:-Wno-inconsistent-dllimport | |
| build:clang-cl --cxxopt=/clang:-Wno-c++11-narrowing --host_cxxopt=/clang:-Wno-c++11-narrowing | |
| ############################################################################### | |
| # Options for hermetic toolchain builds. | |
| ############################################################################### | |
| # Disable default toolchains | |
| build:hermetic-toolchain --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 | |
| build:hermetic-toolchain --repo_env=BAZEL_NO_APPLE_CPP_TOOLCHAIN=1 | |
| # Toolchain setup | |
| build:hermetic-toolchain --config=generic_clang | |
| build:hermetic-toolchain --repo_env=BAZEL_MACOS_FRAMEWORKS=CoreFoundation,CoreGraphics,CoreServices,DiskArbitration,CFNetwork,IOKit,Foundation,Security | |
| build:hermetic-toolchain --repo_env=BAZEL_MACOS_EXPERIMENTAL_INCLUDE_ALL_SDK_LIBS=1 | |
| build:hermetic-toolchain --extra_toolchains=@llvm//toolchain:all | |
| # TODO: The hermetic toolchain doesn't support these deps | |
| build:hermetic-toolchain --@llvm-project//libc:mpc=disable | |
| build:hermetic-toolchain --@llvm-project//libc:mpfr=disable | |
| build:hermetic-toolchain --@llvm-project//llvm:pfm=disable | |
| # TODO: Remove once @llvm is updated >0.7.1 | |
| build:hermetic-toolchain --copt=-Wno-modules-import-nested-redundant --host_copt=-Wno-modules-import-nested-redundant | |
| ############################################################################### | |
| # Options for Emscripten WebAssembly builds. | |
| ############################################################################### | |
| build:wasm --platforms=@emsdk//:platform_wasm | |
| # Match LLVM's single-threaded config and shut the runtime down when main returns. | |
| build:wasm --features=-use_pthreads,exit_runtime | |
| # Make the default CLI artifact use Node's host filesystem; browser builds override this to 0. | |
| build:wasm --linkopt=-sNODERAWFS=1 | |
| # TODO: zstd unconditionally enables pthreads on non-Windows targets. | |
| build:wasm --@llvm-project//third-party:llvm_enable_zstd=false | |
| ############################################################################### | |
| # Options for continuous integration. | |
| ############################################################################### | |
| # -O1 tries to provide a reasonable tradeoff between compile times and runtime | |
| # performance. However, if we start running more tests (e.g. all of | |
| # check-clang) we may want more optimizations. | |
| # Note for anybody considering using --compilation_mode=opt in CI, it builds | |
| # most files twice, one PIC version for shared libraries in tests, and one | |
| # non-PIC version for binaries. | |
| build:ci --copt=-O1 | |
| # Use clang. | |
| build:ci --config=generic_clang | |
| # Speedup bazel using a ramdisk. | |
| build:ci --sandbox_base=/dev/shm | |
| # Use system's mpfr and pfm instead of building it from source. | |
| # This is non hermetic but helps with compile time. | |
| build:ci --@llvm-project//libc:mpfr=system | |
| build:ci --@llvm-project//llvm:pfm=system | |
| # Don't build/test targets tagged with "nobuildkite". | |
| build:ci --build_tag_filters=-nobuildkite | |
| build:ci --test_tag_filters=-nobuildkite | |
| # Show as many errors as possible. | |
| build:ci --keep_going | |
| # Show test errors. | |
| build:ci --test_output=errors | |
| # Only show failing tests to reduce output | |
| build:ci --test_summary=terse | |
| # Attempt to work around intermittent issue while trying to fetch remote blob. | |
| # See e.g. https://github.com/bazelbuild/bazel/issues/18694. | |
| build:ci --remote_default_exec_properties=cache-silo-key=CleverPeafowl | |
| ############################################################################### | |
| # The user.bazelrc file is not checked in but available for local mods. | |
| # Always keep this at the end of the file so that user flags override. | |
| try-import %workspace%/user.bazelrc |