forked from bazelbuild/rules_rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull/expose rustfmt binaries (bazelbuild#291)
* Fetch and expose the rustfmt binary Pulls in the version of rustfmt that is shipped with Rust 1.39.0. Distribution path/version found in official release channel TOML. See http://static.rust-lang.org/dist/channel-rust-1.39.0.toml, and rust-lang/rust-forge#215 for more information on this. Relates to bazelbuild#87. * Set LC_ALL in fetch_shas.sh The order of `sort`'s output depends on this variable, and different users may have it set differently. * Add rustfmt hashes to known_shas rustfmt is versioned independently of the other Rust tools, which necessitates keeping track of its version separately. Binaries are also not provided for FreeBSD, and so a separate targets list is also used. * Expose rustfmt binary via the Rust toolchain * Add test that rustfmt binary works
- Loading branch information
1 parent
d97f996
commit fe50d3b
Showing
11 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
load("@io_bazel_rules_rust//test/rustfmt:rustfmt_generator.bzl", "rustfmt_generator") | ||
|
||
rustfmt_generator( | ||
name = "formatted", | ||
src = ":unformatted.rs", | ||
) | ||
|
||
sh_test( | ||
name = "rustfmt_test", | ||
size = "small", | ||
data = [ | ||
":formatted.rs", | ||
":unformatted.rs", | ||
], | ||
srcs = [":rustfmt_test.sh"], | ||
deps = ["@bazel_tools//tools/bash/runfiles"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
load("@io_bazel_rules_rust//rust:private/utils.bzl", "find_toolchain") | ||
|
||
def _rustfmt_generator_impl(ctx): | ||
toolchain = find_toolchain(ctx) | ||
rustfmt_bin = toolchain.rustfmt | ||
output = ctx.outputs.out | ||
|
||
ctx.actions.run_shell( | ||
inputs = depset([rustfmt_bin, ctx.file.src]), | ||
outputs = [output], | ||
command = "{} --emit stdout --quiet {} > {}".format(rustfmt_bin.path, ctx.file.src.path, output.path), | ||
tools = [rustfmt_bin], | ||
) | ||
|
||
|
||
rustfmt_generator = rule( | ||
_rustfmt_generator_impl, | ||
doc = "Given an unformatted Rust source file, output the file after being run through rustfmt.", | ||
attrs = { | ||
"src": attr.label( | ||
doc = "The file to be formatted.", | ||
allow_single_file = True, | ||
) | ||
}, | ||
outputs = {"out": "%{name}.rs"}, | ||
toolchains = [ | ||
"@io_bazel_rules_rust//rust:toolchain", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
set -euxo pipefail | ||
|
||
formatted="$(rlocation io_bazel_rules_rust/test/rustfmt/formatted.rs)" | ||
unformatted="$(rlocation io_bazel_rules_rust/test/rustfmt/unformatted.rs)" | ||
|
||
# Ensure that the file was formatted | ||
! diff "$unformatted" "$formatted" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fn example(){println!("test");} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
x86_64-unknown-linux-gnu | ||
x86_64-apple-darwin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2019-11-07/rustfmt-1.4.8 |