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

Use crate_name to also match crate_root. #2824

Merged
merged 1 commit into from
Sep 3, 2024

Conversation

UebelAndre
Copy link
Collaborator

This allows targets to have special names that do not match their sources while still ensuring a root is found. I've encountered this when creating macros where I have a Rust target that is a side-effect and not the named target itself. E.g.

load("@rules_rust//rust:defs.bzl", "rust_binary")
load("//control/private:control.bzl", _control_binary = "control_binary")

def control_binary(
    name, 
    # ...
    **kwargs):

    rust_binary(
        name = name + "_bin",
        # ...
        **kwargs
    )

    _control_binary(
        name = name,
        bin = name + "_bin",
        # ...
        **kwargs
    )

Being able to specify crate_name will both ensure the binary is compiled with a cleaner name for the runtime and be able to do the nominal crate_root matching. The diff after this PR achieves the desired behavior.

--- before/defs.bzl	2024-08-31 12:41:24
+++ after/defs.bzl	2024-08-31 12:42:09
@@ -8,6 +8,7 @@

     rust_binary(
         name = name + "_bin",
+        crate_name = name,
         # ...
         **kwargs
     )

@UebelAndre UebelAndre added this pull request to the merge queue Sep 3, 2024
Merged via the queue into bazelbuild:main with commit 73b1594 Sep 3, 2024
3 checks passed
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.

2 participants