aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Meumertzheim <fabian@meumertzhe.im>2023-04-07 19:00:05 +0200
committerGitHub <noreply@github.com>2023-04-07 17:00:05 +0000
commit3b491f1bff144249ceccd072daddf0e22a0192b4 (patch)
tree7727d8542ad9906736f1616291a287120ea34832
parent6e8e7ecdd95276e7efc5eafdd1f14df136de07cc (diff)
downloadbazelbuild-rules_go-3b491f1bff144249ceccd072daddf0e22a0192b4.tar.gz
Drop coverage linker flags from stdlib build (#3522)
We never compile CGo with coverage instrumentation and the stdlib contains no user-provided C/C++ code, so linking coverage runtimes is never needed.
-rw-r--r--go/private/actions/stdlib.bzl8
-rw-r--r--go/private/common.bzl9
-rw-r--r--go/private/context.bzl7
3 files changed, 21 insertions, 3 deletions
diff --git a/go/private/actions/stdlib.bzl b/go/private/actions/stdlib.bzl
index f20bfd5a..a8097e16 100644
--- a/go/private/actions/stdlib.bzl
+++ b/go/private/actions/stdlib.bzl
@@ -13,6 +13,10 @@
# limitations under the License.
load(
+ "//go/private:common.bzl",
+ "COVERAGE_OPTIONS_DENYLIST",
+)
+load(
"//go/private:providers.bzl",
"GoStdLib",
)
@@ -98,10 +102,12 @@ def _build_stdlib(go):
else:
# NOTE(#2545): avoid unnecessary dynamic link
# go std library doesn't use C++, so should not have -lstdc++
+ # Also drop coverage flags as nothing in the stdlib is compiled with
+ # coverage - we disable it for all CGo code anyway.
ldflags = [
option
for option in extldflags_from_cc_toolchain(go)
- if option not in ("-lstdc++", "-lc++")
+ if option not in ("-lstdc++", "-lc++") and option not in COVERAGE_OPTIONS_DENYLIST
]
env.update({
"CGO_ENABLED": "1",
diff --git a/go/private/common.bzl b/go/private/common.bzl
index e47ebd18..5d331b72 100644
--- a/go/private/common.bzl
+++ b/go/private/common.bzl
@@ -243,3 +243,12 @@ def count_group_matches(v, prefix, suffix):
count = count + 1
return count
+
+# C/C++ compiler and linker options related to coverage instrumentation.
+COVERAGE_OPTIONS_DENYLIST = {
+ "--coverage": None,
+ "-ftest-coverage": None,
+ "-fprofile-arcs": None,
+ "-fprofile-instr-generate": None,
+ "-fcoverage-mapping": None,
+}
diff --git a/go/private/context.bzl b/go/private/context.bzl
index 1451895a..65f73b57 100644
--- a/go/private/context.bzl
+++ b/go/private/context.bzl
@@ -51,6 +51,7 @@ load(
)
load(
":common.bzl",
+ "COVERAGE_OPTIONS_DENYLIST",
"as_iterable",
"goos_to_extension",
"goos_to_shared_extension",
@@ -86,7 +87,7 @@ _UNSUPPORTED_C_COMPILERS = {
"clang-cl": None,
}
-_COMPILER_OPTIONS_DENYLIST = {
+_COMPILER_OPTIONS_DENYLIST = dict({
# cgo parses the error messages from the compiler. It can't handle colors.
# Ignore both variants of the diagnostics color flag.
"-fcolor-diagnostics": None,
@@ -105,7 +106,9 @@ _COMPILER_OPTIONS_DENYLIST = {
"--coverage": None,
"-ftest-coverage": None,
"-fprofile-arcs": None,
-}
+ "-fprofile-instr-generate": None,
+ "-fcoverage-mapping": None,
+}, **COVERAGE_OPTIONS_DENYLIST)
_LINKER_OPTIONS_DENYLIST = {
"-Wl,--gc-sections": None,