blob: a5a2f89db316c25f3afb4ea6be8dfb59057cf78e [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")
Brian Silverman547eda02022-05-19 23:14:08 -07003load("@rules_rust//rust:defs.bzl", "rust_binary")
Ravago Jones16809802021-11-18 20:40:03 -08004
Brian Silverman847121b2022-03-09 15:48:08 -08005# 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
9toolchain(
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
23toolchain(
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
40toolchain(
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 Jones16809802021-11-18 20:40:03 -080054toolchain(
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 Silverman847121b2022-03-09 15:48:08 -080062 "@platforms//cpu:armv7",
Ravago Jones16809802021-11-18 20:40:03 -080063 "//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
73write_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
86rust_stdlib_filegroup(
87 name = "empty_stdlib",
88 srcs = [":noop_error_exit"],
89)
90
91rust_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 Silvermana8ad1af2022-07-23 16:05:12 -0700101 rust_std = ":empty_stdlib",
Ravago Jones16809802021-11-18 20:40:03 -0800102 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
112toolchain(
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 Silverman0aa13732022-05-19 23:14:08 -0700123
Brian Silverman0aa13732022-05-19 23:14:08 -0700124rust_binary(
125 name = "tweak_cargo_raze_output",
126 srcs = ["tweak_cargo_raze_output.rs"],
Brian Silvermana8ad1af2022-07-23 16:05:12 -0700127 target_compatible_with = ["//tools/platforms/rust:has_support"],
Brian Silverman0aa13732022-05-19 23:14:08 -0700128 visibility = ["//visibility:public"],
129 deps = [
130 "//third_party/cargo:anyhow",
131 "//third_party/cargo:toml",
132 ],
133)
Brian Silverman8751d482022-05-18 23:28:44 -0700134
135cc_library(
136 name = "forward_allocator",
137 srcs = ["forward_allocator.c"],
138 visibility = ["//visibility:public"],
139)