Fix building with -c dbg

Just create separate lists of flags (and corresponding features) for
each compilation mode, instead of trying to be cute with a default that
gets overriden.

Change-Id: Ib9741681030f5b88dcf200f0144156a626bc16aa
Signed-off-by: Brian Silverman <bsilver16384@gmail.com>
diff --git a/WORKSPACE b/WORKSPACE
index 4aaad5b..40cf405 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -161,13 +161,20 @@
     "-Wformat=2",
     "-Werror",
     "-ggdb3",
-    "-DAOS_DEBUG=0",
 ]
 
 llvm_cxxopts = [
     "-std=gnu++17",
 ]
 
+llvm_opt_copts = [
+    "-DAOS_DEBUG=0",
+]
+
+llvm_fastbuild_copts = [
+    "-DAOS_DEBUG=0",
+]
+
 llvm_dbg_copts = [
     "-DAOS_DEBUG=1",
 ]
@@ -193,9 +200,17 @@
     },
     dbg_copts = {
         "linux-x86_64": llvm_dbg_copts,
-        "linux-armv7": llvm_cxxopts,
+        "linux-armv7": llvm_dbg_copts,
+    },
+    fastbuild_copts = {
+        "linux-x86_64": llvm_fastbuild_copts,
+        "linux-armv7": llvm_fastbuild_copts,
     },
     llvm_version = llvm_version,
