Disable cgo warnings for external repositories

Some cgo packages (like sqlite3) generate a ton of warnings which we
treat as errors. That prevents us from using some of these Go
libraries.

This patch suppresses warnings in third-party cgo code.

This came up during the development of
Ia9561e3fa35c213bbe645b461fcae36ecaf722fa. The sqlite3 cgo module
fails compilation without a patch like this.

Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: I2d1d031a06c8c638f715ff602200ec6db7140214
diff --git a/WORKSPACE b/WORKSPACE
index 03335b4..52af239 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -926,6 +926,12 @@
 
 http_archive(
     name = "io_bazel_rules_go",
+    patch_args = [
+        "-p1",
+    ],
+    patches = [
+        "@//third_party:rules_go/0001-Disable-warnings-for-external-repositories.patch",
+    ],
     sha256 = "2b1641428dff9018f9e85c0384f03ec6c10660d935b750e3fa1492a281a53b0f",
     urls = [
         "https://www.frc971.org/Build-Dependencies/rules_go-v0.29.0.zip",
diff --git a/third_party/rules_go/0001-Disable-warnings-for-external-repositories.patch b/third_party/rules_go/0001-Disable-warnings-for-external-repositories.patch
new file mode 100644
index 0000000..fe8ae87
--- /dev/null
+++ b/third_party/rules_go/0001-Disable-warnings-for-external-repositories.patch
@@ -0,0 +1,28 @@
+From 3113c6d807095eb6068ee4ffbc2f04649f999c35 Mon Sep 17 00:00:00 2001
+From: Philipp Schrader <philipp.schrader@gmail.com>
+Date: Thu, 20 Jan 2022 22:28:10 -0800
+Subject: [PATCH] Disable warnings for external repositories
+
+---
+ go/private/rules/cgo.bzl | 5 +++++
+ 1 file changed, 5 insertions(+)
+
+diff --git a/go/private/rules/cgo.bzl b/go/private/rules/cgo.bzl
+index f75e3c95..ee2a2ca9 100644
+--- a/go/private/rules/cgo.bzl
++++ b/go/private/rules/cgo.bzl
+@@ -53,6 +53,11 @@ def cgo_configure(go, srcs, cdeps, cppopts, copts, cxxopts, clinkopts):
+     if not go.cgo_tools:
+         fail("Go toolchain does not support cgo")
+ 
++    # If we're not in the main repository, ignore all warnings. It's not worth
++    # our time to fix the warnings for third-party cgo code.
++    if go._ctx.label.workspace_name:
++        copts = copts + ["-Wno-everything"]
++
+     cppopts = list(cppopts)
+     copts = go.cgo_tools.c_compile_options + copts
+     cxxopts = go.cgo_tools.cxx_compile_options + cxxopts
+-- 
+2.30.2
+