|
| 1 | +load("@apple_rules_lint//lint:defs.bzl", "get_lint_config") |
| 2 | +load( |
| 3 | + "@rules_rust//rust:defs.bzl", |
| 4 | + "rustfmt_test", |
| 5 | + _rust_binary = "rust_binary", |
| 6 | + _rust_library = "rust_library", |
| 7 | + _rust_test = "rust_test", |
| 8 | + _rust_test_suite = "rust_test_suite", |
| 9 | +) |
| 10 | + |
| 11 | +def _wrap_with_fmt_test(name, tags): |
| 12 | + config = get_lint_config("rust-rustfmt", tags) |
| 13 | + if config: |
| 14 | + rustfmt_test( |
| 15 | + name = "%s-fmt" % name, |
| 16 | + targets = [ |
| 17 | + ":%s" % name, |
| 18 | + ], |
| 19 | + tags = [ |
| 20 | + "lint", |
| 21 | + "rust-rustfmt", |
| 22 | + "rustfmt", |
| 23 | + ], |
| 24 | + ) |
| 25 | + |
| 26 | +def rust_library(name, **kwargs): |
| 27 | + _rust_library(name = name, **kwargs) |
| 28 | + _wrap_with_fmt_test(name, kwargs.get("tags", [])) |
| 29 | + |
| 30 | +def rust_binary(name, **kwargs): |
| 31 | + _rust_binary(name = name, **kwargs) |
| 32 | + _wrap_with_fmt_test(name, kwargs.get("tags", [])) |
| 33 | + |
| 34 | +def rust_test(name, **kwargs): |
| 35 | + _rust_test(name = name, **kwargs) |
| 36 | + _wrap_with_fmt_test(name, kwargs.get("tags", [])) |
| 37 | + |
| 38 | +def rust_test_suite(name, srcs = [], **kwargs): |
| 39 | + _rust_test_suite(name = name, srcs = srcs, **kwargs) |
| 40 | + for src in srcs: |
| 41 | + if not src.endswith(".rs"): |
| 42 | + fail("srcs should have `.rs` extensions") |
| 43 | + |
| 44 | + # Prefixed with `name` to allow parameterization with macros |
| 45 | + # The test name should not end with `.rs` |
| 46 | + test_name = name + "_" + src[:-3] |
| 47 | + _wrap_with_fmt_test(test_name, kwargs.get("tags", [])) |
0 commit comments