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

Fix crate_universe when using bzlmod #2485

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion crate_universe/extension.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ def _generate_hub_and_spokes(module_ctx, cargo_bazel, cfg, annotations):
cargo_lockfile = module_ctx.path(cfg.cargo_lockfile)
tag_path = module_ctx.path(cfg.name)

# Get the prefix of the canonical repo name that will be used for crates
canonical_label = Label(":dummy_target")
idx = str(canonical_label).find("//")
canonical_repository = str(canonical_label)[:idx]

# The "~crate~" portion comes from the definition of the module_extension (currently at the bottom of this file)
canonical_crate_label_metatemplate = "{}~crate~{{repository}}__{{name}}-{{version}}//:{{target}}"
rendering_config = json.decode(render_config(
regen_command = "Run 'cargo update [--workspace]'",
crate_label_template = "@@rules_rust~override~crate~{repository}__{name}-{version}//:{target}",
crate_label_template = canonical_crate_label_metatemplate.format(canonical_repository),
))
config_file = tag_path.get_child("config.json")
module_ctx.file(
Expand Down
5 changes: 3 additions & 2 deletions crate_universe/private/crates_vendor.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -203,21 +203,22 @@ def generate_config_file(
if render_config == None:
render_config = default_render_config

original_crate_label_template = render_config["crate_label_template"]
if mode == "local":
build_file_base_template = "@{}//{}/{{name}}-{{version}}:BUILD.bazel"
crate_label_template = "//{}/{{name}}-{{version}}:{{target}}".format(
output_pkg,
)
else:
build_file_base_template = "@{}//{}:BUILD.{{name}}-{{version}}.bazel"
crate_label_template = render_config["crate_label_template"]
crate_label_template = original_crate_label_template

updates = {
"build_file_template": build_file_base_template.format(
workspace_name,
output_pkg,
),
"crate_label_template": crate_label_template,
"crate_label_template": crate_label_template if crate_label_template else original_crate_label_template,
"crates_module_template": "@{}//{}:{{file}}".format(
workspace_name,
output_pkg,
Expand Down
Loading