Skip to content

Commit 76abd40

Browse files
authored
Add support for package_alias in crate.spec (bzlmod) (#3743)
Closes #3742 This makes using different versions of the same crate easier.
1 parent f5b7135 commit 76abd40

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

crate_universe/extensions.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ def _crate_impl(module_ctx):
11611161
manifests = {str(module_ctx.path(m)): str(m) for m in cfg.manifests}
11621162

11631163
packages = {
1164-
p.package: _package_to_json(p)
1164+
p.package_alias or p.package: _package_to_json(p)
11651165
for p in common_specs + repo_specific_specs.get(cfg.name, [])
11661166
}
11671167

@@ -1431,6 +1431,9 @@ _spec = tag_class(
14311431
doc = "The explicit name of the package.",
14321432
mandatory = True,
14331433
),
1434+
"package_alias": attr.string(
1435+
doc = "Alias for the package.",
1436+
),
14341437
"path": attr.string(
14351438
doc = "The local path of the remote crate. Cannot be used with `version` or `git`.",
14361439
),

examples/crate_universe/MODULE.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,13 @@ no_cargo.spec(
515515
repositories = ["no_cargo"],
516516
version = "0.4",
517517
)
518+
no_cargo.spec(
519+
features = ["util"],
520+
package = "tower",
521+
package_alias = "tower_new", # used in package_alias test
522+
repositories = ["no_cargo"],
523+
version = "0.5.3",
524+
)
518525
no_cargo.spec(
519526
features = ["trace"],
520527
package = "tower-http",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
alias(
2+
name = "tower-new",
3+
actual = "@no_cargo//:tower_new", # ensures the package_alias works
4+
)

0 commit comments

Comments
 (0)