Skip to content

Added label_injection to crate_universe annotations#3755

Draft
UebelAndre wants to merge 2 commits into
bazelbuild:mainfrom
UebelAndre:crate_universe_cleanup
Draft

Added label_injection to crate_universe annotations#3755
UebelAndre wants to merge 2 commits into
bazelbuild:mainfrom
UebelAndre:crate_universe_cleanup

Conversation

@UebelAndre
Copy link
Copy Markdown
Collaborator

@UebelAndre UebelAndre commented Dec 2, 2025

The new label_injection attribute is used to sanitize "apparent labels" used in annotations to "canonical labels". A common example of this is when adding external dependencies to cargo_build_script targets. E.g.

bazel_dep(name = "openssl", version = "3.3.1")

crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
crate.annotation(
    crate = "openssl-sys",
    build_script_data = [
        "@openssl//:openssl",
    ],
    build_script_env = {
        "OPENSSL_BIN": "$(execpath @openssl//:openssl)",
    },
    label_injection = {
        "@openssl//:openssl": "@openssl//:openssl",
    },
)
crate.from_cargo(
    name = "crates_index",
    cargo_lockfile = "//:Cargo.lock",
    manifests = ["//:Cargo.toml"],
)
use_repo(crate, "crates_index")

Before this change inject_repo would have been needed to get @openssl to resolve in the generated openssl-sys crate. After this, labels are remapped after resolving the canonical label based on the label_injection attribute so that even if the module above is consumed as a transitive dependency, the modules are still usable (because inject_repo is only applied to the root module).

@UebelAndre UebelAndre force-pushed the crate_universe_cleanup branch 2 times, most recently from eea7737 to 468c774 Compare December 2, 2025 23:55
@UebelAndre UebelAndre force-pushed the crate_universe_cleanup branch 2 times, most recently from 30fde71 to 468c774 Compare April 22, 2026 17:31
@UebelAndre UebelAndre force-pushed the crate_universe_cleanup branch from 468c774 to f4e986a Compare May 14, 2026 14:27
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.

1 participant