From 26ecfcf1d8a514de805906d4710cfdfb57098c33 Mon Sep 17 00:00:00 2001 From: Malte Poll Date: Thu, 28 Sep 2023 14:29:12 +0200 Subject: [PATCH] Set rulesGoStdlibPrefix as ldflag of go_tool_binary Adapt toolchain with changes from https://github.com/bazelbuild/rules_go/pull/3701 --- toolchains/go/go.bzl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/toolchains/go/go.bzl b/toolchains/go/go.bzl index cb0f26ad8..cb3669f35 100644 --- a/toolchains/go/go.bzl +++ b/toolchains/go/go.bzl @@ -211,7 +211,7 @@ nixpkgs_go_toolchain = repository_rule( go_sdk_build = """ load("@{rules_go}//go/private/rules:binary.bzl", "go_tool_binary") load("@{rules_go}//go/private/rules:sdk.bzl", "package_list") -load("@{rules_go}//go:def.bzl", "go_sdk") +load("@{rules_go}//go:def.bzl", "go_sdk", "RULES_GO_VERSION") load("@{helpers}//:go_sdk.bzl", "go_sdk_for_arch") load(":go_version.bzl", "go_version") @@ -219,6 +219,11 @@ package(default_visibility = ["//visibility:public"]) go_sdk_for_arch(go_version) +# rules_go >= 0.42.0 requires a stdlib prefix +TOOL_BINARY_NEEDS_STDLIB_PREFIX = (int(RULES_GO_VERSION.split(".")[0]) > 0) or (int(RULES_GO_VERSION.split(".")[1]) >= 42) +None if TOOL_BINARY_NEEDS_STDLIB_PREFIX else \ + print("WARNING: rules_go %s is deprecated and support will soon be removed. Upgrade to rules_go >= 0.42.0. See https://github.com/tweag/rules_nixpkgs/issues/421 for more information." % (RULES_GO_VERSION)) + filegroup( name = "headers", srcs = glob(["pkg/include/*.h"]), @@ -237,6 +242,7 @@ filegroup( go_tool_binary( name = "builder", srcs = ["@{rules_go}//go/tools/builders:builder_srcs"], + ldflags = "-X main.rulesGoStdlibPrefix=@{rules_go}//stdlib:" if TOOL_BINARY_NEEDS_STDLIB_PREFIX else None, sdk = ":go_sdk", )