diff --git a/go/private/context.bzl b/go/private/context.bzl index 46ff54b8bb..e9ab9d56cc 100644 --- a/go/private/context.bzl +++ b/go/private/context.bzl @@ -69,7 +69,15 @@ GoContext = provider() _GoContextData = provider() _COMPILER_OPTIONS_BLACKLIST = { + # cgo parses the error messages from the compiler. It can't handle colors. + # Ignore both variants of the diagnostics color flag. "-fcolor-diagnostics": None, + "-fdiagnostics-color": None, + + # cgo also wants to see all the errors when it is testing the compiler. + # fmax-errors limits that and causes build failures. + "-fmax-errors=": None, + "-Wall": None, # Symbols are needed by Go, so keep them @@ -86,8 +94,18 @@ _LINKER_OPTIONS_BLACKLIST = { "-Wl,--gc-sections": None, } +def _match_option(option, pattern): + if pattern.endswith("="): + return option.startswith(pattern) + else: + return option == pattern + def _filter_options(options, blacklist): - return [option for option in options if option not in blacklist] + return [ + option + for option in options + if not any([_match_option(option, pattern) for pattern in blacklist]) + ] def _child_name(go, path, ext, name): childname = mode_string(go.mode) + "/" diff --git a/go/private/rules/cgo.bzl b/go/private/rules/cgo.bzl index c4370909a3..abe91c3fc5 100644 --- a/go/private/rules/cgo.bzl +++ b/go/private/rules/cgo.bzl @@ -795,7 +795,10 @@ def setup_cgo_library_for_mode(name, srcs, cdeps, copts, cxxopts, cppopts, clink name = cgo_o_name, srcs = [select_main_c], deps = cdeps + cgo_o_deps, - copts = copts + cppopts, + copts = copts + cppopts + [ + # The generated thunks often contain unused variables. + "-Wno-unused-variable", + ], linkopts = clinkopts, visibility = ["//visibility:private"], **common_attrs