From af1d81a66adbe4218c6271d1d037da3d73be42ac Mon Sep 17 00:00:00 2001
From: Eleni Mathioulaki <emathioulaki@athenarc.gr>
Date: Sat, 9 Sep 2023 13:03:11 +0300
Subject: [PATCH] bazel patches from upstream

---
 packages/bazel/apple-clang-14.0.3.patch       | 13 ++++
 packages/bazel/bazelconfiguration-0.3.patch   | 16 +++++
 .../bazel/bazelruleclassprovider-0.14.patch   | 16 +++++
 .../bazel/bazelruleclassprovider-0.25.patch   | 16 +++++
 .../bazelruleclassprovider_fj-0.25.patch      | 11 ++++
 packages/bazel/blaze_util_posix-0.29.1.patch  | 12 ++++
 packages/bazel/build-0.29.1.patch             | 61 +++++++++++++++++++
 packages/bazel/cc_configure-0.3.0.patch       | 24 ++++++++
 packages/bazel/cc_configure-0.5.0.patch       | 24 ++++++++
 packages/bazel/compile-0.13.patch             | 11 ++++
 packages/bazel/compile-0.16.patch             | 11 ++++
 packages/bazel/compile-0.21.patch             | 11 ++++
 packages/bazel/compile-0.29.patch             | 11 ++++
 packages/bazel/compile-0.3.patch              | 11 ++++
 packages/bazel/compile-0.4.patch              | 11 ++++
 packages/bazel/compile-0.6.patch              | 11 ++++
 packages/bazel/compile-0.9.patch              | 11 ++++
 packages/bazel/cppcompileaction-0.3.0.patch   | 11 ++++
 packages/bazel/cppcompileaction-0.3.2.patch   | 11 ++++
 packages/bazel/gcc11_1.patch                  | 12 ++++
 packages/bazel/gcc11_2.patch                  | 14 +++++
 packages/bazel/gcc11_3.patch                  | 17 ++++++
 packages/bazel/gcc11_4.patch                  | 44 +++++++++++++
 packages/bazel/unix_cc_configure-0.10.patch   | 22 +++++++
 packages/bazel/unix_cc_configure-0.15.patch   | 22 +++++++
 packages/bazel/unix_cc_configure-0.5.3.patch  | 24 ++++++++
 packages/bazel/unix_cc_configure-3.0.patch    | 19 ++++++
 .../bazel/unix_cc_configure_fj-0.29.1.patch   | 20 ++++++
 packages/bazel/unix_cc_configure_fj-5.0.patch | 23 +++++++
 packages/bazel/unix_cc_configure_fj-5.2.patch | 23 +++++++
 30 files changed, 543 insertions(+)
 create mode 100644 packages/bazel/apple-clang-14.0.3.patch
 create mode 100644 packages/bazel/bazelconfiguration-0.3.patch
 create mode 100644 packages/bazel/bazelruleclassprovider-0.14.patch
 create mode 100644 packages/bazel/bazelruleclassprovider-0.25.patch
 create mode 100644 packages/bazel/bazelruleclassprovider_fj-0.25.patch
 create mode 100644 packages/bazel/blaze_util_posix-0.29.1.patch
 create mode 100644 packages/bazel/build-0.29.1.patch
 create mode 100644 packages/bazel/cc_configure-0.3.0.patch
 create mode 100644 packages/bazel/cc_configure-0.5.0.patch
 create mode 100644 packages/bazel/compile-0.13.patch
 create mode 100644 packages/bazel/compile-0.16.patch
 create mode 100644 packages/bazel/compile-0.21.patch
 create mode 100644 packages/bazel/compile-0.29.patch
 create mode 100644 packages/bazel/compile-0.3.patch
 create mode 100644 packages/bazel/compile-0.4.patch
 create mode 100644 packages/bazel/compile-0.6.patch
 create mode 100644 packages/bazel/compile-0.9.patch
 create mode 100644 packages/bazel/cppcompileaction-0.3.0.patch
 create mode 100644 packages/bazel/cppcompileaction-0.3.2.patch
 create mode 100644 packages/bazel/gcc11_1.patch
 create mode 100644 packages/bazel/gcc11_2.patch
 create mode 100644 packages/bazel/gcc11_3.patch
 create mode 100644 packages/bazel/gcc11_4.patch
 create mode 100644 packages/bazel/unix_cc_configure-0.10.patch
 create mode 100644 packages/bazel/unix_cc_configure-0.15.patch
 create mode 100644 packages/bazel/unix_cc_configure-0.5.3.patch
 create mode 100644 packages/bazel/unix_cc_configure-3.0.patch
 create mode 100644 packages/bazel/unix_cc_configure_fj-0.29.1.patch
 create mode 100644 packages/bazel/unix_cc_configure_fj-5.0.patch
 create mode 100644 packages/bazel/unix_cc_configure_fj-5.2.patch

