-
Notifications
You must be signed in to change notification settings - Fork 4k
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
exec_properties and remote execution platforms in Bazel 1.0 #10266
Comments
@eytankidron you might want to publish this as a blog post? |
- Using RBE autoconfig - changed to execution_properties bazelbuild/bazel#10266 - Added instructions on how to update JDK in bazel GitOrigin-RevId: 61393debe408ee4a0cd746d8dd0ccb058d1c7e06
- Using RBE autoconfig - changed to execution_properties bazelbuild/bazel#10266 - Added instructions on how to update JDK in bazel GitOrigin-RevId: 61393debe408ee4a0cd746d8dd0ccb058d1c7e06
- Using RBE autoconfig - changed to execution_properties bazelbuild/bazel#10266 - Added instructions on how to update JDK in bazel GitOrigin-RevId: 61393debe408ee4a0cd746d8dd0ccb058d1c7e06
Thanks for writing these great docs! For future readers: It seems like the |
@juliexxia is this related to your work exec groups |
|
This is not exactly an issue as such. It is a description of how to use
exec_properties
in Bazel 1.0 and a doc for migrating from the old way of handling multiple remote execution platforms (used in Bazel versions before 1.0) to the new way of handling such platforms (used in Bazel versions 1.0 and up).Background
Bazel 1.0 (and to a limited extend Bazel 0.29) introduces the
exec_properties
attribute which may be assigned to a platform or to a target.exec_properties
in a platform is basically just a replacement of the deprecatedremote_execution_properties
. However, the ability to setexec_properties
in a target is new.If you have multiple platforms that only differ in execution properties, you can simplify your configuration. You would set
exec_properties
on the target and replace the multiple platforms by a single one.Note that this simplification only applies if your targets do not need to select different toolchains.
Is this migration for me?
In order to figure out whether this migration would benefit your work space, let’s break the migration down to two parts:
remote_execution_properties
toexec_properties
.exec_compatible_with
attribute with theexec_properties
attribute in the targets.Part 1
If you have any platforms using the deprecated
remote_execution_properties
attribute or if you callrbe_autoconfig
without setting the attributeuse_legacy_platform_definition = False
, then you probably want to do part 1 of the migration.This migration allows platforms to be used by targets that populate their
exec_properties
attribute.Part 2
The goal of part 2 of the migration is to simplify your setup and reduce the number of platforms. It is relevant for setups that have at least two platforms that only differ in remote execution properties. In this case, the execution properties can be set on the target and the extra platforms can be removed.
These platforms would typically have different constraints. This is how targets choose one platform over the other. If these constraints exist for the sole purpose of distinguishing between these platforms and do not affect toolchains in any way, this is a good indication that the platforms are good candidates for this collapsing.
Here is an example of such platforms. In this example we have two platforms, one for running on
n1-standard-2
machines and one for running onn1-standard-8
machines (this example uses theremote_execution_properties
attribute, which means it hasn’t yet undergone part 1 of the migration).Another example of platforms that may be collapsed is the following pair of platforms:
rbe_autoconfig
(e.g.@rbe_default//config:platform
), andThe reason why this collapsing of platforms is now possible is because
rbe_autoconfig
now accepts remote execution properties directly, which it did not in earlier versions.Migration steps
Let’s break up the migration into two parts as outlined above:
Part 1
rbe_autoconfig
If you are calling rbe_autoconfig from your
WORKSPACE
file, adduse_legacy_platform_definition = False
as follows:This will cause the underlying platform
@rbe_default//config:platform
to useexec_properties
rather thanremote_execution_properties
.platforms
In every platform in your work space replace
remote_execution_properties
withexec_properties
.Note that while
remote_execution_properties
receives a protobuf-as-string value,exec_properties
receives a dict of string->string. If you are using RBE, do not create that dict manually. Instead use create_rbe_exec_properties_dict.For example, this platform:
Would be replaced by this platform:
Deal with inter-repo dependency of platforms
Note that updating all the platforms in your repo from using
remote_execution_properties
to usingexec_properties
might not be sufficient if any of your platforms inherit from platforms from other repos. And vice versa; if there are platforms in other repos that inherit from your platforms, they might be broken by this change.The reason for this is that platforms must either use
remote_execution_properties
orexec_properties
. They cannot use a combination of both.Part 2
Part 2 of the migration will assume that part 1 has completed and no platform is using the deprecated
remote_execution_properties
.Identify platforms to be collapsed
Identify the platforms that can be collapsed into a single platform.
For these platforms, define:
Some examples are:
gceMachineType
; Default:n1-standard-2
; Specialized:n1-standard-8
, ordockerNetwork
; Default:off
; Specialized:standard
.Declare property values in WORKSPACE
When referencing an execution property value it is best to do so through a constant defined in the
WORKSPACE
file via a repository rule that creates a local rep. See GitHub for more about why this is considered best practice. It is typically enough to just define the specialized values as constants but for the sake of completeness, this migration process includes defining both the specialized values and the default values.In order to define these constants we should distinguish between standard remote execution values and non-standard remote execution values.
STANDARD_PROPERTY_SETS
in exec_properties.bzl.The following code snippet, which would live in the
WORKSPACE
file, demonstrates both types:Update rbe_autoconfig with default values
The default remote execution property values are the remote execution property values that will apply to targets that do not choose to override them. These values should be set directly on your platform. If you are using
rbe_autoconfig
, you can pass them as an attribute to the rule.The following is an example that creates, in the
WORKSPACE
file, an underlying platform withSMALL_MACHINE
andNETWORK_OFF
:In the example above, specifying
NETWORK_OFF
is not actually necessary sinceoff
is the default value fordockerNetwork
. It was added here just for clarity and symmetry (and to demonstrate the use ofdicts.add
). Settingexec_properties = SMALL_MACHINE
would have been sufficient and equivalent in this case.Update targets
Identify all the targets that need the specialized remote execution value. To find them, look for targets that use
exec_compatible_with
field to select non-default platforms. Remove these constraints and populate theexec_property
field with the corresponding constant.Clean up constraints and local platforms
At this point you should probably no longer be using the constraint settings and constraint values that were used to distinguish between platforms, and which were previously set in the
exec_compatible_with
attributes of the targets that you just updated.You can now remove them.
Hopefully, the only place that these constraints are still used are in platforms, which can now be removed as well.
You may have local platforms which inherit from a base local platform, but add the just-deleted constraint. These platforms were necessary in order to locally run targets that were compatible with that constraint but are no longer necessary once the constraint is no longer being used.
Removing these platforms also entails registering other platforms (presumably just
@rbe_default//config:platform
) in their place. This registration can be in theWORKSPACE
or through command line flags or bazelrc.The text was updated successfully, but these errors were encountered: