From 7b8b9527ef777ca6fad110a36cb5cd5c1c6ada89 Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Fri, 17 Feb 2023 09:49:04 -0800 Subject: [PATCH] Statically link benchmark test binaries. After update to Go 1.20 in 5572ab2f7d0d ("Bump go version to 1.20"), the benchmark jobs have been failing on BuildKite. This seems to be happening because benchmark test binaries are built in Docker containers but are run on the host. On some hosts, the glibc isn't compatible with glibc in our docker container. So dynamically linked binaries may fail. Linking them statically resolves this glibc compatibility issue. As a result, this change also adds support for static test binaries to tools/bazeldefs/go.bzl. PiperOrigin-RevId: 510455271 --- test/benchmarks/defs.bzl | 6 +++++- tools/bazeldefs/go.bzl | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/test/benchmarks/defs.bzl b/test/benchmarks/defs.bzl index 4ccd57dfe..735b0dafe 100644 --- a/test/benchmarks/defs.bzl +++ b/test/benchmarks/defs.bzl @@ -5,11 +5,15 @@ load("//tools:defs.bzl", "go_test") def benchmark_test(name, tags = [], **kwargs): go_test( name, - tags = [ + tags = tags + [ # Requires docker and runsc to be configured before the test runs. "local", "manual", "gvisor_benchmark", ], + # Benchmark test binaries are built inside a bazel docker container in + # OSS but are executed directly on the host. Use static binaries to + # avoid hitting glibc incompatibility. + static = True, **kwargs ) diff --git a/tools/bazeldefs/go.bzl b/tools/bazeldefs/go.bzl index f4fece797..3efa890d8 100644 --- a/tools/bazeldefs/go.bzl +++ b/tools/bazeldefs/go.bzl @@ -43,7 +43,7 @@ def go_proto_library(name, **kwargs): def go_grpc_and_proto_libraries(name, **kwargs): _go_proto_or_grpc_library(_go_grpc_library, name, **kwargs) -def go_binary(name, static = False, pure = False, x_defs = None, system_malloc = False, **kwargs): +def go_binary(name, static = False, pure = False, x_defs = None, **kwargs): """Build a go binary. Args: @@ -79,17 +79,20 @@ def go_library(name, arch_deps = [], **kwargs): **kwargs ) -def go_test(name, pure = False, library = None, **kwargs): +def go_test(name, static = False, pure = False, library = None, **kwargs): """Build a go test. Args: name: name of the output binary. + static: build a static binary. pure: should it be built without cgo. library: the library to embed. **kwargs: rest of the arguments to pass to _go_test. """ if pure: kwargs["pure"] = "on" + if static: + kwargs["static"] = "on" if library: kwargs["embed"] = [library] _go_test(