Skip to content

Commit

Permalink
Define resource_set for SwiftCompile action.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 449761479
  • Loading branch information
Googler authored and swiple-rules-gardener committed May 19, 2022
1 parent c721682 commit fcc3a59
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions swift/internal/actions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def run_toolchain_action(
),
mnemonic = mnemonic if mnemonic else action_name,
tools = depset(tools, transitive = [tool_config.tool_inputs]),
resource_set = tool_config.resource_set,
**kwargs
)

Expand Down
5 changes: 5 additions & 0 deletions swift/internal/toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ _ToolConfigInfo = provider(
"env",
"executable",
"execution_requirements",
"resource_set",
"tool_input_manifests",
"tool_inputs",
"use_param_file",
Expand Down Expand Up @@ -277,6 +278,7 @@ def _tool_config(
args = [],
env = {},
execution_requirements = {},
resource_set = None,
tool_input_manifests = [],
tool_inputs = depset(),
use_param_file = False,
Expand All @@ -293,6 +295,8 @@ def _tool_config(
invoking actions using this tool.
execution_requirements: A dictionary of execution requirements that
should be passed when creating actions with this tool.
resource_set: The function which build resource set (mem, cpu) for local
invocation of the action.
tool_input_manifests: A list of input runfiles metadata for tools that
should be passed into the `input_manifests` argument of the
`ctx.actions.run` call that registers actions using this tool (see
Expand Down Expand Up @@ -320,6 +324,7 @@ def _tool_config(
env = env,
executable = executable,
execution_requirements = execution_requirements,
resource_set = resource_set,
tool_input_manifests = tool_input_manifests,
tool_inputs = tool_inputs,
use_param_file = use_param_file,
Expand Down
6 changes: 6 additions & 0 deletions swift/toolchains/xcode_swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,11 @@ def _all_action_configs(

return action_configs

def _swift_compile_resource_set(_os, inputs_size):
# The `os` argument is unused, but the Starlark API requires both
# positional arguments.
return {"cpu": 1, "memory": 200. + inputs_size * 0.015}

def _all_tool_configs(
custom_toolchain,
env,
Expand Down Expand Up @@ -553,6 +558,7 @@ def _all_tool_configs(
driver_mode = "swiftc",
env = env,
execution_requirements = execution_requirements,
resource_set = _swift_compile_resource_set,
swift_executable = swift_executable,
tool_input_manifests = generated_header_rewriter.input_manifests,
tool_inputs = generated_header_rewriter.inputs,
Expand Down

1 comment on commit fcc3a59

@brentleyjones
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.