[llvm] [bazel] Add an LLVM ABI-breaking checks build setting (PR #203739)

David Zbarsky via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 13 19:25:09 PDT 2026


https://github.com/dzbarsky updated https://github.com/llvm/llvm-project/pull/203739

>From ae9c70ac0e030c937b667c721314a2cc3d7d0b75 Mon Sep 17 00:00:00 2001
From: David Zbarsky <dzbarsky at gmail.com>
Date: Sat, 13 Jun 2026 22:12:03 -0400
Subject: [PATCH] [bazel] Add an LLVM ABI-breaking checks build setting

Add the default-off //llvm:enable_abi_breaking_checks build setting. When
the setting is enabled, generate LLVM_ENABLE_ABI_BREAKING_CHECKS=1.

The setting changes LLVM's C++ ABI and allows Bazel builds to opt into
checks guarded by LLVM_ENABLE_ABI_BREAKING_CHECKS while preserving the
existing default.
---
 .../llvm-project-overlay/llvm/BUILD.bazel     | 28 +++++++++++++++----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
index 3893710cf3c8f..2a2c3095592a9 100644
--- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -2,7 +2,7 @@
 # See https://llvm.org/LICENSE.txt for license information.
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
-load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
+load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
 load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
 load("@bazel_skylib//rules:write_file.bzl", "write_file")
 load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
@@ -26,6 +26,20 @@ package(
 
 licenses(["notice"])
 
+# Enable checks that alter LLVM's C++ ABI. Usage:
+#   bazel build -- at llvm-project//llvm:enable_abi_breaking_checks=true @llvm-project//llvm:llvm
+bool_flag(
+    name = "enable_abi_breaking_checks",
+    build_setting_default = False,
+)
+
+config_setting(
+    name = "abi_breaking_checks_enabled",
+    flag_values = {
+        ":enable_abi_breaking_checks": "true",
+    },
+)
+
 exports_files([
     "LICENSE.TXT",
     "cmake/modules/llvm-driver-template.cpp.in",
@@ -205,12 +219,16 @@ expand_template(
     name = "abi_breaking_h_gen",
     out = "include/llvm/Config/abi-breaking.h",
     substitutions = {
-        # Define to enable checks that alter the LLVM C++ ABI
-        "#cmakedefine01 LLVM_ENABLE_ABI_BREAKING_CHECKS": "#define LLVM_ENABLE_ABI_BREAKING_CHECKS 0",
-
         # Define to enable reverse iteration of unordered llvm containers
         "#cmakedefine01 LLVM_ENABLE_REVERSE_ITERATION": "#define LLVM_ENABLE_REVERSE_ITERATION 0",
-    },
+    } | select({
+        ":abi_breaking_checks_enabled": {
+            "#cmakedefine01 LLVM_ENABLE_ABI_BREAKING_CHECKS": "#define LLVM_ENABLE_ABI_BREAKING_CHECKS 1",
+        },
+        "//conditions:default": {
+            "#cmakedefine01 LLVM_ENABLE_ABI_BREAKING_CHECKS": "#define LLVM_ENABLE_ABI_BREAKING_CHECKS 0",
+        },
+    }),
     template = "include/llvm/Config/abi-breaking.h.cmake",
 )
 



More information about the llvm-commits mailing list