aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhongpeng Lin <zplin@uber.com>2021-08-10 23:10:31 +0800
committerGitHub <noreply@github.com>2021-08-10 23:10:31 +0800
commit728a9e1874bc965b05c415d7f6b332a86ac35102 (patch)
tree83fee40129dc4968ee403cc19e32f7d5c7c900e8
parente94d5059183a0f76b66cbe3b8c56bcf02a22c99d (diff)
downloadbazelbuild-rules_go-728a9e1874bc965b05c415d7f6b332a86ac35102.tar.gz
Accepting multiple platform SDKs in go_wrap_sdk (#2935)
-rw-r--r--go/private/sdk.bzl20
-rw-r--r--go/toolchains.rst10
2 files changed, 26 insertions, 4 deletions
diff --git a/go/private/sdk.bzl b/go/private/sdk.bzl
index d5b2eac1..0232e7e1 100644
--- a/go/private/sdk.bzl
+++ b/go/private/sdk.bzl
@@ -147,7 +147,19 @@ def go_local_sdk(name, **kwargs):
_register_toolchains(name)
def _go_wrap_sdk_impl(ctx):
- goroot = str(ctx.path(ctx.attr.root_file).dirname)
+ if not ctx.attr.root_file and not ctx.attr.root_files:
+ fail("either root_file or root_files must be provided")
+ if ctx.attr.root_file and ctx.attr.root_files:
+ fail("root_file and root_files cannot be both provided")
+ if ctx.attr.root_file:
+ root_file = ctx.attr.root_file
+ else:
+ goos, goarch = _detect_host_platform(ctx)
+ platform = goos + "_" + goarch
+ if platform not in ctx.attr.root_files:
+ fail("unsupported platform {}".format(platform))
+ root_file = Label(ctx.attr.root_files[platform])
+ goroot = str(ctx.path(root_file).dirname)
platform = _detect_sdk_platform(ctx, goroot)
_sdk_build_file(ctx, platform)
_local_sdk(ctx, goroot)
@@ -156,9 +168,13 @@ _go_wrap_sdk = repository_rule(
implementation = _go_wrap_sdk_impl,
attrs = {
"root_file": attr.label(
- mandatory = True,
+ mandatory = False,
doc = "A file in the SDK root direcotry. Used to determine GOROOT.",
),
+ "root_files": attr.string_dict(
+ mandatory = False,
+ doc = "A set of mappings from the host platform to a file in the SDK's root directory",
+ ),
},
)
diff --git a/go/toolchains.rst b/go/toolchains.rst
index 393fff79..812230b0 100644
--- a/go/toolchains.rst
+++ b/go/toolchains.rst
@@ -355,11 +355,17 @@ rule.
| A unique name for this SDK. This should almost always be :value:`go_sdk` if you want the SDK |
| to be used by toolchains. |
+--------------------------------+-----------------------------+-----------------------------------+
-| :param:`root_file` | :type:`label` | |mandatory| |
+| :param:`root_file` | :type:`label` | :value:`None` |
+--------------------------------+-----------------------------+-----------------------------------+
| A Bazel label referencing a file in the root directory of the SDK. Used to |
-| determine the GOROOT for the SDK. |
+| determine the GOROOT for the SDK. This attribute and `root_files` cannot be both provided. |
+--------------------------------+-----------------------------+-----------------------------------+
+| :param:`root_files` | :type:`string_dict` | :value:`None` |
++--------------------------------+-----------------------------+-----------------------------------+
+| A set of mappings from the host platform to a Bazel label referencing a file in the SDK's root |
+| directory. This attribute and `root_file` cannot be both provided. |
++--------------------------------+-----------------------------+-----------------------------------+
+
**Example:**