Open tetsuok opened 2 years ago
Note that to use
hashbrown
0.12.3 (latest as of writing) incrate_universe
rule, theahash
crate 0.7.6 needs to be patched otherwise build fails with the following message:ERROR: Traceback (most recent call last): File "/home/t/.cache/bazel/_bazel_t/4ba20afb3d7a89a1d3a105467b78f4a5/external/crate_index__ahash-0.7.6/BUILD.bazel", line 51, column 10, in <toplevel> ): [ Error: dictionary expression has duplicate key: ("@rules_rust//rust/platform:x86_64-unknown-linux-gnu",) ERROR: /home/t/.cache/bazel/_bazel_t/4ba20afb3d7a89a1d3a105467b78f4a5/external/crate_index__hashbrown-0.12.3/BUILD.bazel:34:13: no such target '@crate_index__ahash-0.7.6//:ahash': target 'ahash' not declared in package '' defined by /home/t/.cache/bazel/_bazel_t/4ba20afb3d7a89a1d3a105467b78f4a5/external/crate_index__ahash-0.7.6/BUILD.bazel and referenced by '@crate_index__hashbrown-0.12.3//:hashbrown' ERROR: Analysis of target '//:hello' failed; build aborted: INFO: Elapsed time: 1.936s INFO: 0 processes. FAILED: Build did NOT complete successfully (17 packages loaded, 157 targets configured)
This is the same issue as https://github.com/bazelbuild/rules_rust/issues/1236. I would advise not setting that value and letting Bazel be aware of other targets until this kind of filtering is supported (https://github.com/bazelbuild/rules_rust/issues/1417).
crates_repository( name = "crate_index", annotations = { "ahash": [crate.annotation( patch_args = ["-p1"], patches = ["@//:ahash.patch"], version = "=0.7.6", )], }, cargo_lockfile = "//:Cargo.Bazel.lock", lockfile = "//:cargo-bazel-lock.json", packages = { "hashbrown": crate.spec( version = "0.12.3", ), }, render_config = render_config( default_package_name = "", ), supported_platform_triples = ["x86_64-unknown-linux-gnu"], )
Could you try changing "@//:ahash.patch"
to expand the repository name of your workspace?
Thanks, but why does applying patches in cargo.annotation fail? I thought it should work in the same way as http_archive.
Thanks, but why does applying patches in cargo.annotation fail? I thought it should work in the same way as http_archive.
Ah, I see, the thing you're trying to do won't work. By the time an http_archive
is generated for the crate, the dependency graph has already been resolved. What you'd want to do instead is somehow set [patch.crates-io] or something in the manifest crates_repository
uses to query the dependency graph.
@UebelAndre Thanks for the suggestion. I'm now wondering why crate.annotation rule supports the 'patches', 'patch_args', and 'patch_tool' attributes. Cargo Universe is fantastic to enable "Cargo free" set up. It would be great to clarify the intended use cases of the attributes.
crates_repository( name = "crate_index", annotations = { "ahash": [crate.annotation( patch_args = ["-p1"], patches = ["@//:ahash.patch"], version = "=0.7.6", )], }, cargo_lockfile = "//:Cargo.Bazel.lock", lockfile = "//:cargo-bazel-lock.json", packages = { "hashbrown": crate.spec( version = "0.12.3", ), }, render_config = render_config( default_package_name = "", ), supported_platform_triples = ["x86_64-unknown-linux-gnu"], )
Could you try changing
"@//:ahash.patch"
to expand the repository name of your workspace?
Sorry, I missed your prompt response. I just added the workspace name (commit https://github.com/tetsuok/rules_rust_cargo_universe_hashbrown/commit/719a5d0cff1daf7b8ab01a7d3e576bfff60dde6a), but applying the patch still fails, unfortunately.
@UebelAndre Thanks for the suggestion. I'm now wondering why crate.annotation rule supports the 'patches', 'patch_args', and 'patch_tool' attributes. Cargo Universe is fantastic to enable "Cargo free" set up. It would be great to clarify the intended use cases of the attributes.
Rust has it's own build system and public registry where developers can publish versions of their code using said build system. 99.9% of the available libraries you could use in a project are built and tested using Cargo. The way crate_universe
works is by relying on Cargo to go describe dependency graphs and where to download crates from so that it can generate some repository rules and BUILD files to represent the graph. Cargo still plays a part here but ideally users won't have to think about that if they don't want to.
With that said, the patches functionality of crates.annotation
is specifically for the generated http_archive
/git_repository
rules so that developers can modify code (not dependency graphs) in case the dependency (originally built and tested with Cargo) does not work with Bazel or your uses.
The fix here is likely to add a patch
section to crates_repository
which would allow you to pass the same info to Bazel (and ultimately Cargo) that you'd be able to in a standard Cargo.toml
file.
Alternatively, what you could do if you needed this working today, was to make a fork of the dependency you want and change, make a commit with the patches, and pull the project in via git.
Does this address any confusion you had and help get you unblocked?
Yes, thank you for the detailed explanation! I think I understand your point.
crate.annotation rule supports
patches
andpatch_args
attributes, but applying patch failed. See error message below. It would be great if there is something wrong with the configuration (see below).Output:
Below is a set of related files on this issues. For the full contents, see https://github.com/tetsuok/rules_rust_cargo_universe_hashbrown.
WORKSPACE
:ahash.patch
:BUILD.bazel
:hello.rs
:Note that to use
hashbrown
0.12.3 (latest as of writing) incrate_universe
rule, theahash
crate 0.7.6 needs to be patched otherwise build fails with the following message:Below is a generated
crate_index__ahash-0.7.6/BUILD.bazel
. Maybeahash
crate 0.8.0 doesn't have issue, buthashbrown
0.12.3 crate specifiesahash
0.7.0 as a dependency in Cargo.tomlcrate_index__ahash-0.7.6/BUILD.bazel
: