Make loads from @rules_rust//rust:defs.bzl come out on one line (#1753)

At first I was confused why some of the generated files were coming out with loads formatted like this:

https://github.com/bazelbuild/rules_rust/blob/4ef3d4aaa27569616d9d085b0b01b4f155c09675/crate_universe/3rdparty/crates/BUILD.anyhow-1.0.68.bazel#L9-L13

Surely this should be as follows? The wrapped line is even shorter than the unwrapped line.

```bzl
load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
load("@rules_rust//rust:defs.bzl", "rust_library")
```

It turned out to be because crate_universe unconditionally generates _all_ the loads that might be needed:

```bzl
load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
load(
    "@rules_rust//rust:defs.bzl",
    "rust_library",
    "rust_binary",
    "rust_proc_macro",
)
```

and then Buildifier deletes any that are unused, but without rewrapping any lines:

```bzl
load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
load(
    "@rules_rust//rust:defs.bzl",
    "rust_library",
)
```

This PR tweaks crate_universe to generate only loads that are used, so that we retain control over how they are wrapped. After this PR, single loads get put on one line while multiple loads get put on multiple lines.

https://github.com/bazelbuild/rules_rust/blob/e987f2041df8abed1897ab3684a7af3158adee34/crate_universe/3rdparty/crates/BUILD.anyhow-1.0.68.bazel#L9-L10

https://github.com/bazelbuild/rules_rust/blob/e987f2041df8abed1897ab3684a7af3158adee34/bindgen/3rdparty/crates/BUILD.bindgen-0.60.1.bazel#L9-L14
296 files changed
tree: b5d71136b9c86a661ef6ccc96ccb5d103acec265
  1. .bazelci/
  2. .github/
  3. bindgen/
  4. cargo/
  5. crate_universe/
  6. docs/
  7. examples/
  8. proto/
  9. rust/
  10. test/
  11. tools/
  12. util/
  13. wasm_bindgen/
  14. .bazelignore
  15. .bazelrc
  16. .clang-format
  17. .gitattributes
  18. .gitignore
  19. ARCHITECTURE.md
  20. AUTHORS
  21. BUILD.bazel
  22. CODEOWNERS
  23. COMPATIBILITY.md
  24. CONTRIBUTING.md
  25. CONTRIBUTORS
  26. LICENSE.txt
  27. README.md
  28. version.bzl
  29. WORKSPACE.bazel
README.md

Rust Rules

  • Postsubmit Build status

Overview

This repository provides rules for building Rust projects with Bazel.

Community

General discussions and announcements take place in the GitHub Discussions, but there are additional places where community members gather to discuss rules_rust.

Documentation

Please refer to the full documentation.