Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does bxl_actions require an execution platform? #529

Open
zjturner opened this issue Dec 21, 2023 · 1 comment
Open

Why does bxl_actions require an execution platform? #529

zjturner opened this issue Dec 21, 2023 · 1 comment

Comments

@zjturner
Copy link
Contributor

zjturner commented Dec 21, 2023

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, 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?

@wendy728
Copy link
Contributor

What you did is correct, but also I think that normal buck2 runtime has some fallback behavior that wasn't implemented in BXL. I think it makes sense to add it to BXL too.

Side note - we are planning on adding more platform docs soon, sorry for the sparse documentation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants