|
| 1 | +# Copyright 2022 EngFlow Inc. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# This platform is essentially the same as the one provided in https://github.com/facebook/buck2/blob/804d62242214455d51787f7c8c96a1e12c75ec32/examples/remote_execution/engflow/platforms/defs.bzl |
| 16 | +# The main difference is we enable passing CPU and OS constraints and we use the sample EngFlow RE image. |
| 17 | +load("@prelude//:build_mode.bzl", "BuildModeInfo") |
| 18 | + |
| 19 | +def _platforms(ctx): |
| 20 | + constraints = dict() |
| 21 | + constraints.update(ctx.attrs.cpu_configuration[ConfigurationInfo].constraints) |
| 22 | + constraints.update(ctx.attrs.os_configuration[ConfigurationInfo].constraints) |
| 23 | + constraints.update(ctx.attrs.re_provider[ConfigurationInfo].constraints) |
| 24 | + configuration = ConfigurationInfo( |
| 25 | + constraints = constraints, |
| 26 | + values = {}, |
| 27 | + ) |
| 28 | + |
| 29 | + # A bookworm image with rust pre-installed. Image details can be found in https://gallery.ecr.aws/docker/library/rust. |
| 30 | + # Dockerfile can be found in https://github.com/rust-lang/docker-rust/blob/700c4f146427808cfb1e07a646e4afabbe99da4f/stable/bullseye/Dockerfile |
| 31 | + image = "docker://public.ecr.aws/docker/library/rust:1.83.0-bullseye@sha256:24118f76a7da011b22a25b8e9dbdbb549ed29c1eba635d6aa4a9c9f5ed545066" |
| 32 | + name = ctx.label.raw_target() |
| 33 | + platform = ExecutionPlatformInfo( |
| 34 | + label = ctx.label.raw_target(), |
| 35 | + configuration = configuration, |
| 36 | + executor_config = CommandExecutorConfig( |
| 37 | + local_enabled = False, |
| 38 | + remote_enabled = True, |
| 39 | + use_limited_hybrid = False, |
| 40 | + remote_execution_properties = { |
| 41 | + "container-image": image, |
| 42 | + }, |
| 43 | + remote_execution_use_case = "buck2-default", |
| 44 | + # TODO: Use output_paths |
| 45 | + remote_output_paths = "strict", |
| 46 | + ), |
| 47 | + ) |
| 48 | + |
| 49 | + return [ |
| 50 | + DefaultInfo(), |
| 51 | + ExecutionPlatformRegistrationInfo(platforms = [platform]), |
| 52 | + configuration, |
| 53 | + PlatformInfo(label = str(name), configuration = configuration), |
| 54 | + ] |
| 55 | + |
| 56 | +def _action_keys(ctx): |
| 57 | + return [ |
| 58 | + DefaultInfo(), |
| 59 | + BuildModeInfo(cell = ctx.attrs.cell, mode = ctx.attrs.mode), |
| 60 | + ] |
| 61 | + |
| 62 | +platforms = rule( |
| 63 | + attrs = { |
| 64 | + "cpu_configuration": attrs.dep(providers = [ConfigurationInfo]), |
| 65 | + "os_configuration": attrs.dep(providers = [ConfigurationInfo]), |
| 66 | + "re_provider": attrs.dep(providers = [ConfigurationInfo]), |
| 67 | + }, |
| 68 | + impl = _platforms |
| 69 | +) |
| 70 | + |
| 71 | +action_keys = rule( |
| 72 | + attrs = { |
| 73 | + "cell": attrs.string(), |
| 74 | + "mode": attrs.string(), |
| 75 | + }, |
| 76 | + impl = _action_keys |
| 77 | +) |
0 commit comments