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

Mark the bzlmod extension reproducible as appropriate #2575

Merged
merged 1 commit into from
Mar 27, 2024
Merged
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
4 changes: 4 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ module(
version = "0.40.0",
)

bazel_dep(
name = "bazel_features",
version = "1.9.1",
)
bazel_dep(
name = "bazel_skylib",
version = "1.5.0",
Expand Down
14 changes: 14 additions & 0 deletions crate_universe/extension.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Module extension for generating third-party crates for use in bazel."""

load("@bazel_features//:features.bzl", "bazel_features")
load("@bazel_skylib//lib:structs.bzl", "structs")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
Expand Down Expand Up @@ -275,6 +276,8 @@ def _crate_impl(module_ctx):
cargo_bazel = get_cargo_bazel_runner(module_ctx, cargo_bazel_output)

all_repos = []
reproducible = True

for mod in module_ctx.modules:
module_annotations = {}
repo_specific_annotations = {}
Expand Down Expand Up @@ -327,6 +330,11 @@ def _crate_impl(module_ctx):
_generate_hub_and_spokes(module_ctx, cargo_bazel, cfg, annotations, cargo_lockfile = cargo_lockfile, manifests = manifests)

for cfg in mod.tags.from_specs:
# We don't have a Cargo.lock so the resolution can change.
# We could maybe make this reproducible by using `-minimal-version` during resolution.
# See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#minimal-versions
reproducible = False

annotations = _annotations_for_repo(
module_annotations,
repo_specific_annotations.get(cfg.name),
Expand All @@ -339,6 +347,12 @@ def _crate_impl(module_ctx):
if repo not in local_repos:
fail("Annotation specified for repo %s, but the module defined repositories %s" % (repo, local_repos))

metadata_kwargs = {}
if bazel_features.external_deps.extension_metadata_has_reproducible:
metadata_kwargs["reproducible"] = reproducible

return module_ctx.extension_metadata(**metadata_kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on your Bazel requirement, it may be safer to test for extension_metadata via hasattr.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dzbarsky thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe extension_metadata is present in 6.2.0+ and we support a min of 6.3.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fmeum was your comment suggesting that we could eliminate the new dependency on on bazel_features by using hasattr?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot. The 'reproducible' argument is newer than 'extension_metadata'


_from_cargo = tag_class(
doc = "Generates a repo @crates from a Cargo.toml / Cargo.lock pair",
attrs = dict(
Expand Down
Loading