Ravago Jones | 1680980 | 2021-11-18 20:40:03 -0800 | [diff] [blame] | 1 | load("@rules_rust//rust:toolchain.bzl", "rust_stdlib_filegroup", "rust_toolchain") |
| 2 | load("@bazel_skylib//rules:write_file.bzl", "write_file") |
| 3 | |
| 4 | # Similar to the one automatically generated by @rust, but with the correct |
| 5 | # hardware platform configured. |
| 6 | toolchain( |
| 7 | name = "rust-toolchain-roborio", |
| 8 | exec_compatible_with = [ |
| 9 | "@platforms//os:linux", |
| 10 | "@platforms//cpu:x86_64", |
| 11 | ], |
| 12 | target_compatible_with = [ |
| 13 | "@platforms//os:linux", |
| 14 | "//tools/platforms/hardware:roborio", |
| 15 | ], |
| 16 | toolchain = "@rust//:toolchain_for_arm-unknown-linux-gnueabi_impl", |
| 17 | toolchain_type = "@rules_rust//rust:toolchain", |
| 18 | ) |
| 19 | |
| 20 | # The remainder of this file exists to create a NOOP toolchain for Rust on |
| 21 | # platforms that don't support Rust. We can probably get rid of this once |
| 22 | # https://github.com/bazelbuild/bazel/issues/12897 is fixed. |
| 23 | |
| 24 | write_file( |
| 25 | name = "noop_error_exit", |
| 26 | out = "noop_error_exit.sh", |
| 27 | content = [ |
| 28 | "#!/bin/bash", |
| 29 | "echo 'This should never be executed. Something went wrong.' >&2", |
| 30 | "echo 'This NOOP Rust toolchain should never be executed. Something went wrong.' >&2", |
| 31 | "echo 'Check that your target has `target_compatible_with` set to a platform that supports Rust.' >&2", |
| 32 | "exit 1", |
| 33 | ], |
| 34 | is_executable = True, |
| 35 | ) |
| 36 | |
| 37 | rust_stdlib_filegroup( |
| 38 | name = "empty_stdlib", |
| 39 | srcs = [":noop_error_exit"], |
| 40 | ) |
| 41 | |
| 42 | rust_toolchain( |
| 43 | name = "noop_rust_toolchain_impl", |
| 44 | binary_ext = "", |
| 45 | cargo = ":noop_error_exit", |
| 46 | clippy_driver = ":noop_error_exit", |
| 47 | default_edition = "2021", |
| 48 | dylib_ext = ".so", |
| 49 | exec_triple = "none", |
| 50 | os = "none", |
| 51 | rust_doc = ":noop_error_exit", |
| 52 | rust_lib = ":empty_stdlib", |
| 53 | rustc = ":noop_error_exit", |
| 54 | rustc_lib = ":noop_error_exit", |
| 55 | rustc_srcs = None, |
| 56 | rustfmt = ":noop_error_exit", |
| 57 | staticlib_ext = ".a", |
| 58 | stdlib_linkflags = [], |
| 59 | tags = ["manual"], |
| 60 | target_triple = "none", |
| 61 | ) |
| 62 | |
| 63 | toolchain( |
| 64 | name = "noop_rust_toolchain", |
| 65 | exec_compatible_with = [ |
| 66 | "@platforms//os:linux", |
| 67 | ], |
| 68 | target_compatible_with = [ |
| 69 | "//tools/platforms/rust:lacks_support", |
| 70 | ], |
| 71 | toolchain = ":noop_rust_toolchain_impl", |
| 72 | toolchain_type = "@rules_rust//rust:toolchain", |
| 73 | ) |