twitchyliquid64 / usbd-hid

MIT License
87 stars 37 forks source link

usbd-hid 0.7 fails to build after 0.8 releases #72

Closed mciantyre closed 1 month ago

mciantyre commented 1 month ago

The 0.8 releases appear to break builds that depend on usbd-hid 0.7 or 0.6. Here's a reproduction:

cargo new --lib foo && cd foo
cargo add usbd-hid@0.7
cargo build

Here's the build failure:

   Compiling usbd-hid-macros v0.6.0
error[E0277]: the trait bound `usbd_hid_descriptors::MainItemKind: From<std::string::String>` is not satisfied
   --> /Users/mciantyre/.cargo/registry/src/index.crates.io-6f17d22bba15001f/usbd-hid-macros-0.6.0/src/spec.rs:512:43
    |
512 |             self.set_item(name, item_kind.into(), settings, bits, quirks);
    |                                           ^^^^ the trait `From<std::string::String>` is not implemented for `usbd_hid_descriptors::MainItemKind`, which is required by `std::string::String: Into<_>`
    |
    = help: the trait `From<&str>` is implemented for `usbd_hid_descriptors::MainItemKind`
    = help: for that trait implementation, expected `&str`, found `std::string::String`
    = note: required for `std::string::String` to implement `Into<usbd_hid_descriptors::MainItemKind>`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `usbd-hid-macros` (lib) due to 1 previous error
cargo tree output

``` foo v0.1.0 (/tmp/foo) └── usbd-hid v0.7.0 ├── serde v1.0.204 ├── ssmarshal v1.0.0 │ ├── encode_unicode v0.3.6 │ └── serde v1.0.204 ├── usb-device v0.3.2 │ ├── heapless v0.8.0 │ │ ├── hash32 v0.3.1 │ │ │ └── byteorder v1.4.3 │ │ └── stable_deref_trait v1.2.0 │ └── portable-atomic v1.6.0 └── usbd-hid-macros v0.6.0 (proc-macro) ├── byteorder v1.4.3 ├── proc-macro2 v1.0.86 │ └── unicode-ident v1.0.12 ├── quote v1.0.36 │ └── proc-macro2 v1.0.86 (*) ├── serde v1.0.204 ├── syn v1.0.109 │ ├── proc-macro2 v1.0.86 (*) │ ├── quote v1.0.36 (*) │ └── unicode-ident v1.0.12 └── usbd-hid-descriptors v0.8.0 └── bitfield v0.14.0 ```

919616b9b65e89b4c9c8a4adcfe1af7870c891c7 shows that usbd-hid-macros 0.6 is allowed to depend on any version of usbd-hid-descriptors starting from 0.1.2. In this reproduction, usbd-hid-macros selects usbd-hid-descriptors 0.8.0 as its dependency. These seem to be incompatible.

twitchyliquid64 commented 1 month ago

I'm sorry about that, I had a >=x dependency on one of the internal crate which blew up. This is fixed in the 0.8 series.

HaoboGu commented 1 month ago

@twitchyliquid64 Sorry for the ping, but the issue seems still here. I'm using usbd-hid 0.7, and here is the build log: https://github.com/HaoboGu/rmk/actions/runs/9969247462/job/27545878943

twitchyliquid64 commented 1 month ago

Can you try 0.8? Does that work?

HaoboGu commented 1 month ago

Can you try 0.8? Does that work?

No. That's because I'm using the crates.io version of embassy-usb, which uses usbd-hid@0.7

Here is the log:

error: failed to select a version for `byteorder`.
    ... required by package `usbd-hid-macros v0.6.0`
    ... which satisfies dependency `usbd-hid-macros = "^0.6.0"` of package `usbd-hid v0.7.0`
    ... which satisfies dependency `usbd-hid = "^0.7.0"` of package `embassy-usb v0.2.0`
    ... which satisfies dependency `embassy-usb = "^0.2"` of package `rmk v0.2.2 (/Users/haobogu/Projects/keyboard/rmk/rmk)`
versions that meet the requirements `~1.4` are: 1.4.3, 1.4.2, 1.4.1, 1.4.0

all possible versions conflict with previously selected packages.

  previously selected package `byteorder v1.5.0`
    ... which satisfies dependency `byteorder = "^1.5"` of package `usbd-hid-macros v0.8.0`
    ... which satisfies dependency `usbd-hid-macros = "^0.8.0"` of package `usbd-hid v0.8.0`
    ... which satisfies dependency `usbd-hid = "^0.8"` of package `rmk v0.2.2 (/Users/haobogu/Projects/keyboard/rmk/rmk)`

failed to select a version for `byteorder` which could resolve this conflict
twitchyliquid64 commented 1 month ago

I wrote the first version of this in 2020, in the first few months of writing Rust, and foolishly put the >= specifier on the inter-crate version specifiers. This exploded a few days ago when the macros crate was no longer compatible with all older versions.

I don't really know a way to fix this without everyone upgrading to usbd-hid 0.8 :(

If anyone has any ideas for how to fix this for the 0.6 or 0.7 series please let me know. Sorry again.

mciantyre commented 1 month ago

I break my users all the time. You're in good company.

My approach in https://github.com/imxrt-rs/imxrt-hal/pull/169 was to simulate the release of a 0.6.1 usbd-hid-macros package. Here is the change I made. That fixes my builds, and my quick firmware test still worked. I'm not sure if it fixes everything for everyone else, but folks can try it out by adding

[patch.crates-io.usbd-hid-macros]
git = "https://github.com/imxrt-rs/usbd-hid.git"
branch = "patch-imxrt-hal-0.5"

into their project's Cargo.toml.

Is there concern with releasing a 0.6.1 version of usbd-hid-macros, a release that removes the >= specifier? You'll need to select the correct branch point for cutting the release. (Don't do what I did: hastily select a commit from 2 days ago when 0.6.0 was release nearly 2 years ago.)

twitchyliquid64 commented 1 month ago

Hmmm, yeah I can do that. I think crates lets you release patches of old minor versions?

Afaict everyone thats broken was using 0.6 ?

twitchyliquid64 commented 1 month ago

Can you try 0.6.2? Just pushed it.

HaoboGu commented 1 month ago

Could you push a 0.7 update? thanks

twitchyliquid64 commented 1 month ago

Just did, can you test @HaoboGu ?

twitchyliquid64 commented 1 month ago

0.7.1

HaoboGu commented 1 month ago

Just did, can you test @HaoboGu ?

I just tested, worked well! Thanks a lot!

twitchyliquid64 commented 1 month ago

Yay!!!