Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 5, 2023

Conversation

dtolnay
Copy link
Contributor

@dtolnay dtolnay commented Jan 4, 2023

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

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

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

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:

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:

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.

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

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

@illicitonion illicitonion merged commit a31490d into bazelbuild:main Jan 5, 2023
@dtolnay dtolnay deleted the loadoneline branch January 5, 2023 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants