esp-rs / std-training

Embedded Rust on Espressif training material.
https://esp-rs.github.io/std-training
Apache License 2.0
590 stars 75 forks source link

embedded-io compilation fails #118

Closed JuliDi closed 1 year ago

JuliDi commented 1 year ago

After following the instructions in the book, I tried building the Hello Board project with cargo build --target riscv32imc-esp-espidf. The build then fails with many errors of the following type:

   Compiling embedded-io v0.3.1
error[E0658]: generic associated types are unstable
  --> /home/<user>/.cargo/registry/src/github.com-1ecc6299db9ec823/embedded-io-0.3.1/src/asynch.rs:17:5
   |
17 | /     type ReadFuture<'a>: Future<Output = Result<usize, Self::Error>>
18 | |     where
19 | |         Self: 'a;
   | |_________________^
   |
   = note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
   = help: add `#![feature(generic_associated_types)]` to the crate attributes to enable

My rust toolchain is up to date and the specific version requested in the book is available:

$ rustup toolchain list
stable-x86_64-unknown-linux-gnu (default)
nightly-2022-03-10-x86_64-unknown-linux-gnu (override)
JakobGalaxy commented 1 year ago

I am experiencing the same problem.

JakobGalaxy commented 1 year ago

Ok, so I am still new to Rust and a hardly know what I am doing here, but it seems to work, so here it is:

After some searching I found this Reddit post, which says that the feature must be enabled using #![feature(generic_associated_types)] in order to work.

The error says the problem occurs in this file: ~/.cargo/registry/src/github.com-1ecc6299db9ec823/embedded-io-0.3.1/src/asynch.rs, so I opened the src directory containing the asynch.rs and added the before-mentioned line #![feature(generic_associated_types)] to the top of the lib.rs file.

Now it works for me. I don't really think that this is a solution, but I also don't think that it can break much either, as you can always just delete the ~/.cargo/registry/ directory to revert this change. Hope this might help!

JuliDi commented 1 year ago

Thanks for the hint! I was thinking about doing what the compiler suggests, as well. However, this can't be a permanent solution. FYI you do not need to mess with the registry afaik, if you use this https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#testing-a-bugfix

So either embedded-io needs to fix this (which I doubt, because there v0.3.1 is very recent and fixes some issue with nightly), or this repo needs some change – but I have no clue which.

Moreover, it doesn't work on the docker container either. There is an issue with rustc being too old (1.61 and comfy-table needs 1.62 or newer) when installing cargo-espflash. Some crate in the dependency tree apparently causes a lot of trouble.

JakobGalaxy commented 1 year ago

Thanks for the explanation!

JuliDi commented 1 year ago

Just as an info for anyone else encountering the issue, the following steps can be used as a workaround:

fakeplant commented 1 year ago

Easier temp solution than cloning repo. Just override to a prev package version.

[patch.crates-io]
embedded-io = { git = "https://github.com/embassy-rs/embedded-io.git", tag = "v0.3.0"}

and then cargo update

Thanks to @elotom https://github.com/ivmarkov/rust-esp32-std-demo/issues/123#issuecomment-1300522982

JuliDi commented 1 year ago

Thanks @fakeplant ! Works like a charm. Embedded-io is now at release 0.4.0 but the issue seems to persist.

SergioGasquez commented 1 year ago

This should now be fixed with #125