+    opt_copts = {
+        "linux-x86_64": llvm_opt_copts,
+        "linux-armv7": llvm_opt_copts,
+    },
     standard_libraries = {
         "linux-x86_64": "libstdc++-10",
         "linux-armv7": "libstdc++-10",
diff --git a/third_party/bazel-toolchain/bazel_tools_changes/tools/cpp/unix_cc_toolchain_config.bzl b/third_party/bazel-toolchain/bazel_tools_changes/tools/cpp/unix_cc_toolchain_config.bzl
index 8e49eda..8de828f 100755
--- a/third_party/bazel-toolchain/bazel_tools_changes/tools/cpp/unix_cc_toolchain_config.bzl
+++ b/third_party/bazel-toolchain/bazel_tools_changes/tools/cpp/unix_cc_toolchain_config.bzl
@@ -201,6 +201,15 @@
                 with_features = [with_feature_set(features = ["opt"])],
             ),
             flag_set(
+                actions = all_compile_actions,
+                flag_groups = ([
+                    flag_group(
+                        flags = ctx.attr.fastbuild_compile_flags,
+                    ),
+                ] if ctx.attr.fastbuild_compile_flags else []),
+                with_features = [with_feature_set(features = ["fastbuild"])],
+            ),
+            flag_set(
                 actions = [ACTION_NAMES.c_compile],
                 flag_groups = ([
                     flag_group(
@@ -255,6 +264,8 @@
 
     opt_feature = feature(name = "opt")
 
+    fastbuild_feature = feature(name = "fastbuild")
+
     sysroot_feature = feature(
         name = "sysroot",
         enabled = True,
@@ -1218,6 +1229,7 @@
             supports_dynamic_linker_feature,
             dbg_feature,
             opt_feature,
+            fastbuild_feature,
             user_compile_flags_feature,
             sysroot_feature,
             unfiltered_compile_flags_feature,
@@ -1238,6 +1250,7 @@
             supports_dynamic_linker_feature,
             dbg_feature,
             opt_feature,
+            fastbuild_feature,
             user_compile_flags_feature,
             sysroot_feature,
             unfiltered_compile_flags_feature,
@@ -1276,6 +1289,7 @@
         "compile_flags": attr.string_list(),
         "dbg_compile_flags": attr.string_list(),
         "opt_compile_flags": attr.string_list(),
+        "fastbuild_compile_flags": attr.string_list(),
         "cxx_flags": attr.string_list(),
         "c_flags": attr.string_list(),
         "compile_not_cxx_flags": attr.string_list(),
diff --git a/third_party/bazel-toolchain/toolchain/cc_toolchain_config.bzl b/third_party/bazel-toolchain/toolchain/cc_toolchain_config.bzl
index ccadb7c..e429c40 100644
--- a/third_party/bazel-toolchain/toolchain/cc_toolchain_config.bzl
+++ b/third_party/bazel-toolchain/toolchain/cc_toolchain_config.bzl
@@ -46,6 +46,7 @@
         copts,
         opt_copts,
         dbg_copts,
+        fastbuild_copts,
         linkopts,
         host_tools_info = {}):
     host_os_arch_key = _os_arch_pair(host_os, host_arch)
@@ -157,6 +158,9 @@
         "-fdata-sections",
     ]
 
+    fastbuild_compile_flags = [
+    ]
+
     link_flags = [
         "--target=" + target_system_name,
         "-lm",
@@ -396,6 +400,7 @@
     compile_flags.extend(copts)
     dbg_compile_flags.extend(dbg_copts)
     opt_compile_flags.extend(opt_copts)
+    fastbuild_compile_flags.extend(fastbuild_copts)
     link_flags.extend(linkopts)
 
     # Source: https://cs.opensource.google/bazel/bazel/+/master:tools/cpp/unix_cc_toolchain_config.bzl
@@ -414,6 +419,7 @@
         compile_flags = compile_flags,
         dbg_compile_flags = dbg_compile_flags,
         opt_compile_flags = opt_compile_flags,
+        fastbuild_compile_flags = fastbuild_compile_flags,
         cxx_flags = cxx_flags,
         c_flags = conlyopts,
         compile_not_cxx_flags = compile_not_cxx_flags,
diff --git a/third_party/bazel-toolchain/toolchain/internal/configure.bzl b/third_party/bazel-toolchain/toolchain/internal/configure.bzl
index 6a183fc..2d8124d 100644
--- a/third_party/bazel-toolchain/toolchain/internal/configure.bzl
+++ b/third_party/bazel-toolchain/toolchain/internal/configure.bzl
@@ -131,6 +131,7 @@
         copts_dict = rctx.attr.copts,
         opt_copts_dict = rctx.attr.opt_copts,
         dbg_copts_dict = rctx.attr.dbg_copts,
+        fastbuild_copts_dict = rctx.attr.fastbuild_copts,
         linkopts_dict = rctx.attr.linkopts,
     )
     host_tools_info = dict([
@@ -282,6 +283,7 @@
     copts = toolchain_info.copts_dict.get(key, [])
     opt_copts = toolchain_info.opt_copts_dict.get(key, [])
     dbg_copts = toolchain_info.dbg_copts_dict.get(key, [])
+    fastbuild_copts = toolchain_info.fastbuild_copts_dict.get(key, [])
     linkopts = toolchain_info.linkopts_dict.get(key, [])
     target_toolchain_root = toolchain_info.toolchain_root
     if key in toolchain_info.target_toolchain_roots_dict:
@@ -319,6 +321,7 @@
     copts = {copts},
     opt_copts = {opt_copts},
     dbg_copts = {dbg_copts},
+    fastbuild_copts = {fastbuild_copts},
     linkopts = {linkopts},
 )
 
@@ -437,5 +440,6 @@
         copts = copts,
         opt_copts = opt_copts,
         dbg_copts = dbg_copts,
+        fastbuild_copts = fastbuild_copts,
         linkopts = linkopts,
     )
diff --git a/third_party/bazel-toolchain/toolchain/rules.bzl b/third_party/bazel-toolchain/toolchain/rules.bzl
index f27e387..aad2d37 100644
--- a/third_party/bazel-toolchain/toolchain/rules.bzl
+++ b/third_party/bazel-toolchain/toolchain/rules.bzl
@@ -175,6 +175,13 @@
                "({}), ".format(", ".join(_supported_os_arch_keys())) +
                "used only with -c dbg."),
     ),
+    "fastbuild_copts": attr.string_list_dict(
+        mandatory = False,
+        doc = ("Extra flags for compiling C, C++, and assembly files, " +
+               "for each target OS and arch pair you want to support " +
+               "({}), ".format(", ".join(_supported_os_arch_keys())) +
+               "used only with -c fastbuild."),
+    ),
     "linkopts": attr.string_list_dict(
         mandatory = False,
         doc = ("Extra flags to pass to the linker, " +