rules_rust icon indicating copy to clipboard operation
rules_rust copied to clipboard

Crate Universe: enable all features when generating metadata

Open golovasteek opened this issue 2 years ago • 2 comments

Closes https://github.com/bazelbuild/rules_rust/issues/1939

Objective of this change is to "render" optional dependencies of workspace members. And at the same time do not include them in the all_crate_deps. Optional dependencies should be handled in the BUILD.bazel file by maintainer, in case they are required.

Design notes:

  • The optional dependencies should be resolved recursively, and we need to use cargo for it. Before this change resolution was made with all features disabled, and all the optional dependencies were not resolved.
  • In this change we configure cargo to enable all possible features, and resolve all dependencies.
  • The step above alone, will solve the problem of optional dependencies, but would add all optional dependencies unconditionally to the all_crate_deps()
  • In order to exclude the optional deps from crate deps, we need to filter them out from dependencies list. We do filtering of optional only for workspace members.
  • we need to to provide optional dependencies as a "workspace_members_deps", to ensure that appropriate alias will be created.

Caveats:

  • in the metadata.json resolved dependency name coverted from "hyphen-notation" to "snake_case_notation", so I had to normalize names.

Open topics:

  • Would be nice to test end-to-end: given a Cargo.toml,
    • ensure that dependencies are rendered, fetched, and aliases are created.
    • ensure that all_crate_deps do not include optional deps.
  • Unit test maybe?
    • given Cargo.toml ensure that metadata.json has resolved optinal dependencies
    • given metadata.json, ensure that defs.bzl and BUILD.bazel are generated properly.
  • CI tests are failing, but not sure how failed test related to my change.

golovasteek avatar Apr 29 '23 16:04 golovasteek

Thanks for working on this! Got a question for you 😄

UebelAndre avatar May 03 '23 15:05 UebelAndre

Apologies for resurrecting this, but is this worth working on, or would starting over be better (given the age of the PR)

rossdylan avatar May 13 '25 17:05 rossdylan