Skip to content

Commit

Permalink
[workspace] Add rust_toolchain externals (RobotLocomotion#20325)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwnimmer-tri authored Oct 11, 2023
1 parent 7cb258c commit 44546f1
Show file tree
Hide file tree
Showing 19 changed files with 1,004 additions and 8 deletions.
7 changes: 0 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ load("//tools/workspace:default.bzl", "add_default_workspace")

add_default_workspace()

# TODO(jwnimmer-tri) Before we enable Clarabel by default, we need to figure
# out how to provide the Rust toolchains as part of `default.bzl`. For now,
# we'll work around it by adding the toolchain definition to our WORKSPACE.
load("@rules_rust//rust:repositories.bzl", "rust_register_toolchains")

rust_register_toolchains()

# Add some special heuristic logic for using CLion with Drake.
load("//tools/clion:repository.bzl", "drake_clion_environment")

Expand Down
5 changes: 5 additions & 0 deletions tools/workspace/default.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ load("//tools/workspace/rules_pkg:repository.bzl", "rules_pkg_repository")
load("//tools/workspace/rules_python:repository.bzl", "rules_python_repository") # noqa
load("//tools/workspace/rules_rust:repository.bzl", "rules_rust_repository")
load("//tools/workspace/rules_rust_tinyjson:repository.bzl", "rules_rust_tinyjson_repository") # noqa
load("//tools/workspace/rust_toolchain:repository.bzl", "register_rust_toolchains", "rust_toolchain_repositories") # noqa
load("//tools/workspace/scs_internal:repository.bzl", "scs_internal_repository") # noqa
load("//tools/workspace/sdformat_internal:repository.bzl", "sdformat_internal_repository") # noqa
load("//tools/workspace/snopt:repository.bzl", "snopt_repository")
Expand Down Expand Up @@ -338,6 +339,8 @@ def add_default_repositories(excludes = [], mirrors = DEFAULT_MIRRORS):
rules_rust_repository(name = "rules_rust", mirrors = mirrors)
if "rules_rust_tinyjson" not in excludes:
rules_rust_tinyjson_repository(name = "rules_rust_tinyjson", mirrors = mirrors) # noqa
if "rust_toolchain" not in excludes:
rust_toolchain_repositories(mirrors = mirrors, excludes = excludes)
if "scs_internal" not in excludes:
scs_internal_repository(name = "scs_internal", mirrors = mirrors)
if "sdformat_internal" not in excludes:
Expand Down Expand Up @@ -412,6 +415,8 @@ def add_default_toolchains(excludes = []):
native.register_toolchains(
"//tools/py_toolchain:toolchain",
)
if "rust" not in excludes:
register_rust_toolchains()

def add_default_workspace(
repository_excludes = [],
Expand Down
8 changes: 7 additions & 1 deletion tools/workspace/rules_rust/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ load("@drake//tools/workspace:github.bzl", "github_archive")

def rules_rust_repository(
name,
mirrors = None):
mirrors = None,
extra_patches = None):
github_archive(
name = name,
repository = "bazelbuild/rules_rust", # License: Apache-2.0
upgrade_advice = """
An upgrade to @rules_rust also requires re-pinning the toolchain.
Run `drake/tools/workspace/rust_toolchain/upgrade.sh`.
""",
commit = "0.28.0",
sha256 = "e2f32fad3539bd57527901981ef6fb200d71030c30994bdf48faa6f56683f2d0", # noqa
patches = extra_patches,
mirrors = mirrors,
)
5 changes: 5 additions & 0 deletions tools/workspace/rust_toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load("//tools/lint:lint.bzl", "add_lint_tests")

add_lint_tests(
python_lint_extra_srcs = ["upgrade.py"],
)
17 changes: 17 additions & 0 deletions tools/workspace/rust_toolchain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

The bazel @rules_rust toolchain logic contains a lot of load-time options that
make it difficult to pin down exactly what is being fetched. However for Drake,
we want to keep a carefully inventory of what we're using.

To that end, we "vendor" the result of what rust_register_toolchains() would
usually do and commit the information into Drake. That vendored information is
created by the `update.sh` script and lives in the `lock/**` subdirectory tree.

In short, we pin pointers to rust-lang.org downloads for the compiler, standard
library, etc. along with sha256 checksums and generated BUILD wrapper files.

The rustc version is governed by whatever @rules_rust pins to by default.

The `upgrade.py` script is a fully-automatic mechanism to upgrade the pinned
toolchain after an upgrade to @rules_rust. It uses the `upgrade` directory as
a scratch workspace to help bootstrap the process.
224 changes: 224 additions & 0 deletions tools/workspace/rust_toolchain/lock/archives.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
# This file is automatically generated by upgrade.py.

ARCHIVES = [
dict(
name = "rust_darwin_aarch64__aarch64-apple-darwin__stable",
build_file = Label("@drake//tools/workspace/rust_toolchain:lock/details/BUILD.rust_darwin_aarch64__aarch64-apple-darwin__stable.bazel"),
downloads = "[]",
),
dict(
name = "rust_darwin_aarch64__aarch64-apple-darwin__stable_tools",
build_file = Label("@drake//tools/workspace/rust_toolchain:lock/details/BUILD.rust_darwin_aarch64__aarch64-apple-darwin__stable_tools.bazel"),
downloads = json.encode(
[
{
"sha256": "53fa11e327a57a147a1cafd58a6fa04d90db67d6b7f62b67d586b23cb2da3cb7",
"stripPrefix": "rustc-1.72.1-aarch64-apple-darwin/rustc",
"url": [
"https://static.rust-lang.org/dist/rustc-1.72.1-aarch64-apple-darwin.tar.gz",
],
},
{
"sha256": "68997a26526ec5ae25c9d9f1c35cd60be8a094b5388644c2e5ccce2b55c3777d",
"stripPrefix": "clippy-1.72.1-aarch64-apple-darwin/clippy-preview",
"url": [
"https://static.rust-lang.org/dist/clippy-1.72.1-aarch64-apple-darwin.tar.gz",
],
},
{
"sha256": "bd1364c57bdbf95c3b54a609ba85052490615274a4514c35f2515ec1aa65d26c",
"stripPrefix": "cargo-1.72.1-aarch64-apple-darwin/cargo",
"url": [
"https://static.rust-lang.org/dist/cargo-1.72.1-aarch64-apple-darwin.tar.gz",
],
},
{
"sha256": "16024a4bbcfb417c672f42c781352cc48bec6431559ccb50fe17a8a1af15ccda",
"stripPrefix": "rustfmt-1.72.1-aarch64-apple-darwin/rustfmt-preview",
"url": [
"https://static.rust-lang.org/dist/rustfmt-1.72.1-aarch64-apple-darwin.tar.gz",
],
},
{
"sha256": "70a9a6db8d424b85433c200c5e08d0592a4f32ff30f1802bff0208ce591019bb",
"stripPrefix": "llvm-tools-1.72.1-aarch64-apple-darwin/llvm-tools-preview",
"url": [
"https://static.rust-lang.org/dist/llvm-tools-1.72.1-aarch64-apple-darwin.tar.gz",
],
},
{
"sha256": "45adf6906c1a277508f6dd080f74dc35b3db2efc94f39bd6c007f75180b7bba0",
"stripPrefix": "rust-std-1.72.1-aarch64-apple-darwin/rust-std-aarch64-apple-darwin",
"url": [
"https://static.rust-lang.org/dist/rust-std-1.72.1-aarch64-apple-darwin.tar.gz",
],
},
],
),
),
dict(
name = "rust_darwin_x86_64__x86_64-apple-darwin__stable",
build_file = Label("@drake//tools/workspace/rust_toolchain:lock/details/BUILD.rust_darwin_x86_64__x86_64-apple-darwin__stable.bazel"),
downloads = "[]",
),
dict(
name = "rust_darwin_x86_64__x86_64-apple-darwin__stable_tools",
build_file = Label("@drake//tools/workspace/rust_toolchain:lock/details/BUILD.rust_darwin_x86_64__x86_64-apple-darwin__stable_tools.bazel"),
downloads = json.encode(
[
{
"sha256": "ddd7ef3194f717ffbbc9520a4b1b292ed2f76c503004c806bd59b27b976a01aa",
"stripPrefix": "rustc-1.72.1-x86_64-apple-darwin/rustc",
"url": [
"https://static.rust-lang.org/dist/rustc-1.72.1-x86_64-apple-darwin.tar.gz",
],
},
{
"sha256": "ac876eb8c55a2d6f45b2436619a59dbc93deccecfa0526a2f248726d7ef19359",
"stripPrefix": "clippy-1.72.1-x86_64-apple-darwin/clippy-preview",
"url": [
"https://static.rust-lang.org/dist/clippy-1.72.1-x86_64-apple-darwin.tar.gz",
],
},
{
"sha256": "68ebee1ff497c4c2c67033b5ad1f8ff53a96097094a75a27596699483d1f8a17",
"stripPrefix": "cargo-1.72.1-x86_64-apple-darwin/cargo",
"url": [
"https://static.rust-lang.org/dist/cargo-1.72.1-x86_64-apple-darwin.tar.gz",
],
},
{
"sha256": "39fba27f59ee5c09b79b6bb25313ebc2ac48952f8af7a0a8669d8d34fdf0cc47",
"stripPrefix": "rustfmt-1.72.1-x86_64-apple-darwin/rustfmt-preview",
"url": [
"https://static.rust-lang.org/dist/rustfmt-1.72.1-x86_64-apple-darwin.tar.gz",
],
},
{
"sha256": "5f9b3ae0f571b442f314cde95bb7a3a99d15404db59269e254030e7b8de461da",
"stripPrefix": "llvm-tools-1.72.1-x86_64-apple-darwin/llvm-tools-preview",
"url": [
"https://static.rust-lang.org/dist/llvm-tools-1.72.1-x86_64-apple-darwin.tar.gz",
],
},
{
"sha256": "a984c8b97237edd50641b32cc14dde199fb37e2118490514c7c9777bab772532",
"stripPrefix": "rust-std-1.72.1-x86_64-apple-darwin/rust-std-x86_64-apple-darwin",
"url": [
"https://static.rust-lang.org/dist/rust-std-1.72.1-x86_64-apple-darwin.tar.gz",
],
},
],
),
),
dict(
name = "rust_linux_aarch64__aarch64-unknown-linux-gnu__stable",
build_file = Label("@drake//tools/workspace/rust_toolchain:lock/details/BUILD.rust_linux_aarch64__aarch64-unknown-linux-gnu__stable.bazel"),
downloads = "[]",
),
dict(
name = "rust_linux_aarch64__aarch64-unknown-linux-gnu__stable_tools",
build_file = Label("@drake//tools/workspace/rust_toolchain:lock/details/BUILD.rust_linux_aarch64__aarch64-unknown-linux-gnu__stable_tools.bazel"),
downloads = json.encode(
[
{
"sha256": "04d75869d1c0f01e365d5d579456a81e817ed97463b70e7c273d031c48d2838b",
"stripPrefix": "rustc-1.72.1-aarch64-unknown-linux-gnu/rustc",
"url": [
"https://static.rust-lang.org/dist/rustc-1.72.1-aarch64-unknown-linux-gnu.tar.gz",
],
},
{
"sha256": "463f32172cdd6df9a13690652e1da63e8689b8267b9996a9cc890fc7fec67eb3",
"stripPrefix": "clippy-1.72.1-aarch64-unknown-linux-gnu/clippy-preview",
"url": [
"https://static.rust-lang.org/dist/clippy-1.72.1-aarch64-unknown-linux-gnu.tar.gz",
],
},
{
"sha256": "ad282984ef42304a1c700ecf47f75344c69bdcc0f682d61c46a8584d6e3e904b",
"stripPrefix": "cargo-1.72.1-aarch64-unknown-linux-gnu/cargo",
"url": [
"https://static.rust-lang.org/dist/cargo-1.72.1-aarch64-unknown-linux-gnu.tar.gz",
],
},
{
"sha256": "9010f967c04ca295fe495a153b8c1880cc04c874fb4b04cbfd231a75d2a6341d",
"stripPrefix": "rustfmt-1.72.1-aarch64-unknown-linux-gnu/rustfmt-preview",
"url": [
"https://static.rust-lang.org/dist/rustfmt-1.72.1-aarch64-unknown-linux-gnu.tar.gz",
],
},
{
"sha256": "b3ea855011ac898b51dea2891d1cec1cc22dbd1e9b9f8306e772b1258e447040",
"stripPrefix": "llvm-tools-1.72.1-aarch64-unknown-linux-gnu/llvm-tools-preview",
"url": [
"https://static.rust-lang.org/dist/llvm-tools-1.72.1-aarch64-unknown-linux-gnu.tar.gz",
],
},
{
"sha256": "7c43a6f56b100ce929967ef0d34fa316e0c4b233cb3ba84db67832135006c403",
"stripPrefix": "rust-std-1.72.1-aarch64-unknown-linux-gnu/rust-std-aarch64-unknown-linux-gnu",
"url": [
"https://static.rust-lang.org/dist/rust-std-1.72.1-aarch64-unknown-linux-gnu.tar.gz",
],
},
],
),
),
dict(
name = "rust_linux_x86_64__x86_64-unknown-linux-gnu__stable",
build_file = Label("@drake//tools/workspace/rust_toolchain:lock/details/BUILD.rust_linux_x86_64__x86_64-unknown-linux-gnu__stable.bazel"),
downloads = "[]",
),
dict(
name = "rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools",
build_file = Label("@drake//tools/workspace/rust_toolchain:lock/details/BUILD.rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools.bazel"),
downloads = json.encode(
[
{
"sha256": "9cf84e4de7302644e8c68b8d2abf6ac9e2b56409c3fa5b2ab95168bfaa5c562d",
"stripPrefix": "rustc-1.72.1-x86_64-unknown-linux-gnu/rustc",
"url": [
"https://static.rust-lang.org/dist/rustc-1.72.1-x86_64-unknown-linux-gnu.tar.gz",
],
},
{
"sha256": "5e7bcb8ef851a4d66b4aee533dab122a56d5f24992822b78d0244c1f859c3cb8",
"stripPrefix": "clippy-1.72.1-x86_64-unknown-linux-gnu/clippy-preview",
"url": [
"https://static.rust-lang.org/dist/clippy-1.72.1-x86_64-unknown-linux-gnu.tar.gz",
],
},
{
"sha256": "8eeb3412ddec7be32bb8599a7d86c8a5e3a09b82ca8d870f3b30133bf478a155",
"stripPrefix": "cargo-1.72.1-x86_64-unknown-linux-gnu/cargo",
"url": [
"https://static.rust-lang.org/dist/cargo-1.72.1-x86_64-unknown-linux-gnu.tar.gz",
],
},
{
"sha256": "7c4f1ce681b0c8d4da15fddf5cd0a7dc91917b79ae74ac917d0270fb2ec43c90",
"stripPrefix": "rustfmt-1.72.1-x86_64-unknown-linux-gnu/rustfmt-preview",
"url": [
"https://static.rust-lang.org/dist/rustfmt-1.72.1-x86_64-unknown-linux-gnu.tar.gz",
],
},
{
"sha256": "fb0850d5853780826cc60b5e16a9fcfcd7305c0c65314bbaaa92efb27d8d54bb",
"stripPrefix": "llvm-tools-1.72.1-x86_64-unknown-linux-gnu/llvm-tools-preview",
"url": [
"https://static.rust-lang.org/dist/llvm-tools-1.72.1-x86_64-unknown-linux-gnu.tar.gz",
],
},
{
"sha256": "d5d3751b4558864fd95f17b1b6eaeff3130a3de1a6920750a3b8c6b0fa03fb1c",
"stripPrefix": "rust-std-1.72.1-x86_64-unknown-linux-gnu/rust-std-x86_64-unknown-linux-gnu",
"url": [
"https://static.rust-lang.org/dist/rust-std-1.72.1-x86_64-unknown-linux-gnu.tar.gz",
],
},
],
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file is automatically generated by upgrade.py.

toolchain(
name = "toolchain",
exec_compatible_with = ["@platforms//cpu:aarch64","@platforms//os:osx"],
target_compatible_with = ["@platforms//cpu:aarch64","@platforms//os:osx"],
toolchain = "@rust_darwin_aarch64__aarch64-apple-darwin__stable_tools//:rust_toolchain",
toolchain_type = "@rules_rust//rust:toolchain",
target_settings = ["@rules_rust//rust/toolchain/channel:stable"],
)
Loading

0 comments on commit 44546f1

Please sign in to comment.