| # 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. |
| |
| """ |
| C++ toolchain definitions for Clang. |
| """ |
| |
| load( |
| "@rules_fuchsia//common:toolchains/clang/toolchain_utils.bzl", |
| "generate_clang_cc_toolchain", |
| ) |
| load("@rules_fuchsia//common/platforms:utils.bzl", "to_bazel_cpu_name", "to_bazel_os_name") |
| |
| def define_host_prebuilt_clang_cc_toolchains(name, host_os, host_arch): |
| """Define host C++ toolchains that target both x64 and arm64 using a prebuilt Clang installation. |
| |
| Args: |
| name: A prefix for the name of the toolchains generated by this function. |
| host_os: Host os string using Fuchsia conventions. |
| host_arch: Host cpu architecture string, using Fuchsia conventions. |
| """ |
| if host_os == "linux": |
| sysroot_header_files = ["@//:linux_sysroot_headers"] |
| sysroot_library_files_x64 = ["@//:linux_sysroot_libs_x64"] |
| sysroot_library_files_arm64 = ["@//:linux_sysroot_libs_arm64"] |
| sysroot_path = "prebuilt/third_party/sysroot/linux" |
| else: |
| sysroot_header_files = [] |
| sysroot_library_files_x64 = [] |
| sysroot_library_files_arm64 = [] |
| sysroot_path = "" |
| |
| bazel_os = to_bazel_os_name(host_os) |
| bazel_arch = to_bazel_cpu_name(host_arch) |
| |
| generate_clang_cc_toolchain( |
| name = name + "_" + host_os + "_x64", |
| host_os = bazel_os, |
| host_arch = bazel_arch, |
| target_os = bazel_os, |
| target_arch = "x86_64", |
| sysroot_header_files = sysroot_header_files, |
| sysroot_library_files = sysroot_library_files_x64, |
| sysroot_path = sysroot_path, |
| ) |
| |
| generate_clang_cc_toolchain( |
| name = name + "_" + host_os + "_arm64", |
| host_os = bazel_os, |
| host_arch = bazel_arch, |
| target_os = bazel_os, |
| target_arch = "aarch64", |
| sysroot_header_files = sysroot_header_files, |
| sysroot_library_files = sysroot_library_files_arm64, |
| sysroot_path = sysroot_path, |
| ) |
| |
| def define_fuchsia_platform_prebuilt_clang_cc_toolchains(name, host_os, host_arch): |
| bazel_os = to_bazel_os_name(host_os) |
| bazel_arch = to_bazel_cpu_name(host_arch) |
| |
| generate_clang_cc_toolchain( |
| name = name + "_x64", |
| host_os = bazel_os, |
| host_arch = bazel_arch, |
| target_os = "fuchsia", |
| target_arch = "x86_64", |
| extra_target_compatible_with = ["@//build/bazel/platforms:fuchsia_artifacts_build_without_sdk_rules"], |
| ) |
| |
| generate_clang_cc_toolchain( |
| name = name + "_arm64", |
| host_os = bazel_os, |
| host_arch = bazel_arch, |
| target_os = "fuchsia", |
| target_arch = "aarch64", |
| extra_target_compatible_with = ["@//build/bazel/platforms:fuchsia_artifacts_build_without_sdk_rules"], |
| ) |
| |
| generate_clang_cc_toolchain( |
| name = name + "_riscv64", |
| host_os = bazel_os, |
| host_arch = bazel_arch, |
| target_os = "fuchsia", |
| target_arch = "riscv64", |
| extra_target_compatible_with = ["@//build/bazel/platforms:fuchsia_artifacts_build_without_sdk_rules"], |
| ) |