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