esp-rs / esp-idf-template

A "Hello, world!" template of a Rust binary crate for the ESP-IDF framework.
416 stars 50 forks source link

std-template not compiling/core crate not found #239

Open RoyalFoxy opened 1 day ago

RoyalFoxy commented 1 day ago

Bug description

I generated a fresh esp-idf template project with the command cargo generate esp-rs/esp-idf-template cargo and it doesn't build. I get this error

error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --cfg espidf_time64 --target xtensa-esp32-espidf --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg` (exit status: 1)
  --- stderr
  error: could not create LLVM TargetMachine for triple: xtensa-none-elf: No available targets are compatible with triple "xtensa-none-unknown-elf"

I have an existing project that "compiles" but gets stuck on the core crate as it apparently does not exist.

error[E0463]: can't find crate for `core`
  |
  = note: the `riscv32imac-esp-espidf` target may not be installed
  = help: consider downloading the target with `rustup target add riscv32imac-esp-espidf`

For more information about this error, try `rustc --explain E0463`.
error: could not compile `byteorder` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...

As a side note, it worked perfectly fine before for months and suddenly it stopped compiling and I got the second error. I tried creating new template projects and I got the same error at first but then I went through the entire book again to install everything from scratch and checked the links in the bug issue template. Nothing seemed to work.

To Reproduce

Steps to reproduce the behavior:

Likely not reproducible but I'll try :)

  1. Go through the esp book and install everything (std and no-std requirements)
  2. Install everything from https://github.com/esp-rs/esp-idf-template#prerequisites
  3. Create a new project with cargo generate esp-rs/esp-idf-template cargo
  4. Try to build with cargo build
  5. See a failed build (maybe??)

Creating a project from the master branch also doesn't build for me

Have it build the template like before

Additional context

I tried installing everything like 10 times already so that may've bricked something... I also did work with an esp-idf project (not rust) one like exactly 1 year ago~ and it has worked afterwards regardless of it and just now broke but maybe it has to do something with it

RoyalFoxy commented 1 day ago

I found out more information about this issue. If I create a template for the c6 processor it doesn't find the core crate but for the default esp32 processor rustc fails to compile as llvm doesn't find the triplet

RoyalFoxy commented 1 day ago

So trying to compile for the c6 processor with the master branch of the template or the 5.1 version doesn't work either and spits out the same "crate core not found" error

RoyalFoxy commented 1 day ago

It works with dev containers but is a lot slower as I'm on an m2 processor so the container needs to be emulated 🫠 But at least it works for now. Would still like some help for my issue

Vollbrecht commented 1 day ago

what is the output of rustup show ?

Vollbrecht commented 1 day ago

In general if you are not specifying a toolchain manually, we always use the toolchain that is specified inside the rust-toolchain.toml that is inside your project root dir.

ivmarkov commented 1 day ago

@RoyalFoxy

I have an existing project that "compiles" but gets stuck on the core crate as it apparently does not exist.

Crates core, std, panic_abort and so on are built with your project every time you do cargo build. They are not available "per-se", because all ESP IDF targets are Tier 3.

For this to happen, you must have a properly configured .cargo/config.toml in your binary crate root (look there for a TOML section named [unstable]). esp-idf-template does that for you, but if you have another .cargo/config.toml in a parent or grand-parent directory of your binary crate, it will mess up things.

Further, you should either use rust "nightly" (rustup default nightly), or rust "esp" (look at the "espup" documentation in this GH project README). What toolchain you are currently using can be seen with rustup show.

ivmarkov commented 1 day ago

I also suggest you read the README of this project carefully, top to bottom and make sure you applied have all steps, and nothing more.

For example, don't try to be adventurous by installing and activating ESP-IDF yourself. This is possible, but is an advanced configuration better avoided initially.

RoyalFoxy commented 2 hours ago

@Vollbrecht This is the output

Default host: aarch64-apple-darwin
rustup home:  /Users/royalfoxy/.rustup

installed toolchains
--------------------

stable-aarch64-apple-darwin (default)
nightly-2021-01-07-aarch64-apple-darwin
nightly-2022-08-08-aarch64-apple-darwin
nightly-2023-08-08-aarch64-apple-darwin
nightly-2024-03-22-aarch64-apple-darwin
nightly-2024-04-11-aarch64-apple-darwin
nightly-2024-04-17-aarch64-apple-darwin
nightly-aarch64-apple-darwin
1.61.0-aarch64-apple-darwin
esp

installed targets for active toolchain
--------------------------------------

aarch64-apple-darwin
riscv32imac-unknown-none-elf
riscv32imafc-unknown-none-elf
riscv32imc-unknown-none-elf

active toolchain
----------------

nightly-aarch64-apple-darwin (overridden by '/Users/royalfoxy/files/school/programming/m245/m5-nano-c6/rust-toolchain.toml')
rustc 1.83.0-nightly (18b1161ec 2024-10-02)

and I didn't specify any toolchain myself and relied on the template itself to work as it did in the past

RoyalFoxy commented 1 hour ago

@ivmarkov I'm aware they arent shipped pre compiled, by not found/available I meant that the rust compiler literally said "can't find crate for core". I also didn't alter my config.toml besides the baudrate and the CRATE_CC_NO_DEFAULTS if Im not mistaken.

[build]
target = "riscv32imac-esp-espidf"

[target.riscv32imac-esp-espidf]
linker = "ldproxy"
runner = "espflash flash --monitor --baud 460800"
rustflags = [ "--cfg",  "espidf_time64"]

[unstable]
build-std = ["std", "panic_abort"]

[env]
MCU="esp32c6"
ESP_IDF_VERSION = "v5.2.2"

CRATE_CC_NO_DEFAULTS = "1"

I also did use espup like I did in the past and it always worked until it magically didn't anymore. I updated nothing regarding espup and just opened the project and tried to flash my esp32-c6 but then it complained it can't find the crate core all of the sudden which it didn't the week prior.

Switching the toolchain nightly also changed nothing sadly

I also didn't install esp-idf myself for development with rust, I actually did so with the python scripts provided by their devs and had to do so as I was programming in a c++ codebase for a bit but as I stated, that never effected anything for over a year so that shouldn't be an issue.

I already read through all the prerequisites and how to use this template with cargo generate and tried it multiple times but never could get it to build