From f853b6f2b2b0562ceb9c3aa254b44d9db9fb6245 Mon Sep 17 00:00:00 2001 From: ju6ge Date: Thu, 11 Sep 2025 21:42:17 +0200 Subject: [PATCH] =?UTF-8?q?removed=20all=20std=20dependencies=20=E2=80=A6?= =?UTF-8?q?=20WIP=20move=20to=20embassy=20pure=20rust=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rust/.cargo/config.toml | 30 +++++++------ rust/Cargo.toml | 96 +++++++++++++++++++++++++++++------------ rust/build.rs | 51 +++++++++++++++++++++- 3 files changed, 133 insertions(+), 44 deletions(-) diff --git a/rust/.cargo/config.toml b/rust/.cargo/config.toml index 0655fa1..2fe2676 100644 --- a/rust/.cargo/config.toml +++ b/rust/.cargo/config.toml @@ -1,26 +1,28 @@ [build] -#target = "xtensa-esp32-espidf" -target = "riscv32imac-esp-espidf" +rustflags = [ + # Required to obtain backtraces (e.g. when using the "esp-backtrace" crate.) + # NOTE: May negatively impact performance of produced code + "-C", "force-frame-pointers", + "-Z", "stack-protector=all", +] -[target.riscv32imac-esp-espidf] -linker = "ldproxy" +target = "riscv32imac-unknown-none-elf" + +[target.riscv32imac-unknown-none-elf] +runner = "espflash flash --monitor --chip esp32c6" #runner = "espflash flash --monitor --baud 921600 --partition-table partitions.csv -b no-reset" # Select this runner in case of usb ttl -runner = "espflash flash --monitor" +#runner = "espflash flash --monitor" #runner = "cargo runner" #runner = "espflash flash --monitor --partition-table partitions.csv -b no-reset" # create upgrade image file for webupload # runner = espflash erase-parts otadata //ensure flash is clean -rustflags = ["--cfg", "espidf_time64"] # Extending time_t for ESP IDF 5: https://github.com/esp-rs/rust/issues/110 - -[unstable] -build-std = ["std", "panic_abort"] - [env] -MCU = "esp32c6" -# Note: this variable is not used by the pio builder (`cargo build --features pio`) -ESP_IDF_VERSION = "v5.2.1" CHRONO_TZ_TIMEZONE_FILTER = "UTC|America/New_York|America/Chicago|America/Los_Angeles|Europe/London|Europe/Berlin|Europe/Paris|Asia/Tokyo|Asia/Shanghai|Asia/Kolkata|Australia/Sydney|America/Sao_Paulo|Africa/Johannesburg|Asia/Dubai|Pacific/Auckland" CARGO_WORKSPACE_DIR = { value = "", relative = true } -RUST_BACKTRACE = "full" \ No newline at end of file +ESP_LOG="info" + +[unstable] +build-std = ["alloc", "core"] + diff --git a/rust/Cargo.toml b/rust/Cargo.toml index fcb701f..5164975 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -44,56 +44,98 @@ command = [ [package.metadata.espflash] partition_table = "partitions.csv" -[features] -default = ["std", "esp-idf-svc/native"] -pio = ["esp-idf-svc/pio"] -std = ["alloc", "esp-idf-svc/binstart", "esp-idf-svc/std"] -alloc = ["esp-idf-svc/alloc"] -nightly = ["esp-idf-svc/nightly"] -experimental = ["esp-idf-svc/experimental"] -#embassy = ["esp-idf-svc/embassy-sync", "esp-idf-svc/critical-section", "esp-idf-svc/embassy-time-driver"] - [dependencies] #ESP stuff -embedded-svc = { version = "0.28.1", features = ["experimental"] } -esp-idf-hal = "0.45.2" -esp-idf-sys = { version = "0.36.1", features = ["binstart", "native"] } -esp-idf-svc = { version = "0.51.0", default-features = false } +esp-bootloader-esp-idf = { version = "0.2.0", features = ["esp32c6"] } +esp-hal = { version = "=1.0.0-rc.0", features = [ + "esp32c6", + "log-04", + "unstable", +] } +log = "0.4.27" + +embassy-net = { version = "0.7.0", features = [ + "dhcpv4", + "log", + "medium-ethernet", + "tcp", + "udp", +] } +embedded-io = "0.6.1" +embedded-io-async = "0.6.1" +esp-alloc = "0.8.0" +esp-backtrace = { version = "0.17.0", features = [ + "esp32c6", + "exception-handler", + "panic-handler", + "println", +] } +esp-println = { version = "0.15.0", features = ["esp32c6", "log-04"] } +# for more networking protocol support see https://crates.io/crates/edge-net +critical-section = "1.2.0" +embassy-executor = { version = "0.7.0", features = [ + "log", + "task-arena-size-20480", +] } +embassy-time = { version = "0.4.0", features = ["log"] } +esp-hal-embassy = { version = "0.9.0", features = ["esp32c6", "log-04"] } +esp-wifi = { version = "0.15.0", features = [ + "builtin-scheduler", + "esp-alloc", + "esp32c6", + "log-04", + "smoltcp", + "wifi", +] } +smoltcp = { version = "0.12.0", default-features = false, features = [ + "log", + "medium-ethernet", + "multicast", + "proto-dhcpv4", + "proto-dns", + "proto-ipv4", + "socket-dns", + "socket-icmp", + "socket-raw", + "socket-tcp", + "socket-udp", +] } +static_cell = "2.1.1" embedded-hal = "1.0.0" heapless = { version = "0.8", features = ["serde"] } -embedded-hal-bus = { version = "0.3.0", features = ["std"] } +embedded-hal-bus = { version = "0.3.0" } #Hardware additional driver ds18b20 = "0.1.1" -bq34z100 = { version = "0.3.0", features = ["flashstream"] } +#bq34z100 = { version = "0.3.0", default-features = false } one-wire-bus = "0.1.1" ds323x = "0.6.0" #pure code dependencies -once_cell = "1.19.0" -anyhow = { version = "1.0.75", features = ["std", "backtrace"] } -strum = { version = "0.27.0", features = ["derive"] } +#once_cell = "1.19.0" +anyhow = { version = "1.0.75", default-features = false } +#strum = { version = "0.27.0", default-feature = false, features = ["derive"] } measurements = "0.11.0" #json -serde = { version = "1.0.192", features = ["derive"] } -serde_json = "1.0.108" +serde = { version = "1.0.219", features = ["derive", "alloc"], default-features = false } +serde_json = { version = "1.0.143", default-features = false, features = ["alloc"] } #timezone chrono = { version = "0.4.23", default-features = false, features = ["iana-time-zone", "alloc", "serde"] } chrono-tz = { version = "0.10.3", default-features = false, features = ["filter-by-regex"] } eeprom24x = "0.7.2" -url = "2.5.3" +#url = "2.5.3" crc = "3.2.1" -bincode = "2.0.1" +bincode = {version = "2.0.1", default-features = false, features = ["alloc", "serde"] } ringbuffer = "0.15.0" -text-template = "0.1.0" +#text-template = "0.1.0" strum_macros = "0.27.0" -esp-ota = { version = "0.2.2", features = ["log"] } +#esp-ota = { version = "0.2.2", features = ["log"] } unit-enum = "1.4.1" -pca9535 = { version = "2.0.0", features = ["std"] } -ina219 = { version = "0.2.0", features = ["std"] } +pca9535 = { version = "2.0.0" } +ina219 = { version = "0.2.0" } embedded-storage = "=0.3.1" ekv = "1.0.0" embedded-can = "0.4.1" @@ -108,6 +150,4 @@ embedded-can = "0.4.1" #bq34z100 = { path = "../../bq34z100_rust" } [build-dependencies] -cc = "=1.1.30" -embuild = { version = "0.32.0", features = ["espidf"] } vergen = { version = "8.2.6", features = ["build", "git", "gitcl"] } diff --git a/rust/build.rs b/rust/build.rs index 43feaea..6d32dbc 100644 --- a/rust/build.rs +++ b/rust/build.rs @@ -1,6 +1,54 @@ use std::process::Command; use vergen::EmitBuilder; + +fn linker_be_nice() { + let args: Vec = std::env::args().collect(); + if args.len() > 1 { + let kind = &args[1]; + let what = &args[2]; + + match kind.as_str() { + "undefined-symbol" => match what.as_str() { + "_defmt_timestamp" => { + eprintln!(); + eprintln!("💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`"); + eprintln!(); + } + "_stack_start" => { + eprintln!(); + eprintln!("💡 Is the linker script `linkall.x` missing?"); + eprintln!(); + } + "esp_wifi_preempt_enable" + | "esp_wifi_preempt_yield_task" + | "esp_wifi_preempt_task_create" => { + eprintln!(); + eprintln!("💡 `esp-wifi` has no scheduler enabled. Make sure you have the `builtin-scheduler` feature enabled, or that you provide an external scheduler."); + eprintln!(); + } + "embedded_test_linker_file_not_added_to_rustflags" => { + eprintln!(); + eprintln!("💡 `embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests"); + eprintln!(); + } + _ => (), + }, + // we don't have anything helpful for "missing-lib" yet + _ => { + std::process::exit(1); + } + } + + std::process::exit(0); + } + + println!( + "cargo:rustc-link-arg=--error-handling-script={}", + std::env::current_exe().unwrap().display() + ); +} + fn main() { println!("cargo:rerun-if-changed=./src/src_webpack"); Command::new("rm") @@ -64,7 +112,6 @@ fn main() { .unwrap(); } } - - embuild::espidf::sysenv::output(); + linker_be_nice(); let _ = EmitBuilder::builder().all_git().all_build().emit(); }