diff --git a/packages/bazel/apple-clang-14.0.3.patch b/packages/bazel/apple-clang-14.0.3.patch
new file mode 100644
index 00000000..c826951b
--- /dev/null
+++ b/packages/bazel/apple-clang-14.0.3.patch
@@ -0,0 +1,13 @@
+--- a/third_party/zlib/gzguts.h	1980-01-01 00:00:00
++++ b/third_party/zlib/gzguts.h	2023-04-03 12:23:10
+@@ -3,6 +3,10 @@
+  * For conditions of distribution and use, see copyright notice in zlib.h
+  */
+ 
++#ifndef _WIN32
++  #include <unistd.h>
++#endif
++
+ #ifdef _LARGEFILE64_SOURCE
+ #  ifndef _LARGEFILE_SOURCE
+ #    define _LARGEFILE_SOURCE 1
diff --git a/packages/bazel/bazelconfiguration-0.3.patch b/packages/bazel/bazelconfiguration-0.3.patch
new file mode 100644
index 00000000..e6a974a9
--- /dev/null
+++ b/packages/bazel/bazelconfiguration-0.3.patch
@@ -0,0 +1,16 @@
+--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfiguration.java
++++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfiguration.java
+@@ -150,6 +150,13 @@
+       builder.put("PATH", null);
+       builder.put("LD_LIBRARY_PATH", null);
+     }
++
++    Map<String, String> spackEnv = System.getenv();
++    for (String envName : spackEnv.keySet()) {
++      if (envName.startsWith("SPACK_")) {
++        builder.put(envName, spackEnv.get(envName));
++      }
++    }
+   }
+ 
+   private static PathFragment determineShellExecutable(OS os, PathFragment fromOption) {
diff --git a/packages/bazel/bazelruleclassprovider-0.14.patch b/packages/bazel/bazelruleclassprovider-0.14.patch
new file mode 100644
index 00000000..b0aebdf3
--- /dev/null
+++ b/packages/bazel/bazelruleclassprovider-0.14.patch
@@ -0,0 +1,16 @@
+--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
++++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
+@@ -168,6 +168,13 @@ public class BazelRuleClassProvider {
+       env.put("PATH", null);
+     }
+ 
++    Map<String, String> spackEnv = System.getenv();
++    for (String envName : spackEnv.keySet()) {
++      if (envName.startsWith("SPACK_")) {
++        env.put(envName, spackEnv.get(envName));
++      }
++    }
++
+     // Shell environment variables specified via options take precedence over the
+     // ones inherited from the fragments. In the long run, these fragments will
+     // be replaced by appropriate default rc files anyway.
diff --git a/packages/bazel/bazelruleclassprovider-0.25.patch b/packages/bazel/bazelruleclassprovider-0.25.patch
new file mode 100644
index 00000000..0d68cd98
--- /dev/null
+++ b/packages/bazel/bazelruleclassprovider-0.25.patch
@@ -0,0 +1,16 @@
+--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
++++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
+@@ -181,6 +181,13 @@ public class BazelRuleClassProvider {
+           env.put("PATH", null);
+         }
+ 
++        Map<String, String> spackEnv = System.getenv();
++        for (String envName : spackEnv.keySet()) {
++          if (envName.startsWith("SPACK_")) {
++            env.put(envName, spackEnv.get(envName));
++          }
++        }
++
+         // Shell environment variables specified via options take precedence over the
+         // ones inherited from the fragments. In the long run, these fragments will
+         // be replaced by appropriate default rc files anyway.
diff --git a/packages/bazel/bazelruleclassprovider_fj-0.25.patch b/packages/bazel/bazelruleclassprovider_fj-0.25.patch
new file mode 100644
index 00000000..709e5ee0
--- /dev/null
+++ b/packages/bazel/bazelruleclassprovider_fj-0.25.patch
@@ -0,0 +1,11 @@
+--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
++++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
+@@ -185,7 +185,7 @@ public class BazelRuleClassProvider {
+ 
+         Map<String, String> spackEnv = System.getenv();
+         for (String envName : spackEnv.keySet()) {
+-          if (envName.startsWith("SPACK_")) {
++          if ((envName.startsWith("SPACK_")) || (envName.equals("fcc_ENV")) || (envName.equals("FCC_ENV"))) {
+             env.put(envName, spackEnv.get(envName));
+           }
+         }
diff --git a/packages/bazel/blaze_util_posix-0.29.1.patch b/packages/bazel/blaze_util_posix-0.29.1.patch
new file mode 100644
index 00000000..aa773a33
--- /dev/null
+++ b/packages/bazel/blaze_util_posix-0.29.1.patch
@@ -0,0 +1,12 @@
+diff -Naur a/src/main/cpp/blaze_util_posix.cc b/src/main/cpp/blaze_util_posix.cc
+--- a/src/main/cpp/blaze_util_posix.cc	1980-01-01 00:00:00.000000000 -0800
++++ b/src/main/cpp/blaze_util_posix.cc	2022-06-30 23:34:08.000000000 -0700
+@@ -600,7 +600,7 @@
+   // Prefer OFD locks if available.  POSIX locks can be lost "accidentally"
+   // due to any close() on the lock file, and are not reliably preserved
+   // across execve() on Linux, which we need for --batch mode.
+-  if (fcntl(fd, F_OFD_SETLK, lock) == 0) return 0;
++  if (fcntl(fd, F_SETLK, lock) == 0) return 0;
+   if (errno != EINVAL) {
+     if (errno != EACCES && errno != EAGAIN) {
+       BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
diff --git a/packages/bazel/build-0.29.1.patch b/packages/bazel/build-0.29.1.patch
new file mode 100644
index 00000000..c3ed9ab2
--- /dev/null
+++ b/packages/bazel/build-0.29.1.patch
@@ -0,0 +1,61 @@
+From 9c9d27561780bc56d9f0867e325c7421a94ee1cb Mon Sep 17 00:00:00 2001
+From: Harsh Bhatia <bhatia4@llnl.gov>
+Date: Tue, 15 Dec 2020 15:56:10 -0800
+Subject: [PATCH] https://github.com/bazelbuild/bazel/commit/ab62a6e097590dac5ec946ad7a796ea0e8593ae0 
+
+---
+ src/conditions/BUILD | 6 ++++++
+ third_party/BUILD    | 8 ++++++--
+ 2 files changed, 12 insertions(+), 2 deletions(-)
+
+diff --git a/src/conditions/BUILD b/src/conditions/BUILD
+index 2b28e28057..faa41a439d 100644
+--- a/src/conditions/BUILD
++++ b/src/conditions/BUILD
+@@ -10,6 +10,12 @@ filegroup(
+     visibility = ["//src:__pkg__"],
+ )
+ 
++config_setting(
++    name = "linux_ppc",
++    values = {"cpu": "ppc"},
++    visibility = ["//visibility:public"],
++)
++
+ config_setting(
+     name = "linux_x86_64",
+     values = {"cpu": "k8"},
+diff --git a/third_party/BUILD b/third_party/BUILD
+index 159006d741..4fcae54c00 100644
+--- a/third_party/BUILD
++++ b/third_party/BUILD
+@@ -523,12 +523,13 @@ UNNECESSARY_DYNAMIC_LIBRARIES = select({
+     "//src/conditions:darwin": "*.so *.dll",
+     "//src/conditions:darwin_x86_64": "*.so *.dll",
+     "//src/conditions:linux_x86_64": "*.jnilib *.dll",
++    "//src/conditions:linux_ppc": "*.so *.jnilib *.dll",
+     # The .so file is an x86 one, so we can just remove it if the CPU is not x86
+     "//src/conditions:arm": "*.so *.jnilib *.dll",
+     "//src/conditions:linux_aarch64": "*.so *.jnilib *.dll",
+     # Play it safe -- better have a big binary than a slow binary
+     # zip -d does require an argument. Supply something bogus.
+-    "//conditions:default": "*.bogusextension",
++    "//conditions:default": "",
+ })
+ 
+ # Remove native libraries that are for a platform different from the one we are
+@@ -537,7 +538,10 @@ genrule(
+     name = "filter_netty_dynamic_libs",
+     srcs = ["netty_tcnative/netty-tcnative-boringssl-static-2.0.24.Final.jar"],
+     outs = ["netty_tcnative/netty-tcnative-filtered.jar"],
+-    cmd = "cp $< $@ && zip -qd $@ " + UNNECESSARY_DYNAMIC_LIBRARIES,
++    cmd = "cp $< $@ && " +
++      # End successfully if there is nothing to be deleted from the archive
++      "if [ -n '" + UNNECESSARY_DYNAMIC_LIBRARIES + "' ]; then " +
++      "zip -qd $@ " + UNNECESSARY_DYNAMIC_LIBRARIES + "; fi",
+ )
+ 
+ java_import(
+-- 
+2.21.0 (Apple Git-122.2)
+
diff --git a/packages/bazel/cc_configure-0.3.0.patch b/packages/bazel/cc_configure-0.3.0.patch
new file mode 100644
index 00000000..79e12269
--- /dev/null
+++ b/packages/bazel/cc_configure-0.3.0.patch
@@ -0,0 +1,24 @@
+--- a/tools/cpp/cc_configure.bzl
++++ b/tools/cpp/cc_configure.bzl
+@@ -173,8 +173,19 @@
+   else:
+     inc_dirs = result.stderr[index1 + 1:index2].strip()
+ 
+-  return [repository_ctx.path(_cxx_inc_convert(p))
+-          for p in inc_dirs.split("\n")]
++  default_inc_directories = [
++    repository_ctx.path(_cxx_inc_convert(p))
++    for p in inc_dirs.split("\n")
++  ]
++
++  env = repository_ctx.os.environ
++  if "SPACK_INCLUDE_DIRS" in env:
++    for path in env["SPACK_INCLUDE_DIRS"].split(":"):
++      default_inc_directories.append(
++        repository_ctx.path(_cxx_inc_convert(path))
++      )
++
++  return default_inc_directories
+ 
+ def _add_option_if_supported(repository_ctx, cc, option):
+   """Checks that `option` is supported by the C compiler."""
diff --git a/packages/bazel/cc_configure-0.5.0.patch b/packages/bazel/cc_configure-0.5.0.patch
new file mode 100644
index 00000000..470986be
--- /dev/null
+++ b/packages/bazel/cc_configure-0.5.0.patch
@@ -0,0 +1,24 @@
+--- a/tools/cpp/cc_configure.bzl
++++ b/tools/cpp/cc_configure.bzl
+@@ -200,8 +200,19 @@
+   else:
+     inc_dirs = result.stderr[index1 + 1:index2].strip()
+ 
+-  return [_escape_string(repository_ctx.path(_cxx_inc_convert(p)))
+-          for p in inc_dirs.split("\n")]
++  default_inc_directories = [
++    _escape_string(repository_ctx.path(_cxx_inc_convert(p)))
++    for p in inc_dirs.split("\n")
++  ]
++
++  env = repository_ctx.os.environ
++  if "SPACK_INCLUDE_DIRS" in env:
++    for path in env["SPACK_INCLUDE_DIRS"].split(":"):
++      default_inc_directories.append(
++        repository_ctx.path(_cxx_inc_convert(path))
++      )
++
++  return default_inc_directories
+ 
+ 
+ def _add_option_if_supported(repository_ctx, cc, option):
diff --git a/packages/bazel/compile-0.13.patch b/packages/bazel/compile-0.13.patch
new file mode 100644
index 00000000..13c82e76
--- /dev/null
+++ b/packages/bazel/compile-0.13.patch
@@ -0,0 +1,11 @@
+--- a/compile.sh
++++ b/compile.sh
+@@ -92,7 +92,7 @@
+ log "Building output/bazel"
+ # We set host and target platform directly since the defaults in @bazel_tools
+ # have not yet been generated.
+-bazel_build "src:bazel${EXE_EXT}" \
++CC=$SPACK_CC CXX=$SPACK_CXX bazel_build "src:bazel${EXE_EXT}" \
+   --host_platform=@bazel_tools//platforms:host_platform \
+   --platforms=@bazel_tools//platforms:target_platform \
+   || fail "Could not build Bazel"
diff --git a/packages/bazel/compile-0.16.patch b/packages/bazel/compile-0.16.patch
new file mode 100644
index 00000000..f61f521a
--- /dev/null
+++ b/packages/bazel/compile-0.16.patch
@@ -0,0 +1,11 @@
+--- a/compile.sh
++++ b/compile.sh
+@@ -92,7 +92,7 @@ display "."
+ log "Building output/bazel"
+ # We set host and target platform directly since the defaults in @bazel_tools
+ # have not yet been generated.
+-bazel_build "src:bazel_nojdk${EXE_EXT}" \
++CC=$SPACK_CC CXX=$SPACK_CXX bazel_build "src:bazel_nojdk${EXE_EXT}" \
+   --host_platform=@bazel_tools//platforms:host_platform \
+   --platforms=@bazel_tools//platforms:target_platform \
+   || fail "Could not build Bazel"
diff --git a/packages/bazel/compile-0.21.patch b/packages/bazel/compile-0.21.patch
new file mode 100644
index 00000000..d666a0f0
--- /dev/null
+++ b/packages/bazel/compile-0.21.patch
@@ -0,0 +1,11 @@
+--- a/compile.sh
++++ b/compile.sh
+@@ -92,7 +92,7 @@ display "."
+ log "Building output/bazel"
+ # We set host and target platform directly since the defaults in @bazel_tools
+ # have not yet been generated.
+-bazel_build "src:bazel_nojdk${EXE_EXT}" \
++CC=$SPACK_CC CXX=$SPACK_CXX bazel_build "src:bazel_nojdk${EXE_EXT}" \
+   --action_env=PATH \
+   --host_platform=@bazel_tools//platforms:host_platform \
+   --platforms=@bazel_tools//platforms:target_platform \
diff --git a/packages/bazel/compile-0.29.patch b/packages/bazel/compile-0.29.patch
new file mode 100644
index 00000000..6cb2eb0b
--- /dev/null
+++ b/packages/bazel/compile-0.29.patch
@@ -0,0 +1,11 @@
+--- a/compile.sh
++++ b/compile.sh
+@@ -63,7 +63,7 @@
+ log "Building output/bazel"
+ # We set host and target platform directly because we are building for the local
+ # host.
+-bazel_build "src:bazel_nojdk${EXE_EXT}" \
++CC=$SPACK_CC CXX=$SPACK_CXX bazel_build "src:bazel_nojdk${EXE_EXT}" \
+   --action_env=PATH \
+   --host_platform=@local_config_platform//:host \
+   --platforms=@local_config_platform//:host \
diff --git a/packages/bazel/compile-0.3.patch b/packages/bazel/compile-0.3.patch
new file mode 100644
index 00000000..82db6efb
--- /dev/null
+++ b/packages/bazel/compile-0.3.patch
@@ -0,0 +1,11 @@
+--- a/compile.sh
++++ b/compile.sh
+@@ -99,7 +99,7 @@
+   new_step 'Building Bazel with Bazel'
+   display "."
+   log "Building output/bazel"
+-  bazel_build "src:bazel${EXE_EXT}"
++  CC=$SPACK_CC CXX=$SPACK_CXX bazel_build "src:bazel${EXE_EXT}"
+   cp -f "bazel-bin/src/bazel${EXE_EXT}" "output/bazel${EXE_EXT}"
+   chmod 0755 "output/bazel${EXE_EXT}"
+   BAZEL="$(pwd)/output/bazel${EXE_EXT}"
diff --git a/packages/bazel/compile-0.4.patch b/packages/bazel/compile-0.4.patch
new file mode 100644
index 00000000..80eab26a
--- /dev/null
+++ b/packages/bazel/compile-0.4.patch
@@ -0,0 +1,11 @@
+--- a/compile.sh
++++ b/compile.sh
+@@ -124,7 +124,7 @@
+   new_step 'Building Bazel with Bazel'
+   display "."
+   log "Building output/bazel"
+-  bazel_build "src:bazel${EXE_EXT}" \
++  CC=$SPACK_CC CXX=$SPACK_CXX bazel_build "src:bazel${EXE_EXT}" \
+     || fail "Could not build Bazel"
+   bazel_bin_path="$(get_bazel_bin_path)/src/bazel${EXE_EXT}"
+   [ -e "$bazel_bin_path" ] \
diff --git a/packages/bazel/compile-0.6.patch b/packages/bazel/compile-0.6.patch
new file mode 100644
index 00000000..64eb408e
--- /dev/null
+++ b/packages/bazel/compile-0.6.patch
@@ -0,0 +1,11 @@
+--- a/compile.sh
++++ b/compile.sh
+@@ -85,7 +85,7 @@
+ log "Building output/bazel"
+ # We set host and target platform directly since the defaults in @bazel_tools
+ # have not yet been generated.
+-bazel_build "src:bazel${EXE_EXT}" \
++CC=$SPACK_CC CXX=$SPACK_CXX bazel_build "src:bazel${EXE_EXT}" \
+   --experimental_host_platform=//tools/platforms:host_platform \
+   --experimental_platforms=//tools/platforms:target_platform \
+   || fail "Could not build Bazel"
diff --git a/packages/bazel/compile-0.9.patch b/packages/bazel/compile-0.9.patch
new file mode 100644
index 00000000..135de3a0
--- /dev/null
+++ b/packages/bazel/compile-0.9.patch
@@ -0,0 +1,11 @@
+--- a/compile.sh
++++ b/compile.sh
+@@ -92,7 +92,7 @@
+ log "Building output/bazel"
+ # We set host and target platform directly since the defaults in @bazel_tools
+ # have not yet been generated.
+-bazel_build "src:bazel${EXE_EXT}" \
++CC=$SPACK_CC CXX=$SPACK_CXX bazel_build "src:bazel${EXE_EXT}" \
+   --host_platform=//tools/platforms:host_platform \
+   --platforms=//tools/platforms:target_platform \
+   || fail "Could not build Bazel"
diff --git a/packages/bazel/cppcompileaction-0.3.0.patch b/packages/bazel/cppcompileaction-0.3.0.patch
new file mode 100644
index 00000000..dd23972d
--- /dev/null
+++ b/packages/bazel/cppcompileaction-0.3.0.patch
@@ -0,0 +1,11 @@
+--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java.orig    2020-06-08 13:42:14.035342560 -0400
++++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java 2020-06-08 13:42:25.149375458 -0400
+@@ -963,7 +963,7 @@
+           // are, it's probably due to a non-hermetic #include, & we should stop
+           // the build with an error.
+           if (execPath.startsWith(execRoot)) {
+-            execPathFragment = execPath.relativeTo(execRoot); // funky but tolerable path
++             //  execPathFragment = execPath.relativeTo(execRoot); // funky but tolerable path
+           } else {
+             problems.add(execPathFragment.getPathString());
+             continue;
diff --git a/packages/bazel/cppcompileaction-0.3.2.patch b/packages/bazel/cppcompileaction-0.3.2.patch
new file mode 100644
index 00000000..c15d3bf6
--- /dev/null
+++ b/packages/bazel/cppcompileaction-0.3.2.patch
@@ -0,0 +1,11 @@
+--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/HeaderDiscovery.java.orig  2020-03-25 08:54:37.914186251 -0400
++++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/HeaderDiscovery.java       2020-03-25 08:55:01.356250657 -0400
+@@ -148,7 +148,7 @@
+         if (execPath.startsWith(execRoot)) {
+           execPathFragment = execPath.relativeTo(execRoot); // funky but tolerable path
+         } else {
+-          problems.add(execPathFragment.getPathString());
++          //          problems.add(execPathFragment.getPathString());
+           continue;
+         }
+       }
diff --git a/packages/bazel/gcc11_1.patch b/packages/bazel/gcc11_1.patch
new file mode 100644
index 00000000..5868f202
--- /dev/null
+++ b/packages/bazel/gcc11_1.patch
@@ -0,0 +1,12 @@
+diff --git a/third_party/ijar/zlib_client.h b/third_party/ijar/zlib_client.h
+index ed6616362fcc..c4b051e0100c 100644
+--- a/third_party/ijar/zlib_client.h
++++ b/third_party/ijar/zlib_client.h
+@@ -16,6 +16,7 @@
+ #define THIRD_PARTY_IJAR_ZLIB_CLIENT_H_
+ 
+ #include <limits.h>
++#include <limits>
+ 
+ #include "third_party/ijar/common.h"
+ 
diff --git a/packages/bazel/gcc11_2.patch b/packages/bazel/gcc11_2.patch
new file mode 100644
index 00000000..aac5b08b
--- /dev/null
+++ b/packages/bazel/gcc11_2.patch
@@ -0,0 +1,14 @@
+diff --git a/third_party/ijar/zlib_client.h b/third_party/ijar/zlib_client.h
+index c4b051e0100c..0a917ff0a99a 100644
+--- a/third_party/ijar/zlib_client.h
++++ b/third_party/ijar/zlib_client.h
+@@ -16,7 +16,9 @@
+ #define THIRD_PARTY_IJAR_ZLIB_CLIENT_H_
+ 
+ #include <limits.h>
++
+ #include <limits>
++#include <stdexcept>
+ 
+ #include "third_party/ijar/common.h"
+ 
diff --git a/packages/bazel/gcc11_3.patch b/packages/bazel/gcc11_3.patch
new file mode 100644
index 00000000..78d24e76
--- /dev/null
+++ b/packages/bazel/gcc11_3.patch
@@ -0,0 +1,17 @@
+diff --git a/third_party/ijar/mapped_file_unix.cc b/third_party/ijar/mapped_file_unix.cc
+index 6e3a90871844..65179e3290ec 100644
+--- a/third_party/ijar/mapped_file_unix.cc
++++ b/third_party/ijar/mapped_file_unix.cc
+@@ -15,10 +15,11 @@
+ #include <errno.h>
+ #include <fcntl.h>
+ #include <stdio.h>
+-#include <unistd.h>
+ #include <sys/mman.h>
++#include <unistd.h>
+ 
+ #include <algorithm>
++#include <limits>
+ 
+ #include "third_party/ijar/mapped_file.h"
+ 
diff --git a/packages/bazel/gcc11_4.patch b/packages/bazel/gcc11_4.patch
new file mode 100644
index 00000000..972c9035
--- /dev/null
+++ b/packages/bazel/gcc11_4.patch
@@ -0,0 +1,44 @@
+--- a/third_party/grpc/grpc_1.33.1.patch
++++ b/third_party/grpc/grpc_1.33.1.patch
+@@ -58,6 +58,14 @@ index 09fcad95a2..9b737e5deb 100644
+      )
+  
+      native.bind(
++@@ -245,6 +245,7 @@ def grpc_deps():
++                 "https://storage.googleapis.com/grpc-bazel-mirror/github.com/abseil/abseil-cpp/archive/df3ea785d8c30a9503321a3d35ee7d35808f190d.tar.gz",
++                 "https://github.com/abseil/abseil-cpp/archive/df3ea785d8c30a9503321a3d35ee7d35808f190d.tar.gz",
++             ],
+++            patches = ["@com_github_grpc_grpc//:third_party/abseil-cpp/absl.patch"],
++         )
++
++     if "bazel_toolchains" not in native.existing_rules():
+ diff --git a/bazel/grpc_extra_deps.bzl b/bazel/grpc_extra_deps.bzl
+ index 4c1dfad2e8..f63c54ddef 100644
+ --- a/bazel/grpc_extra_deps.bzl
+@@ -120,3 +128,25 @@ index c047f0c515..7c24fbc617 100644
+          ":windows": "@com_github_grpc_grpc//third_party/cares:config_windows/ares_config.h",
+          ":android": "@com_github_grpc_grpc//third_party/cares:config_android/ares_config.h",
+          "//conditions:default": "@com_github_grpc_grpc//third_party/cares:config_linux/ares_config.h",
++
++--- /dev/null
+++++ b/third_party/abseil-cpp/absl.patch
++@@ -0,0 +1,18 @@
+++0e2c62da1dcaf6529abab952bdcc96c6de2d9506 by Abseil Team <absl-team@google.com>:
+++
+++Add missing <limits> include
+++
+++PiperOrigin-RevId: 339054753
+++
+++--
+++
+++--- absl/synchronization/internal/graphcycles.cc
++++++ absl/synchronization/internal/graphcycles.cc
+++@@ -37,6 +37,7 @@
+++ 
+++ #include <algorithm>
+++ #include <array>
++++#include <limits>
+++ #include "absl/base/internal/hide_ptr.h"
+++ #include "absl/base/internal/raw_logging.h"
+++ #include "absl/base/internal/spinlock.h"
+
diff --git a/packages/bazel/unix_cc_configure-0.10.patch b/packages/bazel/unix_cc_configure-0.10.patch
new file mode 100644
index 00000000..bdd24e11
--- /dev/null
+++ b/packages/bazel/unix_cc_configure-0.10.patch
@@ -0,0 +1,22 @@
+--- a/tools/cpp/unix_cc_configure.bzl
++++ b/tools/cpp/unix_cc_configure.bzl
+@@ -147,9 +147,18 @@ def get_escaped_cxx_inc_directories(repository_ctx, cc, additional_flags = []):
+   else:
+     inc_dirs = result.stderr[index1 + 1:index2].strip()
+ 
+-  return [_prepare_include_path(repository_ctx, _cxx_inc_convert(p))
+-          for p in inc_dirs.split("\n")]
++  default_inc_directories = [
++    _prepare_include_path(repository_ctx, _cxx_inc_convert(p))
++      for p in inc_dirs.split("\n")
++  ]
++ 
++  env = repository_ctx.os.environ
++  if "SPACK_INCLUDE_DIRS" in env:
++    for path in env["SPACK_INCLUDE_DIRS"].split(":"):
++      default_inc_directories.append(path)
++
++  return default_inc_directories
+ 
+
+ def _is_option_supported(repository_ctx, cc, option):
diff --git a/packages/bazel/unix_cc_configure-0.15.patch b/packages/bazel/unix_cc_configure-0.15.patch
new file mode 100644
index 00000000..74fd8bfb
--- /dev/null
+++ b/packages/bazel/unix_cc_configure-0.15.patch
@@ -0,0 +1,22 @@
+--- a/tools/cpp/unix_cc_configure.bzl
++++ b/tools/cpp/unix_cc_configure.bzl
+@@ -145,11 +145,18 @@ def get_escaped_cxx_inc_directories(repository_ctx, cc, lang_flag, additional_fl
+     else:
+         inc_dirs = result.stderr[index1 + 1:index2].strip()
+ 
+-    return [
++    default_inc_directories = [
+         _prepare_include_path(repository_ctx, _cxx_inc_convert(p))
+         for p in inc_dirs.split("\n")
+     ]
+ 
++    env = repository_ctx.os.environ
++    if "SPACK_INCLUDE_DIRS" in env:
++        for path in env["SPACK_INCLUDE_DIRS"].split(":"):
++            default_inc_directories.append(path)
++
++    return default_inc_directories
++
+ def _is_compiler_option_supported(repository_ctx, cc, option):
+     """Checks that `option` is supported by the C compiler. Doesn't %-escape the option."""
+     result = repository_ctx.execute([
diff --git a/packages/bazel/unix_cc_configure-0.5.3.patch b/packages/bazel/unix_cc_configure-0.5.3.patch
new file mode 100644
index 00000000..79b583ba
--- /dev/null
+++ b/packages/bazel/unix_cc_configure-0.5.3.patch
@@ -0,0 +1,24 @@
+--- a/tools/cpp/unix_cc_configure.bzl
++++ b/tools/cpp/unix_cc_configure.bzl
+@@ -117,9 +117,19 @@ def get_escaped_cxx_inc_directories(repository_ctx, cc):
+   else:
+     inc_dirs = result.stderr[index1 + 1:index2].strip()
+ 
+-  return [escape_string(repository_ctx.path(_cxx_inc_convert(p)))
+-          for p in inc_dirs.split("\n")]
++  default_inc_directories = [
++    escape_string(repository_ctx.path(_cxx_inc_convert(p)))
++          for p in inc_dirs.split("\n")
++  ]
+ 
++  env = repository_ctx.os.environ
++  if "SPACK_INCLUDE_DIRS" in env:
++    for path in env["SPACK_INCLUDE_DIRS"].split(":"):
++      default_inc_directories.append(
++        repository_ctx.path(_cxx_inc_convert(path))
++      )
++
++  return default_inc_directories
+ 
+ def _add_option_if_supported(repository_ctx, cc, option):
+   """Checks that `option` is supported by the C compiler. Doesn't %-escape the option."""
diff --git a/packages/bazel/unix_cc_configure-3.0.patch b/packages/bazel/unix_cc_configure-3.0.patch
new file mode 100644
index 00000000..1140b0c3
--- /dev/null
+++ b/packages/bazel/unix_cc_configure-3.0.patch
@@ -0,0 +1,19 @@
+diff --git a/tools/cpp/unix_cc_configure.bzl b/tools/cpp/unix_cc_configure.bzl
+index 5feb10b76a..cde0b8f8f1 100644
+--- a/tools/cpp/unix_cc_configure.bzl
++++ b/tools/cpp/unix_cc_configure.bzl
+@@ -151,8 +151,14 @@ def get_escaped_cxx_inc_directories(repository_ctx, cc, lang_flag, additional_fl
+         ).stdout.strip() + "/share"
+         inc_directories.append(_prepare_include_path(repository_ctx, resource_dir))
+ 
++    env = repository_ctx.os.environ
++    if "SPACK_INCLUDE_DIRS" in env:
++        for path in env["SPACK_INCLUDE_DIRS"].split(":"):
++            inc_directories.append(path)
++
+     return inc_directories
+ 
++
+ def _is_compiler_option_supported(repository_ctx, cc, option):
+     """Checks that `option` is supported by the C compiler. Doesn't %-escape the option."""
+     result = repository_ctx.execute([
diff --git a/packages/bazel/unix_cc_configure_fj-0.29.1.patch b/packages/bazel/unix_cc_configure_fj-0.29.1.patch
new file mode 100644
index 00000000..376aeee2
--- /dev/null
+++ b/packages/bazel/unix_cc_configure_fj-0.29.1.patch
@@ -0,0 +1,20 @@
+diff -Naur a/tools/cpp/unix_cc_configure.bzl b/tools/cpp/unix_cc_configure.bzl
+--- a/tools/cpp/unix_cc_configure.bzl	1980-01-01 00:00:00.000000000 -0800
++++ b/tools/cpp/unix_cc_configure.bzl	2022-06-30 23:53:17.000000000 -0700
+@@ -379,7 +379,7 @@
+         "",
+         False,
+     ), ":")
+-    gold_linker_path = _find_gold_linker_path(repository_ctx, cc)
++    gold_linker_path = None
+     cc_path = repository_ctx.path(cc)
+     if not str(cc_path).startswith(str(repository_ctx.path(".")) + "/"):
+         # cc is outside the repository, set -B
+@@ -468,7 +468,6 @@
+                     # Security hardening requires optimization.
+                     # We need to undef it as some distributions now have it enabled by default.
+                     "-U_FORTIFY_SOURCE",
+-                    "-fstack-protector",
+                     # All warnings are enabled. Maybe enable -Werror as well?
+                     "-Wall",
+                     # Enable a few more warnings that aren't part of -Wall.
diff --git a/packages/bazel/unix_cc_configure_fj-5.0.patch b/packages/bazel/unix_cc_configure_fj-5.0.patch
new file mode 100644
index 00000000..5f1304b7
--- /dev/null
+++ b/packages/bazel/unix_cc_configure_fj-5.0.patch
@@ -0,0 +1,23 @@
+diff -Naur a/tools/cpp/unix_cc_configure.bzl b/tools/cpp/unix_cc_configure.bzl
+--- a/tools/cpp/unix_cc_configure.bzl	1980-01-01 00:00:00.000000000 -0800
++++ b/tools/cpp/unix_cc_configure.bzl	2022-06-30 23:35:14.000000000 -0700
+@@ -417,10 +417,7 @@
+         bazel_linklibs,
+         False,
+     ), ":")
+-    gold_or_lld_linker_path = (
+-        _find_linker_path(repository_ctx, cc, "lld", is_clang) or
+-        _find_linker_path(repository_ctx, cc, "gold", is_clang)
+-    )
++    gold_or_lld_linker_path = None
+     cc_path = repository_ctx.path(cc)
+     if not str(cc_path).startswith(str(repository_ctx.path(".")) + "/"):
+         # cc is outside the repository, set -B
+@@ -531,7 +528,6 @@
+                     # Security hardening requires optimization.
+                     # We need to undef it as some distributions now have it enabled by default.
+                     "-U_FORTIFY_SOURCE",
+-                    "-fstack-protector",
+                     # All warnings are enabled. Maybe enable -Werror as well?
+                     "-Wall",
+                     # Enable a few more warnings that aren't part of -Wall.
diff --git a/packages/bazel/unix_cc_configure_fj-5.2.patch b/packages/bazel/unix_cc_configure_fj-5.2.patch
new file mode 100644
index 00000000..f7ad3e30
--- /dev/null
+++ b/packages/bazel/unix_cc_configure_fj-5.2.patch
@@ -0,0 +1,23 @@
+diff -Naur a/tools/cpp/unix_cc_configure.bzl b/tools/cpp/unix_cc_configure.bzl
+--- a/tools/cpp/unix_cc_configure.bzl	1980-01-01 00:00:00.000000000 -0800
++++ b/tools/cpp/unix_cc_configure.bzl	2022-06-30 23:58:26.945067883 -0700
+@@ -419,10 +419,7 @@
+         bazel_linklibs,
+         False,
+     ), ":")
+-    gold_or_lld_linker_path = (
+-        _find_linker_path(repository_ctx, cc, "lld", is_clang) or
+-        _find_linker_path(repository_ctx, cc, "gold", is_clang)
+-    )
++    gold_or_lld_linker_path = None
+     cc_path = repository_ctx.path(cc)
+     if not str(cc_path).startswith(str(repository_ctx.path(".")) + "/"):
+         # cc is outside the repository, set -B
+@@ -530,7 +527,6 @@
+             "%{cxx_builtin_include_directories}": get_starlark_list(builtin_include_directories),
+             "%{compile_flags}": get_starlark_list(
+                 [
+-                    "-fstack-protector",
+                     # All warnings are enabled. Maybe enable -Werror as well?
+                     "-Wall",
+                     # Enable a few more warnings that aren't part of -Wall.
-- 
GitLab