Ravago Jones | 1680980 | 2021-11-18 20:40:03 -0800 | [diff] [blame] | 1 | load("@bazel_skylib//rules:write_file.bzl", "write_file") |
Austin Schuh | 8f99c82 | 2024-05-05 22:43:40 -0700 | [diff] [blame^] | 2 | load("@rules_rust//rust:toolchain.bzl", "rust_stdlib_filegroup", "rust_toolchain") |
Ravago Jones | 1680980 | 2021-11-18 20:40:03 -0800 | [diff] [blame] | 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 | ], |
Adam Snaider | 770b97b | 2023-08-04 21:07:48 -0700 | [diff] [blame] | 18 | toolchain = "@rust__x86_64-unknown-linux-gnu__stable_tools//:rust_toolchain", |
Brian Silverman | 847121b | 2022-03-09 15:48:08 -0800 | [diff] [blame] | 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 | ], |
Adam Snaider | 770b97b | 2023-08-04 21:07:48 -0700 | [diff] [blame] | 35 | toolchain = "@rust__armv7-unknown-linux-gnueabihf__stable_tools//:rust_toolchain", |
Brian Silverman | 847121b | 2022-03-09 15:48:08 -0800 | [diff] [blame] | 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 | ], |
Adam Snaider | 770b97b | 2023-08-04 21:07:48 -0700 | [diff] [blame] | 49 | toolchain = "@rust__aarch64-unknown-linux-gnu__stable_tools//:rust_toolchain", |
Brian Silverman | 847121b | 2022-03-09 15:48:08 -0800 | [diff] [blame] | 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 | ], |
Adam Snaider | 770b97b | 2023-08-04 21:07:48 -0700 | [diff] [blame] | 64 | toolchain = "@rust__arm-unknown-linux-gnueabi__stable_tools//:rust_toolchain", |
Ravago Jones | 1680980 | 2021-11-18 20:40:03 -0800 | [diff] [blame] | 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", |
Adam Snaider | 770b97b | 2023-08-04 21:07:48 -0700 | [diff] [blame] | 97 | exec_triple = "none-none-none", |
Ravago Jones | 1680980 | 2021-11-18 20:40:03 -0800 | [diff] [blame] | 98 | rust_doc = ":noop_error_exit", |
Brian Silverman | a8ad1af | 2022-07-23 16:05:12 -0700 | [diff] [blame] | 99 | rust_std = ":empty_stdlib", |
Ravago Jones | 1680980 | 2021-11-18 20:40:03 -0800 | [diff] [blame] | 100 | rustc = ":noop_error_exit", |
| 101 | rustc_lib = ":noop_error_exit", |
Ravago Jones | 1680980 | 2021-11-18 20:40:03 -0800 | [diff] [blame] | 102 | rustfmt = ":noop_error_exit", |
| 103 | staticlib_ext = ".a", |
| 104 | stdlib_linkflags = [], |
| 105 | tags = ["manual"], |
Adam Snaider | 770b97b | 2023-08-04 21:07:48 -0700 | [diff] [blame] | 106 | target_triple = "none-none-none", |
Ravago Jones | 1680980 | 2021-11-18 20:40:03 -0800 | [diff] [blame] | 107 | ) |
| 108 | |
| 109 | toolchain( |
| 110 | name = "noop_rust_toolchain", |
| 111 | exec_compatible_with = [ |
| 112 | "@platforms//os:linux", |
| 113 | ], |
| 114 | target_compatible_with = [ |
| 115 | "//tools/platforms/rust:lacks_support", |
| 116 | ], |
| 117 | toolchain = ":noop_rust_toolchain_impl", |
| 118 | toolchain_type = "@rules_rust//rust:toolchain", |
| 119 | ) |
Brian Silverman | 0aa1373 | 2022-05-19 23:14:08 -0700 | [diff] [blame] | 120 | |
Brian Silverman | 8751d48 | 2022-05-18 23:28:44 -0700 | [diff] [blame] | 121 | cc_library( |
| 122 | name = "forward_allocator", |
| 123 | srcs = ["forward_allocator.c"], |
| 124 | visibility = ["//visibility:public"], |
| 125 | ) |