Skip to content

Commit

Permalink
Add rustfmt_toolchain
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lucasbergman committed Dec 10, 2024
1 parent 8fed658 commit 736fd69
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion testing/rust/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion toolchains/rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- Edit the docstring in `toolchains/rust/rust.bzl` and run `bazel run //docs:update-README.md` to change this repository's `README.md`. -->

Rules for importing a Rust toolchain from Nixpkgs.
Rules for importing a Rust and rustfmt toolchain from Nixpkgs.

# Rules

Expand Down
18 changes: 16 additions & 2 deletions toolchains/rust/rust.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""<!-- Edit the docstring in `toolchains/rust/rust.bzl` and run `bazel run //docs:update-README.md` to change this repository's `README.md`. -->
Rules for importing a Rust toolchain from Nixpkgs.
Rules for importing a Rust and rustfmt toolchain from Nixpkgs.
# Rules
Expand Down Expand Up @@ -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",
Expand All @@ -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
'';
}}
Expand All @@ -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):
Expand Down

0 comments on commit 736fd69

Please sign in to comment.