Skip to content

Commit

Permalink
Rustfmt windows fixes (#376)
Browse files Browse the repository at this point in the history
Uses the more generic process wrapper to avoid using bash
  • Loading branch information
Jalal El Mansouri committed Jul 26, 2020
1 parent 8cfa049 commit 7004ca3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
22 changes: 19 additions & 3 deletions bindgen/bindgen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,21 @@ def _rust_bindgen_impl(ctx):
)

if rustfmt_bin:
ctx.actions.run_shell(
inputs = depset([rustfmt_bin, unformatted_output]),
rustfmt_args = ctx.actions.args()
rustfmt_args.add("--stdout-file", output.path)
rustfmt_args.add("--")
rustfmt_args.add(rustfmt_bin.path)
rustfmt_args.add("--emit", "stdout")
rustfmt_args.add("--quiet")
rustfmt_args.add(unformatted_output.path)

ctx.actions.run(
executable = ctx.executable._process_wrapper,
inputs = [unformatted_output],
outputs = [output],
command = "{} --emit stdout --quiet {} > {}".format(rustfmt_bin.path, unformatted_output.path, output.path),
arguments = [rustfmt_args],
tools = [rustfmt_bin],
mnemonic = "Rustfmt",
)

rust_bindgen = rule(
Expand All @@ -143,6 +153,12 @@ rust_bindgen = rule(
"clang_flags": attr.string_list(
doc = "Flags to pass directly to the clang executable.",
),
"_process_wrapper": attr.label(
default = "@io_bazel_rules_rust//util/process_wrapper",
executable = True,
allow_single_file = True,
cfg = "exec",
),
},
outputs = {"out": "%{name}.rs"},
toolchains = [
Expand Down
25 changes: 20 additions & 5 deletions test/rustfmt/rustfmt_generator.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,37 @@ def _rustfmt_generator_impl(ctx):
rustfmt_bin = toolchain.rustfmt
output = ctx.outputs.out

ctx.actions.run_shell(
inputs = depset([rustfmt_bin, ctx.file.src]),
args = ctx.actions.args()
args.add("--stdout-file", output.path)
args.add("--")
args.add(rustfmt_bin.path)
args.add("--emit", "stdout")
args.add("--quiet")
args.add(ctx.file.src.path)

ctx.actions.run(
executable = ctx.executable._process_wrapper,
inputs = [ctx.file.src],
outputs = [output],
command = "{} --emit stdout --quiet {} > {}".format(rustfmt_bin.path, ctx.file.src.path, output.path),
arguments = [args],
tools = [rustfmt_bin],
mnemonic = "Rustfmt",
)


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,
)
),
"_process_wrapper": attr.label(
default = "@io_bazel_rules_rust//util/process_wrapper",
executable = True,
allow_single_file = True,
cfg = "exec",
),
},
outputs = {"out": "%{name}.rs"},
toolchains = [
Expand Down

0 comments on commit 7004ca3

Please sign in to comment.