Code Monkey home page Code Monkey logo

rules_platform's Introduction

rules_platform

This repository contains all platforms-related rules or transitions that rules author/Bazel users could use. The README should be kept updated as new rules/transition get added to the repo.

For questions or concern, please email [email protected].

Motivation

Many rule authors and users want to create targets that can easily change the target platform: rule authors may want to add convenient rule attributes for this, whereas users frequently need to bundle together executables for multiple platforms in a single high-level artifact. This repo houses new rules/transition which rules authors and Bazel users can import and use. Because these are Starlark implementations, with no Bazel changes, rules authos can feel free to extend or ignore these as needed.

Rules

Use case: Depend on a target built for a different platform

The platform_data rule can be used to change the target platform of a target, and then depend on that elsewhere in the build tree.

cc_binary(name = "foo")

platform_data(
    name = "foo_embedded",
    target = ":foo",
    platform = "//my/new:platform",
)

py_binary(
    name = "flasher",
    srcs = ...,
    data = [
        ":foo_embedded",
    ],
)

Regardless of what platform the top-level :flasher binary is built for, the :foo_embedded target will be built for //my/new:platform.

rules_platform's People

Contributors

aranguyen avatar wyverald avatar

Stargazers

Cornelius Riemenschneider avatar George Kontridze avatar Lenny Khazan avatar Davide Asnaghi avatar

Watchers

John Cater avatar James Cloos avatar Greg avatar  avatar

rules_platform's Issues

Provide a transition for switching the target platform to the exec platform?

In bazel-contrib/rules_oci#590 and bazelbuild/rules_rust#2684 we noticed that a common mistake in rulesets is that they use executables provided by toolchains outside the scope of ctx.actions.run(). Namely, they get embedded into runfiles directories of binaries and tests.

One approach to work around this issue is to declare "run" toolchains, where you essentially leave exec_compatible_with cleared, but set target_compatible_with instead. This is what rules_python uses, which it can do because the toolchain is never directly invoked as part of ctx.actions.run(). It's only embedded into runfiles directories, so that a subsequent py_binary() can run it. In other cases this is impractical, because there is a desire to use tools both within ctx.actions.run() AND runfiles directories. In those cases you need to declare all toolchains in twofold, which is highly inconvenient.

In the PRs linked above we managed to prevent the duplication by adding a special transition like this:

def _transition_to_target_impl(settings, attr):
    return {
        # String conversion is needed to prevent a crash with Bazel 6.x.
        "//command_line_option:extra_execution_platforms": [
            str(platform)
            for platform in settings["//command_line_option:platforms"]
        ],
    }

transition_to_target = transition(
    implementation = _transition_to_target_impl,
    inputs = ["//command_line_option:platforms"],
    outputs = ["//command_line_option:extra_execution_platforms"],
)

This can be combined with a helper rule that depends on a toolchain and returns its configuration through one or more providers. By setting the execution platforms to the target platform, the toolchain resolution is performed in such a way that the exec and target platforms are identical.

Considering that we already needed a transition like this in multiple places, would it make sense to provide it as part of rules_platform? Or would it instead be desirable to extend Bazel's Starlark API for supporting more flexible resolution of toolchains? See bazelbuild/bazel#19645.

`platform_data` required executable targets

This came up in a code review discussion for an (accidental) re-implementation of platform_data: the target in platform_data is required to be executable = True. I thought the reason it's called platform_data and not platform_binary is specifically because the target doesn't have to be created by a binary rule, but can be any kind of data!

It would be nice to relax this restriction.

Tag 0.1.2

Was tag/release 0.1.2 deleted? I was building against it, but it no longer exists.

Edit: and at some point in the last few days, the checksum on the 0.1.0 package was changed. Can you not edit/remove existing releases? It breaks the build for everyone that uses this package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.