Skip to content

Commit

Permalink
use dedicated exec group for link actions
Browse files Browse the repository at this point in the history
When remote execution is used, a user may want to use different
exec properties for different actions under the same target.

For example:

A go_test could include 3 different actions:
- GoCompilePkg
- GoLink
- GoTest

If users wish to use a special exec_properties for GoLink actions,
after this PR, they could do so with:

```python
go_test(
  ...
  exec_properties = {
    # Default
    "container-image": "docker://alpine",
    "EstimatedMemory": "500MB",

    # Only applied to GoLink exec_group
    "GoLink.container-image": "docker://ubuntu",
    "GoLink.EstimatedMemory": "2GB",
  }
  ...
)
```

Reference: https://bazel.build/extending/exec-groups
  • Loading branch information
sluongng committed Sep 26, 2023
1 parent 69d0fc8 commit 700170b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions go/private/actions/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ bzl_library(
"//go/private:common",
"//go/private:mode",
"//go/private:rpath",
"//go/private/rules:execgroup",
"@bazel_skylib//lib:collections",
],
)
Expand Down
5 changes: 5 additions & 0 deletions go/private/actions/link.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ load(
"@bazel_skylib//lib:collections.bzl",
"collections",
)
load(
"//go/private/rules:execgroup.bzl",
"LINK_EXEC_GROUP",
)

def _format_archive(d):
return "{}={}={}".format(d.label, d.importmap, d.file.path)
Expand Down Expand Up @@ -206,6 +210,7 @@ def emit_link(
inputs = inputs,
outputs = [executable],
mnemonic = "GoLink",
exec_group = LINK_EXEC_GROUP,
executable = go.toolchain._builder,
arguments = [builder_args, "--", tool_args],
env = go.env,
Expand Down
10 changes: 10 additions & 0 deletions go/private/rules/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ bzl_library(
"//go/private:mode",
"//go/private:providers",
"//go/private:rpath",
"//go/private/rules:execgroup",
"//go/private/rules:transition",
],
)
Expand All @@ -56,6 +57,14 @@ bzl_library(
], # keep
)

bzl_library(
name = "execgroup",
srcs = ["execgroup.bzl"],
visibility = [
"//go:__subpackages__",
],
)

bzl_library(
name = "info",
srcs = ["info.bzl"],
Expand Down Expand Up @@ -131,6 +140,7 @@ bzl_library(
"//go/private:mode",
"//go/private:providers",
"//go/private/rules:binary",
"//go/private/rules:execgroup",
"//go/private/rules:transition",
"@bazel_skylib//lib:structs",
],
Expand Down
5 changes: 5 additions & 0 deletions go/private/rules/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ load(
"//go/private/rules:transition.bzl",
"go_transition",
)
load(
"//go/private/rules:execgroup.bzl",
"RULES_GO_EXEC_GROUPS",
)
load(
"//go/private:mode.bzl",
"LINKMODES",
Expand Down Expand Up @@ -414,6 +418,7 @@ _go_binary_kwargs = {
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
},
"exec_groups": RULES_GO_EXEC_GROUPS,
"toolchains": [GO_TOOLCHAIN],
"doc": """This builds an executable from a set of source files,
which must all be in the `main` package. You can run the binary with
Expand Down
5 changes: 5 additions & 0 deletions go/private/rules/execgroup.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LINK_EXEC_GROUP = "GoLink"

RULES_GO_EXEC_GROUPS = {
LINK_EXEC_GROUP: exec_group(),
}
5 changes: 5 additions & 0 deletions go/private/rules/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ load(
"//go/private/rules:transition.bzl",
"go_transition",
)
load(
"//go/private/rules:execgroup.bzl",
"RULES_GO_EXEC_GROUPS",
)
load(
"//go/private:mode.bzl",
"LINKMODES",
Expand Down Expand Up @@ -443,6 +447,7 @@ _go_test_kwargs = {
},
"executable": True,
"test": True,
"exec_groups": RULES_GO_EXEC_GROUPS,
"toolchains": [GO_TOOLCHAIN],
"doc": """This builds a set of tests that can be run with `bazel test`.<br><br>
To run all tests in the workspace, and print output on failure (the
Expand Down

0 comments on commit 700170b

Please sign in to comment.