Why does bxl_actions require an execution platform?
- Dominant language
- Rust
- Stars
- 4.4k
- Forks
- 394
- PR merge metrics
- No merged PRs in 30d
Description
If you write `ctx.bxl_actions` from a bxl, the first thing you're confronted with is an error saying that you need to enable execution platforms.
It's not documented how to do this anywhere, the closest I could find was [this page](https://buck2.build/docs/developers/bxl_how_tos/), but all it really says is that you have to enable execution platforms, but doesn't offer any information about how to do this.
For anyone else coming along with the same problem, I had some code like this:
```
# defs.bzl
def _execution_platform_impl(ctx: AnalysisContext) -> list[Provider]:
constraints = dict()
constraints.update(ctx.attrs.cpu_configuration[ConfigurationInfo].constraints)
constraints.update(ctx.attrs.os_configuration[ConfigurationInfo].constraints)
cfg = ConfigurationInfo(constraints = constraints, values = {})
name = ctx.label.raw_target()
platform = ExecutionPlatformInfo(
label = name,
configuration = cfg,
executor_config = CommandExecutorConfig(
local_enabled = True,
remote_enabled = False,
use_windows_path_separators = ctx.attrs.use_windows_path_separators,
),
)
return [
DefaultInfo(),
platform,
PlatformInfo(label = str(name), configuration = cfg),
ExecutionPlatformRegistrationInfo(platforms = [platform]),
]
execution_platform = rule(
impl = _execution_platform_impl,
attrs = {
"cpu_configuration": attrs.dep(providers = [ConfigurationInfo]),
"os_configuration": attrs.dep(providers = [ConfigurationInfo]),
"use_windows_path_separators": attrs.bool(),
},
)
# BUCK
load(":defs.bzl", "execution_platform")
execution_platform(
name = "host-execution",
cpu_configuration = host_configuration.cpu,
os_configuration = host_configuration.os,
use_windows_path_separators = host_info().os.is_windows,
)
```
And then added this to my `.buckconfig`:
```
[build]
execution_platforms = root//platforms:host-execution
```
Not sure if this is correct / ideal / missing something, but hopefully that helps someone else coming along.
Back to my original question, why is this needed? Core buck2 runtime doesn't need this when just building software. Obviously it can run actions, declare outputs, run arbitrary rule code, etc, without an execution platform. So what is special about bxl that makes it need an execution platform in order to do the exact same operations?
Contributor guide
Assessment
This issue has not been assessed yet.