rust-lang / crates.io

The Rust package registry
https://crates.io
Apache License 2.0
2.93k stars 597 forks source link

`features2` in index broke cargo backward compatibility #6135

Open Turbo87 opened 1 year ago

Turbo87 commented 1 year ago

Current Behavior

According to https://www.reddit.com/r/rust/comments/11348jp/comment/j8o4nn6/ ripgrep can no longer be built by older cargo versions (e.g. 1.13).

Expected Behavior

Older cargo versions should be able to still build ripgrep

Steps To Reproduce

according to the Reddit thread:

clone the ripgrep repo and run cargo +1.13.0 b --verbose

Environment

No response

Anything else?

We have identified that the issue is related to how we introduced features2 to the index. ripgrep appears to use clap and in v4.0.0-rc.1 clap started to use the dep: prefix, causing the index to use features2 field.

The way clap used it and crates.io split the features map into features and features2 resulted in the following:

{
  "features": {
    "unstable-doc": [
      "derive"
    ]
  },
  "features2": {
    "derive": [
      "dep:clap_derive",
      "dep:once_cell"
    ]
  }
}

You can see that the unstable-doc feature depends on the derive feature. But since derive is in features2 the old cargo version thinks that the feature does not exist.

When splitting the feature maps we should have recursively moved the unstable-doc feature to features2 too, because it depends on a feature which is itself in features2.

Turbo87 commented 1 year ago

After discussing this with the cargo team on Zulip, we decided that the easiest way forward is to move all features into feature2 if we detect that any feature uses the new feature syntax.