From a7dcce93851cd51d0c3e1646756380d938cc7f02 Mon Sep 17 00:00:00 2001 From: Etienne Perot Date: Fri, 20 Sep 2024 21:37:44 -0700 Subject: [PATCH] `go_library` wrapper: Add `bazel_cgo` and cgo-related arguments. This adds cgo-only arguments passed to `go_library` rules when the `bazel_cgo` argument is specified and `True`. Credits go to @avagin for this change. Updates #9266 Updates #9551 PiperOrigin-RevId: 677085717 --- tools/bazeldefs/go.bzl | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/bazeldefs/go.bzl b/tools/bazeldefs/go.bzl index 57d6c8c486..687d65ac1c 100644 --- a/tools/bazeldefs/go.bzl +++ b/tools/bazeldefs/go.bzl @@ -74,7 +74,22 @@ def go_importpath(target): """Returns the importpath for the target.""" return target[GoLibrary].importpath -def go_library(name, arch_deps = [], **kwargs): +def go_library(name, bazel_cgo = False, cgo_cdeps = [], cgo_clinkopts = [], cgo_copts = [], **kwargs): + """Wrapper for `go_library` rule. + + Args: + name: name of the target. + bazel_cgo: if True, build with cgo. + cgo_cdeps: cgo deps to pass to `go_library`. + cgo_clinkopts: cgo linkopts to pass to `go_library`. + cgo_copts: cgo opts to pass to `go_library`. + **kwargs: rest of the arguments are passed to `go_library`. + """ + if bazel_cgo == True: + kwargs["cgo"] = bazel_cgo + kwargs["cdeps"] = cgo_cdeps + kwargs["clinkopts"] = cgo_clinkopts + kwargs["copts"] = cgo_copts _go_library( name = name, importpath = "gvisor.dev/gvisor/" + native.package_name(),