-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Incorrect documentation for default-features in workspace dependencies #14841
Comments
When building only a single crate in the workspace to run its test, we often recompile a lot of other, unrelated crates. Whenever cargo has a different set of crate features, it needs to recompile. By moving some features (non-exhaustive for now) to the workspace level, we always activate them an avoid recompiling. The cargo docs mismatch the behavior of cargo around default-deps, so I filed that upstream: rust-lang/cargo#14841 Reference script: ```python import tomllib from collections import defaultdict from pathlib import Path uv = Path("/home/konsti/projects/uv") skip_list = ["uv-trampoline", "uv-dev", "uv-performance-flate2-backend", "uv-performance-memory-allocator"] root_feature_map = defaultdict(set) root_default_features = defaultdict(bool) cargo_toml = tomllib.loads(uv.joinpath("Cargo.toml").read_text()) for dep, declaration in cargo_toml["workspace"]["dependencies"].items(): root_default_features[dep] = root_default_features[dep] or declaration.get("default-features", True) root_feature_map[dep].update(declaration.get("features", [])) feature_map = defaultdict(set) default_features = defaultdict(bool) for crate in uv.joinpath("crates").iterdir(): if crate.name in skip_list: continue if not crate.joinpath("Cargo.toml").is_file(): continue cargo_toml = tomllib.loads(crate.joinpath("Cargo.toml").read_text()) for dep, declaration in cargo_toml.get("dependencies", {}).items(): # If any item uses default features, they are used everywhere default_features[dep] = default_features[dep] or declaration.get("default-features", True) feature_map[dep].update(declaration.get("features", [])) for dep, features in sorted(feature_map.items()): features = features - root_feature_map.get(dep, set()) if not features and default_features[dep] == root_default_features[dep]: continue print(dep, default_features[dep], sorted(features)) ```
Documenting is hard ;( Any idea how to add a succinct explanation to the doc? |
Something like "A workspace member will inherit |
When building only a single crate in the workspace to run its tests, we often recompile a lot of other, unrelated crates. Whenever cargo has a different set of crate features, it needs to recompile. By moving some features (non-exhaustive for now) to the workspace level, we always activate them an avoid recompiling. The cargo docs mismatch the behavior of cargo around default-deps, so I filed that upstream and left most `default-features` mismatches: rust-lang/cargo#14841. Reference script: ```python import tomllib from collections import defaultdict from pathlib import Path uv = Path("/home/konsti/projects/uv") skip_list = ["uv-trampoline", "uv-dev", "uv-performance-flate2-backend", "uv-performance-memory-allocator"] root_feature_map = defaultdict(set) root_default_features = defaultdict(bool) cargo_toml = tomllib.loads(uv.joinpath("Cargo.toml").read_text()) for dep, declaration in cargo_toml["workspace"]["dependencies"].items(): root_default_features[dep] = root_default_features[dep] or declaration.get("default-features", True) root_feature_map[dep].update(declaration.get("features", [])) feature_map = defaultdict(set) default_features = defaultdict(bool) for crate in uv.joinpath("crates").iterdir(): if crate.name in skip_list: continue if not crate.joinpath("Cargo.toml").is_file(): continue cargo_toml = tomllib.loads(crate.joinpath("Cargo.toml").read_text()) for dep, declaration in cargo_toml.get("dependencies", {}).items(): # If any item uses default features, they are used everywhere default_features[dep] = default_features[dep] or declaration.get("default-features", True) feature_map[dep].update(declaration.get("features", [])) for dep, features in sorted(feature_map.items()): features = features - root_feature_map.get(dep, set()) if not features and default_features[dep] == root_default_features[dep]: continue print(dep, default_features[dep], sorted(features)) ```
The cargo docs on workspace packages say (https://doc.rust-lang.org/nightly/cargo/reference/specifying-dependencies.html#inheriting-a-dependency-from-a-workspace):
Trying this out however, cargo does not seem to mind the
default-features
key:It's unfortunately not clear to me from the docs if
default-features
are inherited.The text was updated successfully, but these errors were encountered: