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 | |
Brian Silverman | 847121b | 2022-03-09 15:48:08 -0800 | [diff] [blame] | 4 | # We have to declare our toolchains individually to get the corect constraints |
| 5 | # configured so we can robustly select the correct one for each of our |
| 6 | # platforms. |
| 7 | |
| 8 | toolchain( |
| 9 | name = "rust-toolchain-x86", |
| 10 | exec_compatible_with = [ |
| 11 | "@platforms//os:linux", |
| 12 | "@platforms//cpu:x86_64", |
| 13 | ], |
| 14 | target_compatible_with = [ |
| 15 | "@platforms//os:linux", |
| 16 | "@platforms//cpu:x86_64", |
| 17 | ], |
| 18 | toolchain = "@rust//:toolchain_for_x86_64-unknown-linux-gnu_impl", |
| 19 | toolchain_type = "@rules_rust//rust:toolchain", |
| 20 | ) |
| 21 | |
| 22 | toolchain( |
| 23 | name = "rust-toolchain-armv7", |
| 24 | exec_compatible_with = [ |
| 25 | "@platforms//os:linux", |
| 26 | "@platforms//cpu:x86_64", |
| 27 | ], |
| 28 | target_compatible_with = [ |
| 29 | "@platforms//os:linux", |
| 30 | "@platforms//cpu:armv7", |
| 31 | # Include this so we're incompatible with the roborio platform, to avoid |
| 32 | # subtle order dependencies. |
| 33 | "//tools/platforms/hardware:raspberry_pi", |
| 34 | ], |
| 35 | toolchain = "@rust//:toolchain_for_armv7-unknown-linux-gnueabihf_impl", |
| 36 | toolchain_type = "@rules_rust//rust:toolchain", |
| 37 | ) |
| 38 | |
| 39 | toolchain( |
| 40 | name = "rust-toolchain-arm64", |
| 41 | exec_compatible_with = [ |
| 42 | "@platforms//os:linux", |
| 43 | "@platforms//cpu:x86_64", |
| 44 | ], |
| 45 | target_compatible_with = [ |
| 46 | "@platforms//os:linux", |
| 47 | "@platforms//cpu:arm64", |
| 48 | ], |
| 49 | toolchain = "@rust//:toolchain_for_aarch64-unknown-linux-gnu_impl", |
| 50 | toolchain_type = "@rules_rust//rust:toolchain", |
| 51 | ) |
| 52 | |
Ravago Jones | 1680980 | 2021-11-18 20:40:03 -0800 | [diff] [blame] | 53 | toolchain( |
| 54 | name = "rust-toolchain-roborio", |
| 55 | exec_compatible_with = [ |
| 56 | "@platforms//os:linux", |
| 57 | "@platforms//cpu:x86_64", |
| 58 | ], |
| 59 | target_compatible_with = [ |
| 60 | "@platforms//os:linux", |
Brian Silverman | 847121b | 2022-03-09 15:48:08 -0800 | [diff] [blame] | 61 | "@platforms//cpu:armv7", |
Ravago Jones | 1680980 | 2021-11-18 20:40:03 -0800 | [diff] [blame] | 62 | "//tools/platforms/hardware:roborio", |
| 63 | ], |
| 64 | toolchain = "@rust//:toolchain_for_arm-unknown-linux-gnueabi_impl", |
| 65 | toolchain_type = "@rules_rust//rust:toolchain", |
| 66 | ) |
| 67 | |
| 68 | # The remainder of this file exists to create a NOOP toolchain for Rust on |
| 69 | # platforms that don't support Rust. We can probably get rid of this once |
| 70 | # https://github.com/bazelbuild/bazel/issues/12897 is fixed. |
| 71 | |
| 72 | write_file( |
| 73 | name = "noop_error_exit", |
| 74 | out = "noop_error_exit.sh", |
| 75 | content = [ |
| 76 | "#!/bin/bash", |
| 77 | "echo 'This should never be executed. Something went wrong.' >&2", |
| 78 | "echo 'This NOOP Rust toolchain should never be executed. Something went wrong.' >&2", |
| 79 | "echo 'Check that your target has `target_compatible_with` set to a platform that supports Rust.' >&2", |
| 80 | "exit 1", |
| 81 | ], |
| 82 | is_executable = True, |
| 83 | ) |
| 84 | |
| 85 | rust_stdlib_filegroup( |
| 86 | name = "empty_stdlib", |
| 87 | srcs = [":noop_error_exit"], |
| 88 | ) |
| 89 | |
| 90 | rust_toolchain( |
| 91 | name = "noop_rust_toolchain_impl", |
| 92 | binary_ext = "", |
| 93 | cargo = ":noop_error_exit", |
| 94 | clippy_driver = ":noop_error_exit", |
| 95 | default_edition = "2021", |
| 96 | dylib_ext = ".so", |
| 97 | exec_triple = "none", |
| 98 | os = "none", |
| 99 | rust_doc = ":noop_error_exit", |
| 100 | rust_lib = ":empty_stdlib", |
| 101 | rustc = ":noop_error_exit", |
| 102 | rustc_lib = ":noop_error_exit", |
| 103 | rustc_srcs = None, |
| 104 | rustfmt = ":noop_error_exit", |
| 105 | staticlib_ext = ".a", |
| 106 | stdlib_linkflags = [], |
| 107 | tags = ["manual"], |
| 108 | target_triple = "none", |
| 109 | ) |
| 110 | |
| 111 | toolchain( |
| 112 | name = "noop_rust_toolchain", |
| 113 | exec_compatible_with = [ |
| 114 | "@platforms//os:linux", |
| 115 | ], |
| 116 | target_compatible_with = [ |
| 117 | "//tools/platforms/rust:lacks_support", |
| 118 | ], |
| 119 | toolchain = ":noop_rust_toolchain_impl", |
| 120 | toolchain_type = "@rules_rust//rust:toolchain", |
| 121 | ) |
Brian Silverman | 0aa1373 | 2022-05-19 23:14:08 -0700 | [diff] [blame^] | 122 | |
| 123 | ''' |
| 124 | # TODO(Brian): Uncomment in the next change once dependencies exist. |
| 125 | rust_binary( |
| 126 | name = "tweak_cargo_raze_output", |
| 127 | srcs = ["tweak_cargo_raze_output.rs"], |
| 128 | visibility = ["//visibility:public"], |
| 129 | deps = [ |
| 130 | "//third_party/cargo:anyhow", |
| 131 | "//third_party/cargo:toml", |
| 132 | ], |
| 133 | ) |
| 134 | ''' |