1*d4726bddSHONG Yifanload("//rust:defs.bzl", "rust_binary", "rust_clippy", "rust_library") 2*d4726bddSHONG Yifanload("//tools:tool_utils.bzl", "aspect_repository") 3*d4726bddSHONG Yifan 4*d4726bddSHONG Yifanexports_files( 5*d4726bddSHONG Yifan [ 6*d4726bddSHONG Yifan "rustfmt.toml", 7*d4726bddSHONG Yifan "rustfmt_utils.bzl", 8*d4726bddSHONG Yifan ], 9*d4726bddSHONG Yifan visibility = ["//visibility:public"], 10*d4726bddSHONG Yifan) 11*d4726bddSHONG Yifan 12*d4726bddSHONG Yifanrust_library( 13*d4726bddSHONG Yifan name = "rustfmt_lib", 14*d4726bddSHONG Yifan srcs = glob( 15*d4726bddSHONG Yifan include = ["src/**/*.rs"], 16*d4726bddSHONG Yifan exclude = [ 17*d4726bddSHONG Yifan "src/**/*main.rs", 18*d4726bddSHONG Yifan "src/bin/**", 19*d4726bddSHONG Yifan ], 20*d4726bddSHONG Yifan ), 21*d4726bddSHONG Yifan data = [ 22*d4726bddSHONG Yifan "//:rustfmt.toml", 23*d4726bddSHONG Yifan "//rust/toolchain:current_rustfmt_toolchain_for_target", 24*d4726bddSHONG Yifan ], 25*d4726bddSHONG Yifan edition = "2018", 26*d4726bddSHONG Yifan rustc_env = { 27*d4726bddSHONG Yifan "RUSTFMT": "$(rlocationpath //rust/toolchain:current_rustfmt_toolchain_for_target)", 28*d4726bddSHONG Yifan "RUSTFMT_CONFIG": "$(rlocationpath //:rustfmt.toml)", 29*d4726bddSHONG Yifan }, 30*d4726bddSHONG Yifan deps = [ 31*d4726bddSHONG Yifan "//tools/runfiles", 32*d4726bddSHONG Yifan ], 33*d4726bddSHONG Yifan) 34*d4726bddSHONG Yifan 35*d4726bddSHONG Yifan# Deprecated but present for compatibility. 36*d4726bddSHONG Yifanalias( 37*d4726bddSHONG Yifan name = "rustfmt", 38*d4726bddSHONG Yifan actual = ":target_aware_rustfmt", 39*d4726bddSHONG Yifan deprecation = "Prefer //tools/upstream_wrapper:rustfmt", 40*d4726bddSHONG Yifan visibility = ["//visibility:public"], 41*d4726bddSHONG Yifan) 42*d4726bddSHONG Yifan 43*d4726bddSHONG Yifan# This is a wrapper around the upstream rustfmt binary which is aware of targets, 44*d4726bddSHONG Yifan# and will try to do things like set the correct edition for files when formatting them based on their owning targets. 45*d4726bddSHONG Yifanrust_binary( 46*d4726bddSHONG Yifan name = "target_aware_rustfmt", 47*d4726bddSHONG Yifan srcs = [ 48*d4726bddSHONG Yifan "src/main.rs", 49*d4726bddSHONG Yifan ], 50*d4726bddSHONG Yifan data = [ 51*d4726bddSHONG Yifan "//:rustfmt.toml", 52*d4726bddSHONG Yifan ], 53*d4726bddSHONG Yifan edition = "2018", 54*d4726bddSHONG Yifan rustc_env = { 55*d4726bddSHONG Yifan "ASPECT_REPOSITORY": aspect_repository(), 56*d4726bddSHONG Yifan "RUST_DEFAULT_EDITION": "$(RUST_DEFAULT_EDITION)", 57*d4726bddSHONG Yifan }, 58*d4726bddSHONG Yifan toolchains = ["@rules_rust//rust/toolchain:current_rust_toolchain"], 59*d4726bddSHONG Yifan visibility = ["//visibility:public"], 60*d4726bddSHONG Yifan deps = [ 61*d4726bddSHONG Yifan ":rustfmt_lib", 62*d4726bddSHONG Yifan "//util/label", 63*d4726bddSHONG Yifan ], 64*d4726bddSHONG Yifan) 65*d4726bddSHONG Yifan 66*d4726bddSHONG Yifanrust_binary( 67*d4726bddSHONG Yifan name = "rustfmt_test", 68*d4726bddSHONG Yifan srcs = [ 69*d4726bddSHONG Yifan "src/bin/test_main.rs", 70*d4726bddSHONG Yifan ], 71*d4726bddSHONG Yifan edition = "2018", 72*d4726bddSHONG Yifan visibility = ["//visibility:public"], 73*d4726bddSHONG Yifan deps = [ 74*d4726bddSHONG Yifan ":rustfmt_lib", 75*d4726bddSHONG Yifan "//tools/runfiles", 76*d4726bddSHONG Yifan ], 77*d4726bddSHONG Yifan) 78*d4726bddSHONG Yifan 79*d4726bddSHONG Yifanrust_clippy( 80*d4726bddSHONG Yifan name = "rustfmt_clippy", 81*d4726bddSHONG Yifan testonly = True, 82*d4726bddSHONG Yifan visibility = ["//visibility:private"], 83*d4726bddSHONG Yifan deps = [ 84*d4726bddSHONG Yifan ":target_aware_rustfmt", 85*d4726bddSHONG Yifan ], 86*d4726bddSHONG Yifan) 87*d4726bddSHONG Yifan 88*d4726bddSHONG Yifan# Deprecated but present for compatibility. 89*d4726bddSHONG Yifanalias( 90*d4726bddSHONG Yifan name = "upstream_rustfmt", 91*d4726bddSHONG Yifan actual = "//tools/upstream_wrapper:rustfmt", 92*d4726bddSHONG Yifan deprecation = "Prefer //tools/upstream_wrapper:rustfmt", 93*d4726bddSHONG Yifan visibility = ["//visibility:public"], 94*d4726bddSHONG Yifan) 95