diff --git a/crate_universe/private/crates_vendor.bzl b/crate_universe/private/crates_vendor.bzl index 27cd5fff86..98eee26206 100644 --- a/crate_universe/private/crates_vendor.bzl +++ b/crate_universe/private/crates_vendor.bzl @@ -666,10 +666,15 @@ call against the generated workspace. The following table describes how to contr def _crates_vendor_remote_repository_impl(repository_ctx): build_file = repository_ctx.path(repository_ctx.attr.build_file) - defs_module = repository_ctx.path(repository_ctx.attr.defs_module) - repository_ctx.file("BUILD.bazel", repository_ctx.read(build_file)) + + defs_module = repository_ctx.path(repository_ctx.attr.defs_module) repository_ctx.file("defs.bzl", repository_ctx.read(defs_module)) + + if repository_ctx.attr.alias_rules_module: + alias_rules_module = repository_ctx.path(repository_ctx.attr.alias_rules_module) + repository_ctx.file("alias_rules.bzl", repository_ctx.read(alias_rules_module)) + repository_ctx.file("crates.bzl", "") repository_ctx.file("WORKSPACE.bazel", """workspace(name = "{}")""".format( repository_ctx.name, @@ -679,6 +684,12 @@ crates_vendor_remote_repository = repository_rule( doc = "Creates a repository paired with `crates_vendor` targets using the `remote` vendor mode.", implementation = _crates_vendor_remote_repository_impl, attrs = { + "alias_rules_module": attr.label( + doc = "The `alias_rules.bzl` file to use in the repository", + # Not mandatory because making it mandatory would break all current vendors, + # making it very hard to re-vendor without manually changing the files. + mandatory = False, + ), "build_file": attr.label( doc = "The BUILD file to use for the root package", mandatory = True, diff --git a/crate_universe/src/config.rs b/crate_universe/src/config.rs index 5f9b14822e..a1592673a1 100644 --- a/crate_universe/src/config.rs +++ b/crate_universe/src/config.rs @@ -218,7 +218,7 @@ impl AliasRule { match self { AliasRule::Alias => None, AliasRule::Dbg | AliasRule::Fastbuild | AliasRule::Opt => { - Some("//:alias_rules.bzl".to_owned()) + Some(":alias_rules.bzl".to_owned()) } AliasRule::Custom { bzl, .. } => Some(bzl.clone()), } diff --git a/crate_universe/src/rendering/templates/vendor_module.j2 b/crate_universe/src/rendering/templates/vendor_module.j2 index 1205b4dd72..63668cdf46 100644 --- a/crate_universe/src/rendering/templates/vendor_module.j2 +++ b/crate_universe/src/rendering/templates/vendor_module.j2 @@ -23,6 +23,7 @@ def crate_repositories(): maybe( crates_vendor_remote_repository, name = "{{ repository_name }}", + alias_rules_module = Label("{{ crates_module_label(file="alias_rules.bzl") }}"), build_file = Label("{{ crates_module_label(file="BUILD.bazel") }}"), defs_module = Label("{{ crates_module_label(file="defs.bzl") }}"), )