Skip to content
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 add <crate> --git=<repo> -F <feature> results in "error: unrecognized feature for crate <crate>" for crates in a workspace #13542

Closed
digikata opened this issue Mar 5, 2024 · 3 comments
Labels
A-git Area: anything dealing with git C-bug Category: bug Command-add S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.

Comments

@digikata
Copy link

digikata commented Mar 5, 2024

Problem

For crates in a workspace, cargo add with a git flag and feature flag results in an "unrecognized feature" error.
The error occurs if the dependency is being newly added or updated.

Discovered in the fluvio repository CI, but other workspace organized repositories seem to show the same problem.

Steps

  1. cargo init .
  2. cargo add fluvio --git=https://github.com/infinyon/fluvio.git -F admin
    error: unrecognized feature for crate fluvio: admin
    no features available for crate fluvio
  3. Manually adding the dependency line to Cargo.toml works fine:
    fluvio = { features = ["admin"], git = "https://github.com/infinyon/fluvio.git" }

Possible Solution(s)

Manually adding the dependency works fine.

Notes

Other repos with using a workspace fail in the same way:

$ cargo add tokio --git=https://github.com/tokio-rs/tokio.git -F io-util
    Updating git repository `https://github.com/tokio-rs/tokio.git`
      Adding tokio (git) to dependencies.
error: unrecognized feature for crate tokio: io-util

Repos that are not workspace organized seem to work fine:

cargo add anyhow --git https://github.com/dtolnay/anyhow -F backtrace
    Updating git repository `https://github.com/dtolnay/anyhow`
      Adding anyhow (git) to dependencies.
             Features:
             + backtrace
             + std

Version

cargo 1.76.0 (c84b36747 2024-01-18)
release: 1.76.0
commit-hash: c84b367471a2db61d2c2c6aab605b14130b8a31b
commit-date: 2024-01-18
host: aarch64-apple-darwin
libgit2: 1.7.1 (sys:0.18.1 vendored)
libcurl: 8.4.0 (sys:0.4.70+curl-8.5.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Mac OS 14.2.1 [64-bit]
@digikata digikata added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Mar 5, 2024
@digikata digikata changed the title cargo add <crate> --git=<repo> -F <feature> results in "error: unrecognized feature for crate <crate>" cargo add <crate> --git=<repo> -F <feature> results in "error: unrecognized feature for crate <crate>" for crates an a workspace Mar 5, 2024
@epage epage added A-git Area: anything dealing with git Command-add labels Mar 6, 2024
@digikata digikata changed the title cargo add <crate> --git=<repo> -F <feature> results in "error: unrecognized feature for crate <crate>" for crates an a workspace cargo add <crate> --git=<repo> -F <feature> results in "error: unrecognized feature for crate <crate>" for crates in a workspace Mar 7, 2024
@weihanglo
Copy link
Member

I believe this is resolved by #13213. The current beta cargo 1.77.0-beta.7 (3fe68eabf 2024-02-29) and nightly cargo 1.78.0-nightly (a4c63fe53 2024-03-06) work for me.

@weihanglo
Copy link
Member

BTW, cargo add fluvio --git=https://github.com/infinyon/fluvio.git is reporting some invalid Cargo.toml format error and is out of scope of this issue.

Click to see the error messages

cargo +beta add fluvio --git=https://github.com/infinyon/fluvio.git -F admin
    Updating git repository `https://github.com/infinyon/fluvio.git`
error: invalid inline table
expected `}`
  --> ../../../.cargo/git/checkouts/fluvio-190650900278d481/3dff103/smartmodule/cargo_template/Cargo.toml:11:23
   |
11 | fluvio-smartmodule = {{fluvio-smartmodule-cargo-dependency}}
   |                       ^
   |
error: invalid character `{` in package name: `{{project-name}}`, the first character must be a Unicode XID start character (most letters or `_`)
 --> ../../../.cargo/git/checkouts/fluvio-190650900278d481/3dff103/connector/cargo_template/Cargo.toml:2:8
  |
2 | name = "{{project-name}}"
  |        ^^^^^^^^^^^^^^^^^^
  |
      Adding fluvio (git) to dependencies.
             Features:
             + admin
             + openssl
             - fluvio-smartengine
             - rustls
             - smartengine
             - unstable
error: invalid inline table
expected `}`
  --> ../../../.cargo/git/checkouts/fluvio-190650900278d481/3dff103/smartmodule/cargo_template/Cargo.toml:11:23
   |
11 | fluvio-smartmodule = {{fluvio-smartmodule-cargo-dependency}}
   |                       ^
   |
error: invalid character `{` in package name: `{{project-name}}`, the first character must be a Unicode XID start character (most letters or `_`)
 --> ../../../.cargo/git/checkouts/fluvio-190650900278d481/3dff103/connector/cargo_template/Cargo.toml:2:8
  |
2 | name = "{{project-name}}"
  |        ^^^^^^^^^^^^^^^^^^
  |

@weihanglo weihanglo added S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. and removed S-triage Status: This issue is waiting on initial triage. labels Mar 9, 2024
@digikata
Copy link
Author

digikata commented Mar 9, 2024

Thanks, @weihanglo. It does look like the issue will be fixed by #13213. I think I'll close this as a duplicate.

The error is generated from a couple of cargo-generate template directories in the project that aren't actually listed in the top level Cargo.toml as workspace members. If you happen to know a way to keep cargo from parsing those directories I'd be happy to apply that.

@digikata digikata closed this as not planned Won't fix, can't repro, duplicate, stale Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-git Area: anything dealing with git C-bug Category: bug Command-add S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.
Projects
None yet
Development

No branches or pull requests

3 participants