rules_rust
rules_rust copied to clipboard
crate_universe: Generate shallow_since
I'd like to propose the crate_universe generator include shallow_since
within the lock file. As it stands, transitive Cargo dependencies from git don't include shallow_since
which leads to lots of log spam like:
(16:06:54) DEBUG: Rule 'crate_index__<redacted>-0.1.0' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1643038190 +0000"
(16:06:54) DEBUG: Repository crate_index__<redacted>-0.1.0 instantiated at:
/Users/thomas/code/<redacted>/WORKSPACE:198:19: in <toplevel>
/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/crate_index/defs.bzl:1321:10: in crate_repositories
/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/utils.bzl:233:18: in maybe
Repository rule new_git_repository defined at:
/private/var/tmp/_bazel_thomas/796dd52d4d981101108548a9446ddca6/external/bazel_tools/tools/build_defs/repo/git.bzl:186:37: in <toplevel>
Consequently, the crates_repository
rule then becomes filled with needless annotations for shallow_since
.
+1, sounds great! Would gladly review a PR :)
This is already an annotation you can add: https://bazelbuild.github.io/rules_rust/crate_universe.html#crate.annotation-shallow_since
Does that help?
This is already an annotation you can add: https://bazelbuild.github.io/rules_rust/crate_universe.html#crate.annotation-shallow_since
Does that help?
Sorry, what I'm suggesting avoids the need for this in most cases. We're in a situation where we have tons of annotations just for shallow_since
. See:
crates_repository(
name = "crate_index",
annotations = {
"crate-1": [crate.annotation(
shallow_since = "1643039868 +0000",
)],
"crate-2": [crate.annotation(
shallow_since = "1643038190 +0000",
)],
"crate-3": [crate.annotation(
shallow_since = "1644511348 +0000",
)],
# ... and about 10 more like this
},
# ...
)
It would be nice for the generator to include this in the lock file automatically.
Ah yeah, that sounds like it'd be nice. If you'd be willing to open a PR I'm sure @illicitonion or I would be happy to review it 😄
I took a quick look today and it seems like this might be a little trickier than first thought.
The Cargo.Bazel.Lock
file is generated from a Cargo.lock
file, which does not include this information.
Git packages would need to be fetched by the generator itself to get the correct shallow_since
value.
Git packages would need to be fetched by the generator itself to get the correct
shallow_since
value.
I believe that cargo already fetches those repositories to .cargo/git/checkouts
in order to fetch that metadata, so it should already be on disk, and just be a matter of locating it...
https://github.com/rust-lang/cargo/blob/master/src/cargo/sources/git/source.rs is the code in cargo which creates and manages git clones, which should show you how to reverse-engineer the paths.
When isolated=True
we override $CARGO_HOME
, and when not, we'll use default values, so that should give the base directory to be looking up from.