Przeglądaj źródła

Cleanup debug flags and enable libc++ debugging on Linux. (#835)

The big change here is to enable libc++'s debug mode outside of `opt`
builds on Linux where it seems to work well with the Homebrew installed
toolchain. I'm restricting it to Linux as the system libc++ install on
x86 macOS doesn't seem to work. This is based on and subsumes #811.

This also tidies up how `-NDEBUG` is set to include non-codegen compile
actions, and consolidates some optimization flags in a single location.
This part has no functionality change, but would likely invalidate
caches so bundled here where both a) I noticed and b) we already had
a cache invalidation.
Chandler Carruth 4 lat temu
rodzic
commit
bc658e6923
1 zmienionych plików z 25 dodań i 8 usunięć
  1. 25 8
      bazel/cc_toolchains/clang_cc_toolchain_config.bzl

+ 25 - 8
bazel/cc_toolchains/clang_cc_toolchain_config.bzl

@@ -169,13 +169,11 @@ def _impl(ctx):
                 flag_groups = ([
                     flag_group(
                         flags = [
-                            "-DNDEBUG",
                             "-ffunction-sections",
                             "-fdata-sections",
                         ],
                     ),
                 ]),
-                with_features = [with_feature_set(features = ["opt"])],
             ),
             flag_set(
                 actions = codegen_compile_actions,
@@ -284,12 +282,20 @@ def _impl(ctx):
         name = "default_optimization_flags",
         enabled = True,
         requires = [feature_set(["opt"])],
-        flag_sets = [flag_set(
-            actions = codegen_compile_actions,
-            flag_groups = [flag_group(flags = [
-                "-O3",
-            ])],
-        )],
+        flag_sets = [
+            flag_set(
+                actions = all_compile_actions,
+                flag_groups = [flag_group(flags = [
+                    "-DNDEBUG",
+                ])],
+            ),
+            flag_set(
+                actions = codegen_compile_actions,
+                flag_groups = [flag_group(flags = [
+                    "-O3",
+                ])],
+            ),
+        ],
     )
 
     # Handle different levels and forms of debug info emission with individual
@@ -518,6 +524,17 @@ def _impl(ctx):
                     ),
                 ]),
             ),
+            flag_set(
+                actions = all_compile_actions,
+                flag_groups = [flag_group(flags = [
+                    # Enable libc++'s debug features.
+                    "-D_LIBCXX_DEBUG=1",
+                ])],
+                with_features = [
+                    with_feature_set(features = ["dbg"]),
+                    with_feature_set(features = ["fastbuild"]),
+                ],
+            ),
         ],
     )