From ae6971055b32f8e7a0b9b5a5cb3092db99075019 Mon Sep 17 00:00:00 2001 From: Lucas Bergman Date: Thu, 5 Dec 2024 18:37:03 +0000 Subject: [PATCH] Add rustfmt_toolchain This makes the nixpkgs_rust_configure repo rule add a rustfmt_toolchain alongside rust_toolchain, using the same rustfmt binary as the former. Support for a separate toolchain for rustfmt was added in bazelbuild/rules_rust#1719. --- testing/rust/MODULE.bazel | 2 +- toolchains/rust/README.md | 2 +- toolchains/rust/rust.bzl | 18 ++++++++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/testing/rust/MODULE.bazel b/testing/rust/MODULE.bazel index 4a40978af..01dd0e781 100644 --- a/testing/rust/MODULE.bazel +++ b/testing/rust/MODULE.bazel @@ -43,7 +43,7 @@ rust.toolchain( non_module_deps = use_extension("//:non_module_deps.bzl", "non_module_deps") use_repo(non_module_deps, "nixpkgs") use_repo(non_module_deps, "nixpkgs_config_rust_toolchain") -register_toolchains("@nixpkgs_config_rust_toolchain//:rust_nix") +register_toolchains("@nixpkgs_config_rust_toolchain//:all") use_repo(non_module_deps, "nixpkgs_config_cc") use_repo(non_module_deps, "nixpkgs_config_cc_info") diff --git a/toolchains/rust/README.md b/toolchains/rust/README.md index 4afe22eb9..9dafab937 100644 --- a/toolchains/rust/README.md +++ b/toolchains/rust/README.md @@ -2,7 +2,7 @@ -Rules for importing a Rust toolchain from Nixpkgs. +Rules for importing a Rust and rustfmt toolchain from Nixpkgs. # Rules diff --git a/toolchains/rust/rust.bzl b/toolchains/rust/rust.bzl index f87169550..9bb39c169 100644 --- a/toolchains/rust/rust.bzl +++ b/toolchains/rust/rust.bzl @@ -1,6 +1,6 @@ """ -Rules for importing a Rust toolchain from Nixpkgs. +Rules for importing a Rust and rustfmt toolchain from Nixpkgs. # Rules @@ -108,7 +108,7 @@ pkgs.buildEnv {{ visibility = ["//visibility:public"], ) - load('@rules_rust//rust:toolchain.bzl', 'rust_toolchain') + load('@rules_rust//rust:toolchain.bzl', 'rust_toolchain', 'rustfmt_toolchain') rust_toolchain( name = "rust_nix_impl", rust_doc = ":rust_doc", @@ -127,6 +127,12 @@ pkgs.buildEnv {{ stdlib_linkflags = {stdlib_linkflags}, visibility = ["//visibility:public"], ) + + rustfmt_toolchain( + name = "rustfmt_nix_impl", + rustfmt = ":rustfmt", + visibility = ["//visibility:public"], + ) EOF ''; }} @@ -140,6 +146,14 @@ toolchain( exec_compatible_with = {exec_constraints}, target_compatible_with = {target_constraints}, ) + +toolchain( + name = "rustfmt_nix", + toolchain = "@{toolchain_repo}//:rustfmt_nix_impl", + toolchain_type = "@rules_rust//rust/rustfmt:toolchain_type", + exec_compatible_with = {exec_constraints}, + target_compatible_with = {target_constraints}, +) """ def _nixpkgs_rust_toolchain_impl(repository_ctx):