| # 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_sdk_" + fuchsia_target_cpu, |
| ) |
| |
| # The following platforms will be used to generate binaries |
| # for Fuchsia and Linux 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_sdk_$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_sdk_x64", |
| constraint_values = [ |
| "@platforms//os:fuchsia", |
| "@platforms//cpu:x86_64", |
| ":fuchsia_artifacts_build_with_sdk_rules", |
| ], |
| ) |
| |
| platform( |
| name = "fuchsia_sdk_arm64", |
| constraint_values = [ |
| "@platforms//os:fuchsia", |
| "@platforms//cpu:arm64", |
| ":fuchsia_artifacts_build_with_sdk_rules", |
| ], |
| ) |
| |
| platform( |
| name = "fuchsia_sdk_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. |
| |
| # TODO(https://fxbug.dev/484422864): Use "host_*" for host platforms and use |
| # "linux_*" other purposes, such as Starnix binaries. Consider renaming |
| # "linux_*" to "starnix_linux_*" to avoid ambiguity. |
| platform( |
| name = "linux_x64", |
| constraint_values = [ |
| "@platforms//os:linux", |
| "@platforms//cpu:x86_64", |
| ], |
| exec_properties = { |
| "container-image": build_config.rbe_container_image, |
| "OSFamily": "Linux", |
| "Pool": build_config.rbe_pool_name, |
| }, |
| ) |
| |
| platform( |
| name = "linux_arm64", |
| constraint_values = [ |
| "@platforms//os:linux", |
| "@platforms//cpu:arm64", |
| ], |
| ) |
| |
| # TODO(https://fxbug.dev/484422864): Make these standalone platforms that use |
| # the more permissive sysroot. |
| alias( |
| name = "host_linux_x64", |
| actual = ":linux_x64", |
| ) |
| |
| alias( |
| name = "host_linux_arm64", |
| actual = ":linux_arm64", |
| ) |
| |
| # Configuration conditions for the platform values above. |
| # Like `"@platforms//os:fuchsia"`, the `is_fuchsia_${target_cpu}` settings are |
| # true for both Fuchsia platform and Bazel SDK-using platforms. |
| |
| config_setting( |
| name = "is_fuchsia_with_sdk_rules", |
| constraint_values = [ |
| "@platforms//os:fuchsia", |
| ":fuchsia_artifacts_build_with_sdk_rules", |
| ], |
| ) |
| |
| config_setting( |
| name = "is_fuchsia_platform", |
| constraint_values = [ |
| "@platforms//os:fuchsia", |
| ":fuchsia_artifacts_build_without_sdk_rules", |
| ], |
| ) |
| |
| 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", |
| ], |
| ) |
| |
| # Use this to match the host operating system, independent of its CPU. |
| # This will match `target_compatible_with = HOST_OS_CONSTRAINTS` where |
| # HOST_OS_CONSTRAINTS is defined by //build/bazel/platforms:constraints.bzl. |
| config_setting( |
| name = "is_host_os", |
| constraint_values = [ |
| build_config.host_platform_os_constraint, |
| ], |
| ) |
| |
| # 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", |
| ) |