blob: 707c40afdd9b622b3c8e345af55669e47e10e6bc [file] [log] [blame]
Ravago Jones16809802021-11-18 20:40:03 -08001load("@rules_rust//rust:toolchain.bzl", "rust_stdlib_filegroup", "rust_toolchain")
2load("@bazel_skylib//rules:write_file.bzl", "write_file")
3
Brian Silverman847121b2022-03-09 15:48:08 -08004# 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
8toolchain(
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 Snaider770b97b2023-08-04 21:07:48 -070018 toolchain = "@rust__x86_64-unknown-linux-gnu__stable_tools//:rust_toolchain",
Brian Silverman847121b2022-03-09 15:48:08 -080019 toolchain_type = "@rules_rust//rust:toolchain",
20)
21
22toolchain(
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 Snaider770b97b2023-08-04 21:07:48 -070035 toolchain = "@rust__armv7-unknown-linux-gnueabihf__stable_tools//:rust_toolchain",
Brian Silverman847121b2022-03-09 15:48:08 -080036 toolchain_type = "@rules_rust//rust:toolchain",
37)
38
39toolchain(
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 Snaider770b97b2023-08-04 21:07:48 -070049 toolchain = "@rust__aarch64-unknown-linux-gnu__stable_tools//:rust_toolchain",
Brian Silverman847121b2022-03-09 15:48:08 -080050 toolchain_type = "@rules_rust//rust:toolchain",
51)
52
Ravago Jones16809802021-11-18 20:40:03 -080053toolchain(
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 Silverman847121b2022-03-09 15:48:08 -080061 "@platforms//cpu:armv7",
Ravago Jones16809802021-11-18 20:40:03 -080062 "//tools/platforms/hardware:roborio",
63 ],
Adam Snaider770b97b2023-08-04 21:07:48 -070064 toolchain = "@rust__arm-unknown-linux-gnueabi__stable_tools//:rust_toolchain",
Ravago Jones16809802021-11-18 20:40:03 -080065 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
72write_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
85rust_stdlib_filegroup(
86 name = "empty_stdlib",
87 srcs = [":noop_error_exit"],
88)
89
90rust_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 Snaider770b97b2023-08-04 21:07:48 -070097 exec_triple = "none-none-none",
Ravago Jones16809802021-11-18 20:40:03 -080098 rust_doc = ":noop_error_exit",
Brian Silvermana8ad1af2022-07-23 16:05:12 -070099 rust_std = ":empty_stdlib",
Ravago Jones16809802021-11-18 20:40:03 -0800100 rustc = ":noop_error_exit",
101 rustc_lib = ":noop_error_exit",
102 rustc_srcs = None,
103 rustfmt = ":noop_error_exit",
104 staticlib_ext = ".a",
105 stdlib_linkflags = [],
106 tags = ["manual"],
Adam Snaider770b97b2023-08-04 21:07:48 -0700107 target_triple = "none-none-none",
Ravago Jones16809802021-11-18 20:40:03 -0800108)
109
110toolchain(
111 name = "noop_rust_toolchain",
112 exec_compatible_with = [
113 "@platforms//os:linux",
114 ],
115 target_compatible_with = [
116 "//tools/platforms/rust:lacks_support",
117 ],
118 toolchain = ":noop_rust_toolchain_impl",
119 toolchain_type = "@rules_rust//rust:toolchain",
120)
Brian Silverman0aa13732022-05-19 23:14:08 -0700121
Brian Silverman8751d482022-05-18 23:28:44 -0700122cc_library(
123 name = "forward_allocator",
124 srcs = ["forward_allocator.c"],
125 visibility = ["//visibility:public"],
126)