| # Copyright 2022 The Fuchsia Authors. All rights reserved. | 
 | # Use of this source code is governed by a BSD-style license that can be | 
 | # found in the LICENSE file. | 
 | # | 
 |  | 
 | """Bazel platform() definitions for the Fuchsia platform build.""" | 
 |  | 
 | # The Fuchsia build will use transitions that change the --platforms=<label> | 
 | # value to modify the current build configuration. As such, each platform | 
 | # instance represents: | 
 | # | 
 | #  - A separate output directory for generated artifacts. | 
 | #  - An execution environment for generated binaries. | 
 | # | 
 | # The `//build/bazel/platforms:common` platform is used for all targets | 
 | # that do not generate os- or arch-specific binaries (e.g. Java bytecode, | 
 | # auto-generated headers and more). It is set to be the default platforms | 
 | # by using --platforms=//build/bazel/platforms:common in the auto-generated | 
 | # .bazelrc | 
 | # | 
 | # In theory, it should be possible to define additionnal platforms that | 
 | # correspond to specific Fuchsia product configurations, which will allow | 
 | # performing system assembly for several Fuchsia devices in a single | 
 | # build invocation (provided the right transitions are used). | 
 | # | 
 |  | 
 | load("@fuchsia_build_config//:defs.bzl", "build_config") | 
 | load("@fuchsia_build_info//:args.bzl", fuchsia_target_cpu = "target_cpu") | 
 |  | 
 | package(default_visibility = ["//visibility:public"]) | 
 |  | 
 | # The `//build/bazel/platforms:common` platform should be used for | 
 | # the default build configuration, and will contain all build | 
 | # artifacts which do not depend on a specific operating system | 
 | # or CPU architecture. | 
 | platform( | 
 |     name = "common", | 
 |     constraint_values = [], | 
 | ) | 
 |  | 
 | # The //build/bazel/platforms:host platform is used to target | 
 | # the build configuration matching the current host machine. | 
 | alias( | 
 |     name = "host", | 
 |     actual = ":" + build_config.host_tag_alt, | 
 | ) | 
 |  | 
 | alias( | 
 |     name = "default", | 
 |     actual = ":fuchsia_" + fuchsia_target_cpu, | 
 | ) | 
 |  | 
 | # The following platforms will be used to generate binaries | 
 | # for Fuchsia, Linux and MacOS systems respectively. Other | 
 | # parts of Bazel should define C++ and Rust toolchain instances | 
 | # and configs that match the same constraint values to be | 
 | # selected for them. | 
 |  | 
 | # The fuchsia_$cpu platform definitions are used to build | 
 | # Fuchsia binaries with our Bazel SDK rules. As a consequence | 
 | # they require a working @fuchsia_sdk and @fuchsia_clang | 
 | # repository to provide a sysroot and SDK atoms to access | 
 | # platform libraries. | 
 | platform( | 
 |     name = "fuchsia_x64", | 
 |     constraint_values = [ | 
 |         "@platforms//os:fuchsia", | 
 |         "@platforms//cpu:x86_64", | 
 |         ":fuchsia_artifacts_build_with_sdk_rules", | 
 |     ], | 
 | ) | 
 |  | 
 | platform( | 
 |     name = "fuchsia_arm64", | 
 |     constraint_values = [ | 
 |         "@platforms//os:fuchsia", | 
 |         "@platforms//cpu:arm64", | 
 |         ":fuchsia_artifacts_build_with_sdk_rules", | 
 |     ], | 
 | ) | 
 |  | 
 | platform( | 
 |     name = "fuchsia_riscv64", | 
 |     constraint_values = [ | 
 |         "@platforms//os:fuchsia", | 
 |         "@platforms//cpu:riscv64", | 
 |         ":fuchsia_artifacts_build_with_sdk_rules", | 
 |     ], | 
 | ) | 
 |  | 
 | # The fuchsia_platform_$cpu platform definitions are used to | 
 | # build Fuchsia binaries *without* Bazel SDK rules. These artifacts | 
 | # are considered part of the Fuchsia platform itself and are used | 
 | # to generate the SDK atoms that the fuchsia_$cpu platform targets | 
 | # rely on. | 
 | platform( | 
 |     name = "fuchsia_platform_x64", | 
 |     constraint_values = [ | 
 |         "@platforms//os:fuchsia", | 
 |         "@platforms//cpu:x86_64", | 
 |         ":fuchsia_artifacts_build_without_sdk_rules", | 
 |     ], | 
 | ) | 
 |  | 
 | platform( | 
 |     name = "fuchsia_platform_arm64", | 
 |     constraint_values = [ | 
 |         "@platforms//os:fuchsia", | 
 |         "@platforms//cpu:arm64", | 
 |         ":fuchsia_artifacts_build_without_sdk_rules", | 
 |     ], | 
 | ) | 
 |  | 
 | platform( | 
 |     name = "fuchsia_platform_riscv64", | 
 |     constraint_values = [ | 
 |         "@platforms//os:fuchsia", | 
 |         "@platforms//cpu:riscv64", | 
 |         ":fuchsia_artifacts_build_without_sdk_rules", | 
 |     ], | 
 | ) | 
 |  | 
 | # Host platform definitions. | 
 | platform( | 
 |     name = "linux_x64", | 
 |     constraint_values = [ | 
 |         "@platforms//os:linux", | 
 |         "@platforms//cpu:x86_64", | 
 |     ], | 
 |     exec_properties = { | 
 |         "container-image": build_config.rbe_container_image, | 
 |         "gceMachineType": build_config.rbe_gce_machine_type, | 
 |         "OSFamily": "Linux", | 
 |     }, | 
 | ) | 
 |  | 
 | platform( | 
 |     name = "linux_arm64", | 
 |     constraint_values = [ | 
 |         "@platforms//os:linux", | 
 |         "@platforms//cpu:arm64", | 
 |     ], | 
 | ) | 
 |  | 
 | # Configuration conditions for the platform values above. | 
 | config_setting( | 
 |     name = "is_fuchsia_x64", | 
 |     constraint_values = [ | 
 |         "@platforms//os:fuchsia", | 
 |         "@platforms//cpu:x86_64", | 
 |     ], | 
 | ) | 
 |  | 
 | config_setting( | 
 |     name = "is_fuchsia_arm64", | 
 |     constraint_values = [ | 
 |         "@platforms//os:fuchsia", | 
 |         "@platforms//cpu:arm64", | 
 |     ], | 
 | ) | 
 |  | 
 | config_setting( | 
 |     name = "is_fuchsia_riscv64", | 
 |     constraint_values = [ | 
 |         "@platforms//os:fuchsia", | 
 |         "@platforms//cpu:riscv64", | 
 |     ], | 
 | ) | 
 |  | 
 | config_setting( | 
 |     name = "is_linux_x64", | 
 |     constraint_values = [ | 
 |         "@platforms//os:linux", | 
 |         "@platforms//cpu:x86_64", | 
 |     ], | 
 | ) | 
 |  | 
 | config_setting( | 
 |     name = "is_linux_arm64", | 
 |     constraint_values = [ | 
 |         "@platforms//os:linux", | 
 |         "@platforms//cpu:arm64", | 
 |     ], | 
 | ) | 
 |  | 
 | # A constraint dimension which indiciates whether Fuchsia artifacts | 
 | # are generated using SDK rules or not. Platform binaries cannot use | 
 | # SDK rules. | 
 | constraint_setting( | 
 |     name = "fuchsia_artifacts_build_mode", | 
 |     default_constraint_value = ":fuchsia_artifacts_build_with_sdk_rules", | 
 | ) | 
 |  | 
 | constraint_value( | 
 |     name = "fuchsia_artifacts_build_without_sdk_rules", | 
 |     constraint_setting = ":fuchsia_artifacts_build_mode", | 
 | ) | 
 |  | 
 | constraint_value( | 
 |     name = "fuchsia_artifacts_build_with_sdk_rules", | 
 |     constraint_setting = ":fuchsia_artifacts_build_mode", | 
 | ) |