From 036ae077405783cf3941d465b01100ce930876fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 29 Aug 2024 09:41:52 +0200 Subject: [PATCH 01/11] Deduplicate feature check macros --- esp-build/src/lib.rs | 65 ++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/esp-build/src/lib.rs b/esp-build/src/lib.rs index 3de49b6ac3d..12cbfbf899a 100644 --- a/esp-build/src/lib.rs +++ b/esp-build/src/lib.rs @@ -5,6 +5,7 @@ use std::{io::Write as _, process}; use proc_macro::TokenStream; +use quote::ToTokens; use syn::{parse_macro_input, punctuated::Punctuated, LitStr, Token}; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; @@ -58,22 +59,10 @@ pub fn assert_unique_features(input: TokenStream) -> TokenStream { .into_iter() .collect::>(); - let pairs = unique_pairs(&features); - let unique_cfgs = pairs - .iter() - .map(|(a, b)| quote::quote! { all(feature = #a, feature = #b) }); - - let message = format!( - r#" -ERROR: expected exactly zero or one enabled feature from feature group: - {:?} -"#, - features.iter().map(|lit| lit.value()).collect::>(), - ); + let unique = impl_unique_features(&features, "exactly zero or one"); quote::quote! { - #[cfg(any(#(#unique_cfgs),*))] - ::esp_build::error! { #message } + #unique } .into() } @@ -91,17 +80,10 @@ pub fn assert_used_features(input: TokenStream) -> TokenStream { .into_iter() .collect::>(); - let message = format!( - r#" -ERROR: expected at least one enabled feature from feature group: - {:?} - "#, - features.iter().map(|lit| lit.value()).collect::>() - ); + let used = impl_used_features(&features, "at least one"); quote::quote! { - #[cfg(not(any(#(feature = #features),*)))] - ::esp_build::error! { #message } + #used } .into() } @@ -118,6 +100,20 @@ pub fn assert_unique_used_features(input: TokenStream) -> TokenStream { .into_iter() .collect::>(); + let unique = impl_unique_features(&features, "exactly one"); + let used = impl_used_features(&features, "exactly one"); + + quote::quote! { + #unique + #used + } + .into() +} + +// ---------------------------------------------------------------------------- +// Helper Functions + +fn impl_unique_features(features: &[LitStr], expectation: &str) -> impl ToTokens { let pairs = unique_pairs(&features); let unique_cfgs = pairs .iter() @@ -125,22 +121,33 @@ pub fn assert_unique_used_features(input: TokenStream) -> TokenStream { let message = format!( r#" -ERROR: expected exactly one enabled feature from feature group: +ERROR: expected {expectation} enabled feature from feature group: + {:?} +"#, + features.iter().map(|lit| lit.value()).collect::>(), + ); + + quote::quote! { + #[cfg(any(#(#unique_cfgs),*))] + ::esp_build::error! { #message } + } +} + +fn impl_used_features(features: &[LitStr], expectation: &str) -> impl ToTokens { + let message = format!( + r#" +ERROR: expected {expectation} enabled feature from feature group: {:?} "#, features.iter().map(|lit| lit.value()).collect::>() ); quote::quote! { - #[cfg(any(any(#(#unique_cfgs),*), not(any(#(feature = #features),*))))] + #[cfg(not(any(#(feature = #features),*)))] ::esp_build::error! { #message } } - .into() } -// ---------------------------------------------------------------------------- -// Helper Functions - // Adapted from: // https://github.com/dtolnay/build-alert/blob/49d060e/src/lib.rs#L54-L93 fn do_alert(color: Color, input: TokenStream) -> TokenStream { From 8ec0d3625e08b7e07c94ee3734cce00026b929b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 29 Aug 2024 10:01:51 +0200 Subject: [PATCH 02/11] Re-enable rust-analyzer for most of the workspace --- .vscode/settings.json.example | 12 ++++++++++++ Cargo.toml | 10 ++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json.example diff --git a/.vscode/settings.json.example b/.vscode/settings.json.example new file mode 100644 index 00000000000..c8b2256ff23 --- /dev/null +++ b/.vscode/settings.json.example @@ -0,0 +1,12 @@ +{ + "rust-analyzer.cargo.allTargets": false, + "rust-analyzer.cargo.target": "riscv32imac-unknown-none-elf", + "rust-analyzer.cargo.features": [ + "esp32c6", + "esp-hal/async", + "esp-hal/defmt", + "esp-backtrace/defmt", + "esp-println/uart", + "esp-println/defmt-espflash" + ] +} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index a7c4172d717..bd0734cadbe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,16 +1,15 @@ [workspace] resolver = "2" -members = ["xtask"] -exclude = [ +members = [ + "xtask", + "esp-hal", "esp-alloc", "esp-backtrace", "esp-build", - "esp-hal", "esp-hal-embassy", "esp-hal-procmacros", "esp-hal-smartled", "esp-ieee802154", - "esp-lp-hal", "esp-metadata", "esp-println", "esp-riscv-rt", @@ -20,6 +19,9 @@ exclude = [ "extras/bench-server", "extras/esp-wifishark", "extras/ieee802154-sniffer", +] +exclude = [ + "esp-lp-hal", "hil-test", "xtensa-lx", "xtensa-lx-rt", From c8ea88ce9821b34de0315a7815c41837d58254f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 29 Aug 2024 12:04:02 +0200 Subject: [PATCH 03/11] Cargo fix --- .vscode/settings.json.example | 2 ++ Cargo.toml | 9 +++++++ esp-build/src/lib.rs | 2 +- esp-hal-procmacros/src/embassy.rs | 6 ++--- esp-hal-procmacros/src/enum_dispatch.rs | 25 ++++++++--------- esp-hal-procmacros/src/interrupt.rs | 4 +-- esp-hal-procmacros/src/lib.rs | 4 +-- examples/Cargo.toml | 9 ------- extras/bench-server/src/main.rs | 36 +++++++++++++++++-------- 9 files changed, 55 insertions(+), 42 deletions(-) diff --git a/.vscode/settings.json.example b/.vscode/settings.json.example index c8b2256ff23..0bf1dbcf900 100644 --- a/.vscode/settings.json.example +++ b/.vscode/settings.json.example @@ -1,6 +1,8 @@ { "rust-analyzer.cargo.allTargets": false, + "rust-analyzer.cargo.targetDir": "target/rust-analyzer", "rust-analyzer.cargo.target": "riscv32imac-unknown-none-elf", + "rust-analyzer.procMacro.attributes.enable": false, "rust-analyzer.cargo.features": [ "esp32c6", "esp-hal/async", diff --git a/Cargo.toml b/Cargo.toml index bd0734cadbe..7888112a6a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,3 +27,12 @@ exclude = [ "xtensa-lx-rt", "xtensa-lx-rt/procmacros", ] + +[profile.release] +codegen-units = 1 +debug = 2 +debug-assertions = false +incremental = false +opt-level = 3 +lto = 'fat' +overflow-checks = false diff --git a/esp-build/src/lib.rs b/esp-build/src/lib.rs index 12cbfbf899a..4e97602da0a 100644 --- a/esp-build/src/lib.rs +++ b/esp-build/src/lib.rs @@ -114,7 +114,7 @@ pub fn assert_unique_used_features(input: TokenStream) -> TokenStream { // Helper Functions fn impl_unique_features(features: &[LitStr], expectation: &str) -> impl ToTokens { - let pairs = unique_pairs(&features); + let pairs = unique_pairs(features); let unique_cfgs = pairs .iter() .map(|(a, b)| quote::quote! { all(feature = #a, feature = #b) }); diff --git a/esp-hal-procmacros/src/embassy.rs b/esp-hal-procmacros/src/embassy.rs index fdd44ff863c..9d1dc5c0144 100644 --- a/esp-hal-procmacros/src/embassy.rs +++ b/esp-hal-procmacros/src/embassy.rs @@ -46,13 +46,13 @@ pub(crate) mod main { if !f.sig.generics.params.is_empty() { ctxt.error_spanned_by(&f.sig, "main function must not be generic"); } - if !f.sig.generics.where_clause.is_none() { + if f.sig.generics.where_clause.is_some() { ctxt.error_spanned_by(&f.sig, "main function must not have `where` clauses"); } - if !f.sig.abi.is_none() { + if f.sig.abi.is_some() { ctxt.error_spanned_by(&f.sig, "main function must not have an ABI qualifier"); } - if !f.sig.variadic.is_none() { + if f.sig.variadic.is_some() { ctxt.error_spanned_by(&f.sig, "main function must not be variadic"); } match &f.sig.output { diff --git a/esp-hal-procmacros/src/enum_dispatch.rs b/esp-hal-procmacros/src/enum_dispatch.rs index 2372be88426..3a010bd9849 100644 --- a/esp-hal-procmacros/src/enum_dispatch.rs +++ b/esp-hal-procmacros/src/enum_dispatch.rs @@ -30,21 +30,18 @@ impl Parse for MakeGpioEnumDispatchMacro { let mut elements = vec![]; - let mut stream = input.parse::()?.stream().into_iter(); + let stream = input.parse::()?.stream().into_iter(); let mut element_name = String::new(); - loop { - match stream.next() { - Some(v) => match v { - TokenTree::Ident(ident) => { - element_name = ident.to_string(); - } - TokenTree::Literal(lit) => { - let index = lit.to_string().parse().unwrap(); - elements.push((element_name.clone(), index)); - } - _ => (), - }, - None => break, + for v in stream { + match v { + TokenTree::Ident(ident) => { + element_name = ident.to_string(); + } + TokenTree::Literal(lit) => { + let index = lit.to_string().parse().unwrap(); + elements.push((element_name.clone(), index)); + } + _ => (), } } diff --git a/esp-hal-procmacros/src/interrupt.rs b/esp-hal-procmacros/src/interrupt.rs index 385dbb3c06d..f84acbfcbc5 100644 --- a/esp-hal-procmacros/src/interrupt.rs +++ b/esp-hal-procmacros/src/interrupt.rs @@ -24,7 +24,7 @@ pub(crate) fn check_attr_whitelist( 'o: for attr in attrs { for val in whitelist { - if eq(&attr, &val) { + if eq(attr, val) { continue 'o; } } @@ -35,7 +35,7 @@ pub(crate) fn check_attr_whitelist( } }; - return Err(Error::new(attr.span(), &err_str).to_compile_error().into()); + return Err(Error::new(attr.span(), err_str).to_compile_error().into()); } Ok(()) diff --git a/esp-hal-procmacros/src/lib.rs b/esp-hal-procmacros/src/lib.rs index 6bec2d198f1..0a1106e4b87 100644 --- a/esp-hal-procmacros/src/lib.rs +++ b/esp-hal-procmacros/src/lib.rs @@ -210,7 +210,7 @@ pub fn ram(args: TokenStream, input: TokenStream) -> TokenStream { let hal = proc_macro2::Ident::new( if let Ok(FoundCrate::Name(ref name)) = crate_name("esp-hal") { - &name + name } else { "crate" }, @@ -278,7 +278,7 @@ pub fn handler(args: TokenStream, input: TokenStream) -> TokenStream { let root = Ident::new( if let Ok(FoundCrate::Name(ref name)) = crate_name("esp-hal") { - &name + name } else { "crate" }, diff --git a/examples/Cargo.toml b/examples/Cargo.toml index c05bee62d00..f06e7465459 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -80,12 +80,3 @@ embassy-generic-timers = ["embassy-time/generic-queue-8"] opsram-2m = ["esp-hal/opsram-2m"] psram-2m = ["esp-hal/psram-2m"] - -[profile.release] -codegen-units = 1 -debug = 2 -debug-assertions = false -incremental = false -opt-level = 3 -lto = 'fat' -overflow-checks = false diff --git a/extras/bench-server/src/main.rs b/extras/bench-server/src/main.rs index 21ab64867c7..7f38acf749d 100644 --- a/extras/bench-server/src/main.rs +++ b/extras/bench-server/src/main.rs @@ -1,7 +1,9 @@ -use std::io::{Read, Write}; -use std::net::{TcpListener, TcpStream}; -use std::thread::spawn; -use std::time::Duration; +use std::{ + io::{Read, Write}, + net::{TcpListener, TcpStream}, + thread::spawn, + time::Duration, +}; use log::info; @@ -22,8 +24,12 @@ fn tx_listen() { } fn tx_conn(mut socket: TcpStream) { - socket.set_read_timeout(Some(Duration::from_secs(30))).unwrap(); - socket.set_write_timeout(Some(Duration::from_secs(30))).unwrap(); + socket + .set_read_timeout(Some(Duration::from_secs(30))) + .unwrap(); + socket + .set_write_timeout(Some(Duration::from_secs(30))) + .unwrap(); let buf = [0; 1024]; loop { @@ -44,8 +50,12 @@ fn rx_listen() { } fn rx_conn(mut socket: TcpStream) { - socket.set_read_timeout(Some(Duration::from_secs(30))).unwrap(); - socket.set_write_timeout(Some(Duration::from_secs(30))).unwrap(); + socket + .set_read_timeout(Some(Duration::from_secs(30))) + .unwrap(); + socket + .set_write_timeout(Some(Duration::from_secs(30))) + .unwrap(); let mut buf = [0; 1024]; loop { @@ -66,8 +76,12 @@ fn rxtx_listen() { } fn rxtx_conn(mut socket: TcpStream) { - socket.set_read_timeout(Some(Duration::from_secs(30))).unwrap(); - socket.set_write_timeout(Some(Duration::from_secs(30))).unwrap(); + socket + .set_read_timeout(Some(Duration::from_secs(30))) + .unwrap(); + socket + .set_write_timeout(Some(Duration::from_secs(30))) + .unwrap(); let mut buf = [0; 1024]; loop { @@ -84,4 +98,4 @@ fn rxtx_conn(mut socket: TcpStream) { } } } -} \ No newline at end of file +} From 8a80937a285bde47efbbb7317406238ce2cc3546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 29 Aug 2024 12:53:37 +0200 Subject: [PATCH 04/11] Turn off defmt --- .vscode/settings.json.example | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json.example b/.vscode/settings.json.example index 0bf1dbcf900..809de418731 100644 --- a/.vscode/settings.json.example +++ b/.vscode/settings.json.example @@ -1,14 +1,13 @@ { "rust-analyzer.cargo.allTargets": false, "rust-analyzer.cargo.targetDir": "target/rust-analyzer", - "rust-analyzer.cargo.target": "riscv32imac-unknown-none-elf", "rust-analyzer.procMacro.attributes.enable": false, "rust-analyzer.cargo.features": [ "esp32c6", "esp-hal/async", - "esp-hal/defmt", - "esp-backtrace/defmt", + "esp-hal/log", + "esp-backtrace/println", "esp-println/uart", - "esp-println/defmt-espflash" + "esp-println/log" ] } \ No newline at end of file From bf54601af750d61a7ae2099855830353f6c22c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 29 Aug 2024 12:59:19 +0200 Subject: [PATCH 05/11] Only build xtask --- .github/workflows/hil.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/hil.yml b/.github/workflows/hil.yml index 47b9773889a..c30091df688 100644 --- a/.github/workflows/hil.yml +++ b/.github/workflows/hil.yml @@ -60,7 +60,7 @@ jobs: run: cargo install cross - name: Build xtasks - run: cross build --release --target ${{ matrix.host.rust-target }} + run: cross build --release --target ${{ matrix.host.rust-target }} -p xtask - name: Upload artifact uses: actions/upload-artifact@v4 From e5c623a84afcd9b8786057a9869b6fed4a19bab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 29 Aug 2024 13:45:47 +0200 Subject: [PATCH 06/11] Clippy pls --- .vscode/settings.json.example | 6 ++++-- esp-hal-procmacros/src/lp_core.rs | 30 +++++++++++++++--------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/.vscode/settings.json.example b/.vscode/settings.json.example index 809de418731..7c55fbadfcd 100644 --- a/.vscode/settings.json.example +++ b/.vscode/settings.json.example @@ -6,8 +6,10 @@ "esp32c6", "esp-hal/async", "esp-hal/log", + "esp-hal-procmacros/has-lp-core", "esp-backtrace/println", "esp-println/uart", - "esp-println/log" - ] + "esp-println/log", + ], + "editor.formatOnSave": true, } \ No newline at end of file diff --git a/esp-hal-procmacros/src/lp_core.rs b/esp-hal-procmacros/src/lp_core.rs index 31baca8eee4..2cf4741a109 100644 --- a/esp-hal-procmacros/src/lp_core.rs +++ b/esp-hal-procmacros/src/lp_core.rs @@ -219,7 +219,7 @@ pub fn load_lp_code(input: TokenStream) -> TokenStream { }; let hal_crate = if let Ok(FoundCrate::Name(ref name)) = hal_crate { - let ident = Ident::new(&name, Span::call_site().into()); + let ident = Ident::new(name, Span::call_site().into()); quote!( #ident ) } else { quote!(crate) @@ -261,12 +261,14 @@ pub fn load_lp_code(input: TokenStream) -> TokenStream { let mut sections: Vec
= sections .into_iter() - .filter(|section| match section.kind() { - SectionKind::Text - | SectionKind::ReadOnlyData - | SectionKind::Data - | SectionKind::UninitializedData => true, - _ => false, + .filter(|section| { + matches!( + section.kind(), + SectionKind::Text + | SectionKind::ReadOnlyData + | SectionKind::Data + | SectionKind::UninitializedData + ) }) .collect(); sections.sort_by(|a, b| a.address().partial_cmp(&b.address()).unwrap()); @@ -280,9 +282,8 @@ pub fn load_lp_code(input: TokenStream) -> TokenStream { for section in sections { if section.address() > last_address { - for _ in 0..(section.address() - last_address) { - binary.push(0); - } + let fill = section.address() - last_address; + binary.extend(std::iter::repeat(0).take(fill as usize)); } binary.extend_from_slice(section.data().unwrap()); @@ -293,21 +294,20 @@ pub fn load_lp_code(input: TokenStream) -> TokenStream { .symbols() .find(|s| s.name().unwrap().starts_with("__ULP_MAGIC_")); - if let None = magic_symbol { + let magic_symbol = if let Some(magic_symbol) = magic_symbol { + magic_symbol.name().unwrap() + } else { return Error::new( Span::call_site().into(), "Given file doesn't seem to be an LP/ULP core application.", ) .to_compile_error() .into(); - } - - let magic_symbol = magic_symbol.unwrap().name().unwrap(); + }; let magic_symbol = magic_symbol.trim_start_matches("__ULP_MAGIC_"); let args: Vec = magic_symbol .split("$") - .into_iter() .map(|t| { let t = if t.contains("OutputOpenDrain") { t.replace("OutputOpenDrain", "LowPowerOutputOpenDrain") From b816dc6bb3ab335cd327ad2dddaa77cb2bf01a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 29 Aug 2024 14:10:04 +0200 Subject: [PATCH 07/11] Fix CI --- .vscode/settings.json.example | 2 ++ Cargo.toml | 2 +- esp-hal-procmacros/src/lp_core.rs | 16 +++++++-------- esp-lp-hal/Cargo.toml | 8 ++++---- xtask/src/lib.rs | 12 +++++++++-- xtask/src/main.rs | 33 +++++++++++++++++++------------ 6 files changed, 45 insertions(+), 28 deletions(-) diff --git a/.vscode/settings.json.example b/.vscode/settings.json.example index 7c55fbadfcd..5ab665a9dde 100644 --- a/.vscode/settings.json.example +++ b/.vscode/settings.json.example @@ -8,6 +8,8 @@ "esp-hal/log", "esp-hal-procmacros/has-lp-core", "esp-backtrace/println", + "esp-backtrace/panic-handler", + "esp-backtrace/exception-handler", "esp-println/uart", "esp-println/log", ], diff --git a/Cargo.toml b/Cargo.toml index 7888112a6a8..6938bc8589f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "esp-hal-procmacros", "esp-hal-smartled", "esp-ieee802154", + "esp-lp-hal", "esp-metadata", "esp-println", "esp-riscv-rt", @@ -21,7 +22,6 @@ members = [ "extras/ieee802154-sniffer", ] exclude = [ - "esp-lp-hal", "hil-test", "xtensa-lx", "xtensa-lx-rt", diff --git a/esp-hal-procmacros/src/lp_core.rs b/esp-hal-procmacros/src/lp_core.rs index 2cf4741a109..98915ddc0e5 100644 --- a/esp-hal-procmacros/src/lp_core.rs +++ b/esp-hal-procmacros/src/lp_core.rs @@ -23,19 +23,19 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { let mut res = String::from("__ULP_MAGIC_"); for &a in args { let t = &a.ty; - let quoted = to_string(&t); + let quoted = to_string(t); res.push_str("ed); - res.push_str("$"); + res.push('$'); } res } pub(crate) fn get_simplename(t: &Type) -> String { - String::from(match t { + match t { Type::Path(p) => String::from(&p.path.segments.last().unwrap().ident.to_string()), _ => String::new(), - }) + } } pub(crate) fn extract_pin(ty: &Type) -> u8 { @@ -49,7 +49,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { res = extract_pin(t); } GenericArgument::Const(c) => { - res = ("e! { #c }.to_string()).parse().unwrap(); + res = quote! { #c }.to_string().parse().unwrap(); } _ => (), } @@ -68,11 +68,11 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { res.push_str(&segment.ident.to_string()); if let PathArguments::AngleBracketed(g) = &segment.arguments { - res.push_str("<"); + res.push('<'); let mut pushed = false; for arg in &g.args { if pushed { - res.push_str(","); + res.push(','); } match arg { @@ -87,7 +87,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { _ => (), } } - res.push_str(">"); + res.push('>'); } } diff --git a/esp-lp-hal/Cargo.toml b/esp-lp-hal/Cargo.toml index f8e893dab6e..72db1c35d42 100644 --- a/esp-lp-hal/Cargo.toml +++ b/esp-lp-hal/Cargo.toml @@ -7,10 +7,6 @@ description = "HAL for low-power RISC-V coprocessors found in ESP32 devices" repository = "https://github.com/esp-rs/esp-hal" license = "MIT OR Apache-2.0" -[lib] -bench = false -test = false - keywords = [ "embedded", "embedded-hal", @@ -24,6 +20,10 @@ categories = [ "no-std", ] +[lib] +bench = false +test = false + [dependencies] cfg-if = "1.0.0" document-features = "0.2.10" diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 9e28b57faab..61fed2aede9 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -114,7 +114,7 @@ pub fn build_documentation( package: Package, chip: Chip, target: &str, -) -> Result<()> { +) -> Result { let package_name = package.to_string(); let package_path = windows_safe_path(&workspace.join(&package_name)); @@ -142,7 +142,15 @@ pub fn build_documentation( // Execute `cargo doc` from the package root: cargo::run(&args, &package_path)?; - Ok(()) + let docs_path = windows_safe_path( + &workspace + .join("target") + .join(target) + .join("doc") + .join(package.to_string().replace('-', "_")), + ); + + Ok(docs_path) } /// Load all examples at the given path, and parse their metadata. diff --git a/xtask/src/main.rs b/xtask/src/main.rs index bbec3a47e3d..4317ccba2e0 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -341,10 +341,12 @@ fn build_documentation(workspace: &Path, args: BuildDocumentationArgs) -> Result } // Copy any additional assets to the documentation's output path: - fs::copy(resources.join("esp-rs.svg"), output_path.join("esp-rs.svg"))?; + fs::copy(resources.join("esp-rs.svg"), output_path.join("esp-rs.svg")) + .context("Failed to copy esp-rs.svg")?; // Render the index and write it out to the documentaiton's output path: - let source = fs::read_to_string(resources.join("index.html.jinja"))?; + let source = fs::read_to_string(resources.join("index.html.jinja")) + .context("Failed to read index.html.jinja")?; let mut env = minijinja::Environment::new(); env.add_template("index", &source)?; @@ -352,7 +354,7 @@ fn build_documentation(workspace: &Path, args: BuildDocumentationArgs) -> Result let tmpl = env.get_template("index")?; let html = tmpl.render(minijinja::context! { packages => packages })?; - fs::write(output_path.join("index.html"), html)?; + fs::write(output_path.join("index.html"), html).context("Failed to write index.html")?; Ok(()) } @@ -377,14 +379,12 @@ fn build_documentation_for_package( // Build the documentation for the specified package, targeting the // specified chip: - xtask::build_documentation(workspace, package, *chip, target)?; - - let docs_path = xtask::windows_safe_path( - &workspace - .join(package.to_string()) - .join("target") - .join(target) - .join("doc"), + let docs_path = xtask::build_documentation(workspace, package, *chip, target)?; + + ensure!( + docs_path.exists(), + "Documentation not found at {}", + docs_path.display() ); let output_path = output_path @@ -394,8 +394,15 @@ fn build_documentation_for_package( let output_path = xtask::windows_safe_path(&output_path); // Create the output directory, and copy the built documentation into it: - fs::create_dir_all(&output_path)?; - copy_dir_all(&docs_path, &output_path)?; + fs::create_dir_all(&output_path) + .with_context(|| format!("Failed to create {}", output_path.display()))?; + copy_dir_all(&docs_path, &output_path).with_context(|| { + format!( + "Failed to copy {} to {}", + docs_path.display(), + output_path.display() + ) + })?; // Build the context object required for rendering this particular build's // information on the documentation index: From c6842e6f9051fdd1f1b17d1dc974f1607eb4c607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 29 Aug 2024 16:04:13 +0200 Subject: [PATCH 08/11] Fix paths --- .vscode/settings.json.example | 8 ++++++++ esp-lp-hal/.cargo/config.toml | 4 ++-- esp-lp-hal/Cargo.toml | 6 +++--- esp-lp-hal/examples/{blinky.rs => lp_blinky.rs} | 0 esp-lp-hal/examples/{i2c.rs => lp_i2c.rs} | 0 esp-lp-hal/examples/{uart.rs => lp_uart.rs} | 0 examples/src/bin/lp_core_basic.rs | 2 +- examples/src/bin/lp_core_i2c.rs | 2 +- examples/src/bin/lp_core_uart.rs | 2 +- examples/src/bin/ulp_riscv_core_basic.rs | 2 +- 10 files changed, 17 insertions(+), 9 deletions(-) rename esp-lp-hal/examples/{blinky.rs => lp_blinky.rs} (100%) rename esp-lp-hal/examples/{i2c.rs => lp_i2c.rs} (100%) rename esp-lp-hal/examples/{uart.rs => lp_uart.rs} (100%) diff --git a/.vscode/settings.json.example b/.vscode/settings.json.example index 5ab665a9dde..fe35ce53bc1 100644 --- a/.vscode/settings.json.example +++ b/.vscode/settings.json.example @@ -1,4 +1,12 @@ { + // These are recommended settings. + // Should you wish to disable rust-analyzer, you can replace all of this with + // `"rust-analyzer.files.excludeDirs": ["."]`. + // You can also omit all this, but that will cause r-a to try + // (and after a long while, fail) initializing. + // Note that we are not telling rust-analyzer to use an embedded target. + // This results in a few pointer width related errors, but it also means r-a is able + // to cope with xtask and its dependencies. "rust-analyzer.cargo.allTargets": false, "rust-analyzer.cargo.targetDir": "target/rust-analyzer", "rust-analyzer.procMacro.attributes.enable": false, diff --git a/esp-lp-hal/.cargo/config.toml b/esp-lp-hal/.cargo/config.toml index 3cf0f9207b6..62bc6838311 100644 --- a/esp-lp-hal/.cargo/config.toml +++ b/esp-lp-hal/.cargo/config.toml @@ -1,7 +1,7 @@ [alias] esp32c6 = "build --release --examples --features=esp32c6 --target riscv32imac-unknown-none-elf" -esp32s2 = "build --release --example=blinky --features=esp32s2 --target riscv32imc-unknown-none-elf" -esp32s3 = "build --release --example=blinky --features=esp32s3 --target riscv32imc-unknown-none-elf" +esp32s2 = "build --release --example=lp_blinky --features=esp32s2 --target riscv32imc-unknown-none-elf" +esp32s3 = "build --release --example=lp_blinky --features=esp32s3 --target riscv32imc-unknown-none-elf" [build] # target = "riscv32imc-unknown-none-elf" # ESP32-S2 + ESP32-S3 diff --git a/esp-lp-hal/Cargo.toml b/esp-lp-hal/Cargo.toml index 72db1c35d42..4f2854a9b39 100644 --- a/esp-lp-hal/Cargo.toml +++ b/esp-lp-hal/Cargo.toml @@ -73,15 +73,15 @@ embedded-hal = ["dep:embedded-hal", "dep:embedded-hal-nb"] embedded-io = ["dep:embedded-io"] [[example]] -name = "blinky" +name = "lp_blinky" required-features = ["embedded-hal-02"] [[example]] -name = "i2c" +name = "lp_i2c" required-features = ["embedded-hal-02", "esp32c6"] [[example]] -name = "uart" +name = "lp_uart" required-features = ["embedded-hal-02", "esp32c6"] [lints.rust] diff --git a/esp-lp-hal/examples/blinky.rs b/esp-lp-hal/examples/lp_blinky.rs similarity index 100% rename from esp-lp-hal/examples/blinky.rs rename to esp-lp-hal/examples/lp_blinky.rs diff --git a/esp-lp-hal/examples/i2c.rs b/esp-lp-hal/examples/lp_i2c.rs similarity index 100% rename from esp-lp-hal/examples/i2c.rs rename to esp-lp-hal/examples/lp_i2c.rs diff --git a/esp-lp-hal/examples/uart.rs b/esp-lp-hal/examples/lp_uart.rs similarity index 100% rename from esp-lp-hal/examples/uart.rs rename to esp-lp-hal/examples/lp_uart.rs diff --git a/examples/src/bin/lp_core_basic.rs b/examples/src/bin/lp_core_basic.rs index 81dc1a7a632..4e03e5e90f6 100644 --- a/examples/src/bin/lp_core_basic.rs +++ b/examples/src/bin/lp_core_basic.rs @@ -36,7 +36,7 @@ fn main() -> ! { // load code to LP core let lp_core_code = - load_lp_code!("../esp-lp-hal/target/riscv32imac-unknown-none-elf/release/examples/blinky"); + load_lp_code!("../target/riscv32imac-unknown-none-elf/release/examples/blinky"); // start LP core lp_core_code.run(&mut lp_core, LpCoreWakeupSource::HpCpu, lp_pin); diff --git a/examples/src/bin/lp_core_i2c.rs b/examples/src/bin/lp_core_i2c.rs index b285b4b172d..23724635f3f 100644 --- a/examples/src/bin/lp_core_i2c.rs +++ b/examples/src/bin/lp_core_i2c.rs @@ -41,7 +41,7 @@ fn main() -> ! { // load code to LP core let lp_core_code = - load_lp_code!("../esp-lp-hal/target/riscv32imac-unknown-none-elf/release/examples/i2c"); + load_lp_code!("../target/riscv32imac-unknown-none-elf/release/examples/lp_i2c"); // start LP core lp_core_code.run(&mut lp_core, LpCoreWakeupSource::HpCpu, lp_i2c); diff --git a/examples/src/bin/lp_core_uart.rs b/examples/src/bin/lp_core_uart.rs index df795db9682..7604703c62c 100644 --- a/examples/src/bin/lp_core_uart.rs +++ b/examples/src/bin/lp_core_uart.rs @@ -59,7 +59,7 @@ fn main() -> ! { // Load code to LP core: let lp_core_code = - load_lp_code!("../esp-lp-hal/target/riscv32imac-unknown-none-elf/release/examples/uart"); + load_lp_code!("../target/riscv32imac-unknown-none-elf/release/examples/lp_uart"); // Start LP core: lp_core_code.run(&mut lp_core, LpCoreWakeupSource::HpCpu, lp_uart); diff --git a/examples/src/bin/ulp_riscv_core_basic.rs b/examples/src/bin/ulp_riscv_core_basic.rs index 578e7e6a31d..63955dd712f 100644 --- a/examples/src/bin/ulp_riscv_core_basic.rs +++ b/examples/src/bin/ulp_riscv_core_basic.rs @@ -37,7 +37,7 @@ fn main() -> ! { // load code to LP core let lp_core_code = - load_lp_code!("../esp-lp-hal/target/riscv32imc-unknown-none-elf/release/examples/blinky"); + load_lp_code!("../target/riscv32imc-unknown-none-elf/release/examples/lp_blinky"); // start LP core lp_core_code.run(&mut ulp_core, ulp_core::UlpCoreWakeupSource::HpCpu, pin); From 7438e6771bb75cf4d8b9a7baef617ad540ce95c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 29 Aug 2024 16:07:04 +0200 Subject: [PATCH 09/11] Always create doc directory first --- examples/src/bin/lp_core_basic.rs | 2 +- xtask/src/main.rs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/src/bin/lp_core_basic.rs b/examples/src/bin/lp_core_basic.rs index 4e03e5e90f6..f41f96906ff 100644 --- a/examples/src/bin/lp_core_basic.rs +++ b/examples/src/bin/lp_core_basic.rs @@ -36,7 +36,7 @@ fn main() -> ! { // load code to LP core let lp_core_code = - load_lp_code!("../target/riscv32imac-unknown-none-elf/release/examples/blinky"); + load_lp_code!("../target/riscv32imac-unknown-none-elf/release/examples/lp_blinky"); // start LP core lp_core_code.run(&mut lp_core, LpCoreWakeupSource::HpCpu, lp_pin); diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 4317ccba2e0..21436a92b13 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -332,6 +332,9 @@ fn build_documentation(workspace: &Path, args: BuildDocumentationArgs) -> Result let output_path = workspace.join("docs"); let resources = workspace.join("resources"); + fs::create_dir_all(&output_path) + .with_context(|| format!("Failed to create {}", output_path.display()))?; + let mut packages = HashMap::new(); for package in args.packages { packages.insert( From b6da9b7536d57f29bbbb6ccdd98b9cbc444aeec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 29 Aug 2024 16:20:18 +0200 Subject: [PATCH 10/11] Revert r-a --- .vscode/settings.json.example | 25 ------------------- Cargo.toml | 17 +++---------- esp-lp-hal/.cargo/config.toml | 4 +-- esp-lp-hal/Cargo.toml | 6 ++--- .../examples/{lp_blinky.rs => blinky.rs} | 0 esp-lp-hal/examples/{lp_i2c.rs => i2c.rs} | 0 esp-lp-hal/examples/{lp_uart.rs => uart.rs} | 0 examples/Cargo.toml | 9 +++++++ examples/src/bin/lp_core_basic.rs | 2 +- examples/src/bin/lp_core_i2c.rs | 2 +- examples/src/bin/lp_core_uart.rs | 2 +- examples/src/bin/ulp_riscv_core_basic.rs | 2 +- xtask/src/lib.rs | 4 +-- 13 files changed, 23 insertions(+), 50 deletions(-) delete mode 100644 .vscode/settings.json.example rename esp-lp-hal/examples/{lp_blinky.rs => blinky.rs} (100%) rename esp-lp-hal/examples/{lp_i2c.rs => i2c.rs} (100%) rename esp-lp-hal/examples/{lp_uart.rs => uart.rs} (100%) diff --git a/.vscode/settings.json.example b/.vscode/settings.json.example deleted file mode 100644 index fe35ce53bc1..00000000000 --- a/.vscode/settings.json.example +++ /dev/null @@ -1,25 +0,0 @@ -{ - // These are recommended settings. - // Should you wish to disable rust-analyzer, you can replace all of this with - // `"rust-analyzer.files.excludeDirs": ["."]`. - // You can also omit all this, but that will cause r-a to try - // (and after a long while, fail) initializing. - // Note that we are not telling rust-analyzer to use an embedded target. - // This results in a few pointer width related errors, but it also means r-a is able - // to cope with xtask and its dependencies. - "rust-analyzer.cargo.allTargets": false, - "rust-analyzer.cargo.targetDir": "target/rust-analyzer", - "rust-analyzer.procMacro.attributes.enable": false, - "rust-analyzer.cargo.features": [ - "esp32c6", - "esp-hal/async", - "esp-hal/log", - "esp-hal-procmacros/has-lp-core", - "esp-backtrace/println", - "esp-backtrace/panic-handler", - "esp-backtrace/exception-handler", - "esp-println/uart", - "esp-println/log", - ], - "editor.formatOnSave": true, -} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 6938bc8589f..a7c4172d717 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,11 @@ [workspace] resolver = "2" -members = [ - "xtask", - "esp-hal", +members = ["xtask"] +exclude = [ "esp-alloc", "esp-backtrace", "esp-build", + "esp-hal", "esp-hal-embassy", "esp-hal-procmacros", "esp-hal-smartled", @@ -20,19 +20,8 @@ members = [ "extras/bench-server", "extras/esp-wifishark", "extras/ieee802154-sniffer", -] -exclude = [ "hil-test", "xtensa-lx", "xtensa-lx-rt", "xtensa-lx-rt/procmacros", ] - -[profile.release] -codegen-units = 1 -debug = 2 -debug-assertions = false -incremental = false -opt-level = 3 -lto = 'fat' -overflow-checks = false diff --git a/esp-lp-hal/.cargo/config.toml b/esp-lp-hal/.cargo/config.toml index 62bc6838311..3cf0f9207b6 100644 --- a/esp-lp-hal/.cargo/config.toml +++ b/esp-lp-hal/.cargo/config.toml @@ -1,7 +1,7 @@ [alias] esp32c6 = "build --release --examples --features=esp32c6 --target riscv32imac-unknown-none-elf" -esp32s2 = "build --release --example=lp_blinky --features=esp32s2 --target riscv32imc-unknown-none-elf" -esp32s3 = "build --release --example=lp_blinky --features=esp32s3 --target riscv32imc-unknown-none-elf" +esp32s2 = "build --release --example=blinky --features=esp32s2 --target riscv32imc-unknown-none-elf" +esp32s3 = "build --release --example=blinky --features=esp32s3 --target riscv32imc-unknown-none-elf" [build] # target = "riscv32imc-unknown-none-elf" # ESP32-S2 + ESP32-S3 diff --git a/esp-lp-hal/Cargo.toml b/esp-lp-hal/Cargo.toml index 4f2854a9b39..72db1c35d42 100644 --- a/esp-lp-hal/Cargo.toml +++ b/esp-lp-hal/Cargo.toml @@ -73,15 +73,15 @@ embedded-hal = ["dep:embedded-hal", "dep:embedded-hal-nb"] embedded-io = ["dep:embedded-io"] [[example]] -name = "lp_blinky" +name = "blinky" required-features = ["embedded-hal-02"] [[example]] -name = "lp_i2c" +name = "i2c" required-features = ["embedded-hal-02", "esp32c6"] [[example]] -name = "lp_uart" +name = "uart" required-features = ["embedded-hal-02", "esp32c6"] [lints.rust] diff --git a/esp-lp-hal/examples/lp_blinky.rs b/esp-lp-hal/examples/blinky.rs similarity index 100% rename from esp-lp-hal/examples/lp_blinky.rs rename to esp-lp-hal/examples/blinky.rs diff --git a/esp-lp-hal/examples/lp_i2c.rs b/esp-lp-hal/examples/i2c.rs similarity index 100% rename from esp-lp-hal/examples/lp_i2c.rs rename to esp-lp-hal/examples/i2c.rs diff --git a/esp-lp-hal/examples/lp_uart.rs b/esp-lp-hal/examples/uart.rs similarity index 100% rename from esp-lp-hal/examples/lp_uart.rs rename to esp-lp-hal/examples/uart.rs diff --git a/examples/Cargo.toml b/examples/Cargo.toml index f06e7465459..c05bee62d00 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -80,3 +80,12 @@ embassy-generic-timers = ["embassy-time/generic-queue-8"] opsram-2m = ["esp-hal/opsram-2m"] psram-2m = ["esp-hal/psram-2m"] + +[profile.release] +codegen-units = 1 +debug = 2 +debug-assertions = false +incremental = false +opt-level = 3 +lto = 'fat' +overflow-checks = false diff --git a/examples/src/bin/lp_core_basic.rs b/examples/src/bin/lp_core_basic.rs index f41f96906ff..81dc1a7a632 100644 --- a/examples/src/bin/lp_core_basic.rs +++ b/examples/src/bin/lp_core_basic.rs @@ -36,7 +36,7 @@ fn main() -> ! { // load code to LP core let lp_core_code = - load_lp_code!("../target/riscv32imac-unknown-none-elf/release/examples/lp_blinky"); + load_lp_code!("../esp-lp-hal/target/riscv32imac-unknown-none-elf/release/examples/blinky"); // start LP core lp_core_code.run(&mut lp_core, LpCoreWakeupSource::HpCpu, lp_pin); diff --git a/examples/src/bin/lp_core_i2c.rs b/examples/src/bin/lp_core_i2c.rs index 23724635f3f..b285b4b172d 100644 --- a/examples/src/bin/lp_core_i2c.rs +++ b/examples/src/bin/lp_core_i2c.rs @@ -41,7 +41,7 @@ fn main() -> ! { // load code to LP core let lp_core_code = - load_lp_code!("../target/riscv32imac-unknown-none-elf/release/examples/lp_i2c"); + load_lp_code!("../esp-lp-hal/target/riscv32imac-unknown-none-elf/release/examples/i2c"); // start LP core lp_core_code.run(&mut lp_core, LpCoreWakeupSource::HpCpu, lp_i2c); diff --git a/examples/src/bin/lp_core_uart.rs b/examples/src/bin/lp_core_uart.rs index 7604703c62c..df795db9682 100644 --- a/examples/src/bin/lp_core_uart.rs +++ b/examples/src/bin/lp_core_uart.rs @@ -59,7 +59,7 @@ fn main() -> ! { // Load code to LP core: let lp_core_code = - load_lp_code!("../target/riscv32imac-unknown-none-elf/release/examples/lp_uart"); + load_lp_code!("../esp-lp-hal/target/riscv32imac-unknown-none-elf/release/examples/uart"); // Start LP core: lp_core_code.run(&mut lp_core, LpCoreWakeupSource::HpCpu, lp_uart); diff --git a/examples/src/bin/ulp_riscv_core_basic.rs b/examples/src/bin/ulp_riscv_core_basic.rs index 63955dd712f..578e7e6a31d 100644 --- a/examples/src/bin/ulp_riscv_core_basic.rs +++ b/examples/src/bin/ulp_riscv_core_basic.rs @@ -37,7 +37,7 @@ fn main() -> ! { // load code to LP core let lp_core_code = - load_lp_code!("../target/riscv32imc-unknown-none-elf/release/examples/lp_blinky"); + load_lp_code!("../esp-lp-hal/target/riscv32imc-unknown-none-elf/release/examples/blinky"); // start LP core lp_core_code.run(&mut ulp_core, ulp_core::UlpCoreWakeupSource::HpCpu, pin); diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 61fed2aede9..6eb98fcbd89 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -144,10 +144,10 @@ pub fn build_documentation( let docs_path = windows_safe_path( &workspace + .join(package.to_string()) .join("target") .join(target) - .join("doc") - .join(package.to_string().replace('-', "_")), + .join("doc"), ); Ok(docs_path) From 21a9bed69a78988feaad292de4b8a2465a39b460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Fri, 30 Aug 2024 12:49:48 +0200 Subject: [PATCH 11/11] Update esp-hal-procmacros/src/lp_core.rs Co-authored-by: Dominic Fischer <14130965+Dominaezzz@users.noreply.github.com> --- esp-hal-procmacros/src/lp_core.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp-hal-procmacros/src/lp_core.rs b/esp-hal-procmacros/src/lp_core.rs index 98915ddc0e5..5fa639d7e92 100644 --- a/esp-hal-procmacros/src/lp_core.rs +++ b/esp-hal-procmacros/src/lp_core.rs @@ -33,7 +33,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { pub(crate) fn get_simplename(t: &Type) -> String { match t { - Type::Path(p) => String::from(&p.path.segments.last().unwrap().ident.to_string()), + Type::Path(p) => p.path.segments.last().unwrap().ident.to_string(), _ => String::new(), } }