Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set rulesGoStdlibPrefix as ldflag of go_tool_binary #422

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion toolchains/go/go.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,19 @@ 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")

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"]),
Expand All @@ -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",
)

Expand Down