-
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
Cargo 1.78+ incorrectly drops FeatureValue
s that match the implicit feature
#14321
Comments
I found this related issue after all: #10125 However it is described as a "entirely reasonable human error". I would classify this as a Cargo bug / breaking change, given that the |
Was hoping this was reproducible with $ cargo +1.76 metadata | jq '.packages[0].features'
warning: please specify `--format-version` flag explicitly to avoid compatibility problems
{
"tonic_010": [
"dep:tonic_010"
]
}
$ cargo +1.77 metadata | jq '.packages[0].features'
warning: please specify `--format-version` flag explicitly to avoid compatibility problems
{
"tonic_010": [
"dep:tonic_010"
]
} |
On
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
name = "hs-clarity-resource-locator-rust"
version = "0.1.0"
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
readme = false
[[bin]]
name = "hs-clarity-resource-locator-rust"
path = "src/main.rs"
[dependencies.tonic_010]
version = "0.10"
optional = true
package = "tonic"
[features]
tonic_010 = ["dep:tonic_010"] The features: {
"tonic_010": [
Dep {
dep_name: "tonic_010",
},
],
}, But what we send to the registry is bad: [src/cargo/ops/registry/publish.rs:473:5] &new_crate = NewCrate {
name: "hs-clarity-resource-locator-rust",
vers: "0.1.0",
deps: [
NewCrateDependency {
optional: true,
default_features: true,
name: "tonic",
features: [],
version_req: "^0.10",
target: None,
kind: "normal",
registry: None,
explicit_name_in_toml: Some(
"tonic_010",
),
artifact: None,
bindep_target: None,
lib: false,
},
],
features: {
"tonic_010": [],
},
authors: [],
description: None,
documentation: None,
homepage: None,
readme: None,
readme_file: None,
keywords: [],
categories: [],
license: None,
license_file: None,
repository: None,
badges: {},
links: None,
rust_version: None,
} @NiklasRosenstein are you using a custom registry? crates.io re-generates the summary, ignoring |
@epage Yep, can confirm this is happening for a third-party registry! |
#13518 is the only significant change I've seen in this area recently |
@NiklasRosenstein May be a good idea to try a |
Alternatively may be easy to write a test case for https://github.com/rust-lang/cargo/blob/master/tests/testsuite/publish.rs and run |
atm I am updating the tests to cover this and will then cherry pick to just before #13518. |
Confirmed that it is that PR. It is also specific to renaming. |
Posted a fix at #14325. |
fix(publish): Don't strip non-dev features ### What does this PR try to resolve? First, we added support for stripping of local-only dev-dependencies. This was dual-implemented for `Cargo.toml` and `Summary`. This left off stripping of `dep/feature` that reference dev-dependencies (enabling features within dev-dependencies). When we fixed this, we again dual-implemented it. The `Cargo.toml` version was correct but the `Summary` version was instead stripping too many features, particularly features that reference renamed dependencies. We didn't have tests for this case and it wasn't caught earlier because crates.io re-generates the `Summary` from `Cargo.toml`, ignoring what we post. That makes this only show up with custom registries that trust what Cargo posts. Rather than fixing the `Summary` generation, I remove the dual-implementation and instead generate the `Summary` from the published `Cargo.toml`. Fixes #14321 ### How should we test and review this PR? ### Additional information Unfortunately, we don't have access directly to the packaged `Cargo.toml`. It could be passed around and I originally did so, hoping to remove use of the local `Package`. However, the local `Package` is needed for things like reading the `README`. So I scaled back and isolate the change to only what needs it. This also makes it easier for `prepare_transmit` callers. Fully open to someone exploring removing this extra `prepare_for_publish` in the future.
First, we added support for stripping of local-only dev-dependencies. This was dual-implemented for `Cargo.toml` and `Summary`. This left off stripping of `dep/feature` that reference dev-dependencies (enabling features within dev-dependencies). When we fixed this, we again dual-implemented it. The `Cargo.toml` version was correct but the `Summary` version was instead stripping too many features, particularly features that reference renamed dependencies. We didn't have tests for this case and it wasn't caught earlier because crates.io re-generates the `Summary` from `Cargo.toml`, ignoring what we post. That makes this only show up with custom registries that trust what Cargo posts. Rather than fixing the `Summary` generation, I remove the dual-implementation and instead generate the `Summary` from the published `Cargo.toml`. Unfortunately, we don't have access directly to the packaged `Cargo.toml`. It could be passed around and I originally did so, hoping to remove use of the local `Package`. However, the local `Package` is needed for things like reading the `README`. So I scaled back and isolate the change to only what needs it. This also makes it easier for `prepare_transmit` callers. Fully open to someone exploring removing this extra `prepare_for_publish` in the future. Fixes rust-lang#14321
First, we added support for stripping of local-only dev-dependencies. This was dual-implemented for `Cargo.toml` and `Summary`. This left off stripping of `dep/feature` that reference dev-dependencies (enabling features within dev-dependencies). When we fixed this, we again dual-implemented it. The `Cargo.toml` version was correct but the `Summary` version was instead stripping too many features, particularly features that reference renamed dependencies. We didn't have tests for this case and it wasn't caught earlier because crates.io re-generates the `Summary` from `Cargo.toml`, ignoring what we post. That makes this only show up with custom registries that trust what Cargo posts. Rather than fixing the `Summary` generation, I remove the dual-implementation and instead generate the `Summary` from the published `Cargo.toml`. Unfortunately, we don't have access directly to the packaged `Cargo.toml`. It could be passed around and I originally did so, hoping to remove use of the local `Package`. However, the local `Package` is needed for things like reading the `README`. So I scaled back and isolate the change to only what needs it. This also makes it easier for `prepare_transmit` callers. Fully open to someone exploring removing this extra `prepare_for_publish` in the future. Fixes rust-lang#14321
Hey @epage, thank you for fixing this. 🚀 It's going to land in Cargo 1.81, yes? Speaking to how Cargo handles caches for crate indexes in general, I wonder if there is something that should be done with regards to error reporting and the caching behaviour. As it stands today,
If I may suggest (maybe naively); Cargo could
What do you think? |
We haven't done a beta-backport yet. Will do that in this week. |
This PR was against 1.82 but i have a cherry-pick to 1.81 ready to go when i get onto better internet. I believe your first case is being tracked in #10623. The second case shouldn't be a problem and I'd need reproduction steps. |
First, we added support for stripping of local-only dev-dependencies. This was dual-implemented for `Cargo.toml` and `Summary`. This left off stripping of `dep/feature` that reference dev-dependencies (enabling features within dev-dependencies). When we fixed this, we again dual-implemented it. The `Cargo.toml` version was correct but the `Summary` version was instead stripping too many features, particularly features that reference renamed dependencies. We didn't have tests for this case and it wasn't caught earlier because crates.io re-generates the `Summary` from `Cargo.toml`, ignoring what we post. That makes this only show up with custom registries that trust what Cargo posts. Rather than fixing the `Summary` generation, I remove the dual-implementation and instead generate the `Summary` from the published `Cargo.toml`. Unfortunately, we don't have access directly to the packaged `Cargo.toml`. It could be passed around and I originally did so, hoping to remove use of the local `Package`. However, the local `Package` is needed for things like reading the `README`. So I scaled back and isolate the change to only what needs it. This also makes it easier for `prepare_transmit` callers. Fully open to someone exploring removing this extra `prepare_for_publish` in the future. Fixes rust-lang#14321
First, we added support for stripping of local-only dev-dependencies. This was dual-implemented for `Cargo.toml` and `Summary`. This left off stripping of `dep/feature` that reference dev-dependencies (enabling features within dev-dependencies). When we fixed this, we again dual-implemented it. The `Cargo.toml` version was correct but the `Summary` version was instead stripping too many features, particularly features that reference renamed dependencies. We didn't have tests for this case and it wasn't caught earlier because crates.io re-generates the `Summary` from `Cargo.toml`, ignoring what we post. That makes this only show up with custom registries that trust what Cargo posts. Rather than fixing the `Summary` generation, I remove the dual-implementation and instead generate the `Summary` from the published `Cargo.toml`. Unfortunately, we don't have access directly to the packaged `Cargo.toml`. It could be passed around and I originally did so, hoping to remove use of the local `Package`. However, the local `Package` is needed for things like reading the `README`. So I scaled back and isolate the change to only what needs it. This also makes it easier for `prepare_transmit` callers. Fully open to someone exploring removing this extra `prepare_for_publish` in the future. Fixes rust-lang#14321
First, we added support for stripping of local-only dev-dependencies. This was dual-implemented for `Cargo.toml` and `Summary`. This left off stripping of `dep/feature` that reference dev-dependencies (enabling features within dev-dependencies). When we fixed this, we again dual-implemented it. The `Cargo.toml` version was correct but the `Summary` version was instead stripping too many features, particularly features that reference renamed dependencies. We didn't have tests for this case and it wasn't caught earlier because crates.io re-generates the `Summary` from `Cargo.toml`, ignoring what we post. That makes this only show up with custom registries that trust what Cargo posts. Rather than fixing the `Summary` generation, I remove the dual-implementation and instead generate the `Summary` from the published `Cargo.toml`. Unfortunately, we don't have access directly to the packaged `Cargo.toml`. It could be passed around and I originally did so, hoping to remove use of the local `Package`. However, the local `Package` is needed for things like reading the `README`. So I scaled back and isolate the change to only what needs it. This also makes it easier for `prepare_transmit` callers. Fully open to someone exploring removing this extra `prepare_for_publish` in the future. Fixes rust-lang#14321
Problem
Cargo 1.78 and 1.79 drops
FeatureValue
s that match the default feature, resulting in an invalid feature map that later causes Cargo to ignore the version when parsing the index in the slow path ofSummaries::parse()
due tobuild_feature_map()
returning an error.Example error message:
The corresponding
Cargo.toml
looks like this:❌ The error occurs because when this crate is published by Cargo 1.78 or 1.79, the feature map is broken:
✅ When published with Cargo 1.76 or 1.77 instead, you get:
✅ When removing the
[features]
table from theCargo.toml
, you get:My hypothesis is that Cargo does some "cleaning" of the features map, maybe attempting to remove features that would be implied anyway, but it results in a broken map.
Steps
Cargo.toml
akin to the one shown aboveMore elaborate local testing:
sparsereg.py
from below to record anewcrate.json
when publishingsparse+http://localhost:8000/cargo/foorepo/index/
0001-Add-cargo-build-feature-map.rs.patch
cargo run --bin cargo-build-feature-map -- newcrate.json
Result
Additional files
sparsereg.py
0001-Add-cargo-build-feature-map.rs.patch
Possible Solution(s)
No response
Notes
No response
Version
The text was updated successfully, but these errors were encountered: