Skip to content

Commit

Permalink
Accepting multiple platform SDKs in go_wrap_sdk (bazelbuild#2935)
Browse files Browse the repository at this point in the history
  • Loading branch information
linzhp committed Aug 10, 2021
1 parent e94d505 commit 728a9e1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
20 changes: 18 additions & 2 deletions go/private/sdk.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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",
),
},
)

Expand Down
10 changes: 8 additions & 2 deletions go/toolchains.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:**

Expand Down

0 comments on commit 728a9e1

Please sign in to comment.