blob: fccc3e477b415f9c3ec994f5764a17a43f54c770 [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 ],
18 toolchain = "@rust//:toolchain_for_x86_64-unknown-linux-gnu_impl",
19 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 ],
35 toolchain = "@rust//:toolchain_for_armv7-unknown-linux-gnueabihf_impl",
36 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 ],
49 toolchain = "@rust//:toolchain_for_aarch64-unknown-linux-gnu_impl",
50 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 ],
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
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",
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
111toolchain(
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 Silverman0aa13732022-05-19 23:14:08 -0700122
123'''
124# TODO(Brian): Uncomment in the next change once dependencies exist.
125rust_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'''