| # 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. |
| |
| """Top level BUILD.bazel in the @fuchsia_rust_toolchain repository.""" |
| |
| load("@fuchsia_build_config//:defs.bzl", "build_config") |
| load("@rules_rust//rust:toolchain.bzl", "rust_stdlib_filegroup", "rust_toolchain") |
| |
| host_os = build_config.host_os |
| host_arch = build_config.host_arch |
| host_triple = build_config.host_target_triple |
| |
| filegroup( |
| name = "rustc_lib", |
| srcs = glob( |
| ["lib/*.so"], |
| allow_empty = True, # This is empty on Mac builders. |
| ), |
| ) |
| |
| # Define the host Rust toolchain. |
| |
| rust_stdlib_filegroup( |
| name = "rust_std_host", |
| srcs = glob(["lib/rustlib/%s/lib/*" % host_triple]), |
| ) |
| |
| rust_toolchain( |
| name = "rust_%s_%s_toolchain" % (host_os, host_arch), |
| rustc = "//:bin/rustc", |
| rustc_lib = "//:rustc_lib", |
| clippy_driver = "//:bin/clippy-driver", |
| rust_std = "//:rust_std_host", |
| rust_doc = "//:bin/rustdoc", |
| binary_ext = "", |
| staticlib_ext = ".a", |
| dylib_ext = ".dylib" if host_os == "mac" else ".so", |
| stdlib_linkflags = ["-lpthread", "-ldl"] if host_os == "linux" else [], |
| exec_triple = host_triple, # e.g. "x86_64-unknown-linux-gnu", |
| target_triple = host_triple, # e.g. "x86_64-unknown-linux-gnu", |
| |
| # Ensure debug symbols are preserved even with --compilation_mode is |
| # set to 'fastbuild' or 'opt', as there are no separate actions to produce |
| # stripped and unstripped binaries in rules_rust. |
| # |
| # debug_info controls whether debug info is generated during compilation, |
| # and strip_level controls whether they are removed during linking. |
| |
| # LINT.IfChange |
| debug_info = { |
| "dbg": "2", |
| "fastbuild": "1", # default "0", i.e. no symbols. |
| "opt": "1", # default "0", i.e. no symbols. |
| }, |
| strip_level = { |
| "dbg": "none", |
| "fastbuild": "none", |
| "opt": "none", |
| }, |
| # LINT.ThenChange(//build/bazel/debug_symbols/README.md) |
| ) |
| |
| toolchain( |
| name = "rust_%s_%s" % (host_os, host_arch), |
| exec_compatible_with = [ |
| build_config.host_platform_cpu_constraint, |
| build_config.host_platform_os_constraint, |
| ], |
| target_compatible_with = [ |
| build_config.host_platform_cpu_constraint, # e.g. "@platforms//cpu:x86_64", |
| build_config.host_platform_os_constraint, # e.g. "@platforms//os:linux", |
| ], |
| toolchain = ":rust_%s_%s_toolchain" % (host_os, host_arch), |
| toolchain_type = "@rules_rust//rust:toolchain", |
| ) |
| |
| # Define the Fuchsia/x64 Rust toolchain |
| |
| rust_stdlib_filegroup( |
| name = "rust_std_fuchsia_x64", |
| srcs = glob(["lib/rustlib/x86_64-unknown-fuchsia/lib/*"]), |
| ) |
| |
| rust_toolchain( |
| name = "rust_fuchsia_x64_toolchain", |
| rustc = "//:bin/rustc", |
| rustc_lib = "//:rustc_lib", |
| clippy_driver = "//:bin/clippy-driver", |
| rust_std = "//:rust_std_fuchsia_x64", |
| rust_doc = "//:bin/rustdoc", |
| binary_ext = "", |
| staticlib_ext = ".a", |
| dylib_ext = ".so", |
| stdlib_linkflags = [], |
| exec_triple = "x86_64-unknown-fuchsia", |
| target_triple = "x86_64-unknown-fuchsia", |
| ) |
| |
| toolchain( |
| name = "rust_fuchsia_x64", |
| exec_compatible_with = [ |
| build_config.host_platform_cpu_constraint, |
| build_config.host_platform_os_constraint, |
| ], |
| target_compatible_with = [ |
| "@platforms//cpu:x86_64", |
| "@platforms//os:fuchsia", |
| ], |
| toolchain = ":rust_fuchsia_x64_toolchain", |
| toolchain_type = "@rules_rust//rust:toolchain", |
| ) |
| |
| # Define the Fuchsia/arm64 Rust toolchain |
| |
| rust_stdlib_filegroup( |
| name = "rust_std_fuchsia_arm64", |
| srcs = glob(["lib/rustlib/aarch64-unknown-fuchsia/lib/*"]), |
| ) |
| |
| rust_toolchain( |
| name = "rust_fuchsia_arm64_toolchain", |
| rustc = "//:bin/rustc", |
| rustc_lib = "//:rustc_lib", |
| clippy_driver = "//:bin/clippy-driver", |
| rust_std = "//:rust_std_fuchsia_arm64", |
| rust_doc = "//:bin/rustdoc", |
| binary_ext = "", |
| staticlib_ext = ".a", |
| dylib_ext = ".so", |
| stdlib_linkflags = [], |
| exec_triple = "aarch64-unknown-fuchsia", |
| target_triple = "aarch64-unknown-fuchsia", |
| # See https://fuchsia.dev/fuchsia-src/concepts/kernel/shadow_call_stack#use_in_zircon_fuchsia |
| # Rust compilers are detecting incompatible ABIs in rust builds. Any Rust |
| # code that is targeted for ARM64 Fuchsia must be compiled with shadow |
| # call stack to avoid build failures due to ABI mismatch. |
| extra_rustc_flags = ["-Zsanitizer=shadow-call-stack"], |
| ) |
| |
| toolchain( |
| name = "rust_fuchsia_arm64", |
| exec_compatible_with = [ |
| build_config.host_platform_cpu_constraint, |
| build_config.host_platform_os_constraint, |
| ], |
| target_compatible_with = [ |
| "@platforms//cpu:aarch64", |
| "@platforms//os:fuchsia", |
| ], |
| toolchain = ":rust_fuchsia_arm64_toolchain", |
| toolchain_type = "@rules_rust//rust:toolchain", |
| ) |
| |
| # Define the Fuchsia/riscv64 Rust toolchain |
| |
| rust_stdlib_filegroup( |
| name = "rust_std_fuchsia_riscv64", |
| # See https://doc.rust-lang.org/rustc/platform-support/riscv64gc-unknown-linux-gnu.html |
| # which this uses a "riscv64gc" prefix, while C++ uses only "riscv64" for the same |
| # ABI. |
| srcs = glob(["lib/rustlib/riscv64gc-unknown-fuchsia/lib/*"]), |
| ) |
| |
| rust_toolchain( |
| name = "rust_fuchsia_riscv64_toolchain", |
| rustc = "//:bin/rustc", |
| rustc_lib = "//:rustc_lib", |
| clippy_driver = "//:bin/clippy-driver", |
| rust_std = "//:rust_std_fuchsia_riscv64", |
| rust_doc = "//:bin/rustdoc", |
| binary_ext = "", |
| staticlib_ext = ".a", |
| dylib_ext = ".so", |
| stdlib_linkflags = [], |
| exec_triple = "riscv64-unknown-fuchsia", |
| target_triple = "riscv64-unknown-fuchsia", |
| # See https://fuchsia.dev/fuchsia-src/concepts/kernel/shadow_call_stack#use_in_zircon_fuchsia |
| # Rust compilers are detecting incompatible ABIs in rust builds. Any Rust |
| # code that is targeted for RISC-V64 Fuchsia must be compiled with shadow |
| # call stack to avoid build failures due to ABI mismatch. |
| extra_rustc_flags = ["-Zsanitizer=shadow-call-stack"], |
| ) |
| |
| toolchain( |
| name = "rust_fuchsia_riscv64", |
| exec_compatible_with = [ |
| build_config.host_platform_cpu_constraint, |
| build_config.host_platform_os_constraint, |
| ], |
| target_compatible_with = [ |
| "@platforms//cpu:riscv64", |
| "@platforms//os:fuchsia", |
| ], |
| toolchain = ":rust_fuchsia_riscv64_toolchain", |
| toolchain_type = "@rules_rust//rust:toolchain", |
| ) |