Skip to content

Commit

Permalink
else-if
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Feb 10, 2025
1 parent 01378f1 commit 1487046
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 26 deletions.
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,15 @@ fn process_file(
};
let res = engine.eval::<bool>(cond).unwrap();
include.push(res && *include.last().unwrap());
} else if trimmed.starts_with("#ELIF ") || trimmed.starts_with("//ELIF ") {
let cond = if trimmed.starts_with("#ELIF ") {
trimmed.strip_prefix("#ELIF ").unwrap()
} else {
trimmed.strip_prefix("//ELIF ").unwrap()
};
let res = engine.eval::<bool>(cond).unwrap();
let last = include.pop();
include.push(res && !last.unwrap());
} else if trimmed.starts_with("#ELSE") || trimmed.starts_with("//ELSE") {
let res = !*include.last().unwrap();
include.pop();
Expand Down
3 changes: 1 addition & 2 deletions template/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ ESP_LOG="INFO"
rustflags = [
#IF option("xtensa")
"-C", "link-arg=-nostartfiles",
#ENDIF
#IF option("riscv")
#ELIF option("riscv")
# Required to obtain backtraces (e.g. when using the "esp-backtrace" crate.)
# NOTE: May negatively impact performance of produced code
"-C", "force-frame-pointers",
Expand Down
25 changes: 14 additions & 11 deletions template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,37 @@ name = "project-name"
path = "./src/bin/main.rs"

[dependencies]
#IF option("panic-esp-backtrace")
esp-backtrace = { version = "0.15.0", features = [
#REPLACE esp32c6 mcu
"esp32c6",
"exception-handler",
"panic-handler",
#IF option("probe-rs")
#IF option("log-frontend-defmt")
#+"defmt",
#ELSE
"println",
#ENDIF
]}
#ENDIF
esp-hal = { version = "0.23.1", features = [
#REPLACE esp32c6 mcu
"esp32c6",
"unstable",
#IF option("probe-rs")
#IF option("log-frontend-defmt")
#+"defmt",
#ENDIF
] }
#IF !option("probe-rs")
#IF option("log-backend-esp-println")
#REPLACE esp32c6 mcu
esp-println = { version = "0.13.0", features = ["esp32c6", "log"] }
#ELIF option("log-backend-defmt-rtt")
#+defmt-rtt = "0.4.1"
#ENDIF
#IF option("log-frontend-log")
log = { version = "0.4.21" }
#ELIF option("log-frontend-defmt")
#+defmt = "0.3.10"
#ENDIF
#IF option("alloc")
esp-alloc = { version = "0.6.0" }
Expand All @@ -59,10 +67,9 @@ esp-wifi = { version = "0.12.0", default-features=false, features = [
"coex",
#ENDIF
"esp-alloc",
#IF option("probe-rs")
#IF option("log-frontend-defmt")
#+"defmt",
#ENDIF
#IF !option("probe-rs")
#ELIF option("log-frontend-log")
"log",
#ENDIF
] }
Expand All @@ -86,14 +93,10 @@ smoltcp = { version = "0.12.0", default-features = false, features = [
#IF option("ble")
#+bleps = { git = "https://github.com/bjoernQ/bleps", package = "bleps", rev = "a5148d8ae679e021b78f53fd33afb8bb35d0b62e", features = [ "macros", "async"] }
#ENDIF
#IF option("probe-rs")
#+defmt = "0.3.10"
#+defmt-rtt = "0.4.1"
#ENDIF
#IF option("embassy")
embassy-executor = { version = "0.7.0", features = [
"task-arena-size-20480",
#IF option("probe-rs")
#IF option("log-frontend-defmt")
"defmt"
#ENDIF
] }
Expand Down
2 changes: 1 addition & 1 deletion template/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
linker_be_nice();
//IF option("probe-rs")
//IF option("log-frontend-defmt")
println!("cargo:rustc-link-arg=-Tdefmt.x");
//ENDIF
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
Expand Down
3 changes: 1 addition & 2 deletions template/rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ channel = "stable"
components = ["rust-src"]
#REPLACE riscv32imac-unknown-none-elf rust_target
targets = ["riscv32imac-unknown-none-elf"]
#ENDIF
#IF option("xtensa")
#ELIF option("xtensa")
#+channel = "esp"
#ENDIF
11 changes: 5 additions & 6 deletions template/src/bin/async_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use esp_hal::clock::CpuClock;
//IF option("probe-rs")
//+ use defmt_rtt as _;
//+ use defmt::info;
//ENDIF
//IF !option("probe-rs")
//ELSE
use log::info;
//ENDIF

Expand All @@ -24,17 +23,17 @@ async fn main(spawner: Spawner) {
//REPLACE generate-version generate-version
// generator version: generate-version

//IF !option("probe-rs")
esp_println::logger::init_logger_from_env();
//ENDIF

let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);

//IF option("alloc")
esp_alloc::heap_allocator!(72 * 1024);
//ENDIF

//IF !option("probe-rs")
esp_println::logger::init_logger_from_env();
//ENDIF

//IF !option("esp32")
let timer0 = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(timer0.alarm0);
Expand Down
8 changes: 4 additions & 4 deletions template/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ fn main() -> ! {
//REPLACE generate-version generate-version
// generator version: generate-version

//IF !option("probe-rs")
esp_println::logger::init_logger_from_env();
//ENDIF

let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
//IF option("wifi") || option("ble")
let peripherals = esp_hal::init(config);
//ELSE
//+let _peripherals = esp_hal::init(config);
//ENDIF

//IF !option("probe-rs")
esp_println::logger::init_logger_from_env();
//ENDIF

//IF option("alloc")
esp_alloc::heap_allocator!(72 * 1024);
//ENDIF
Expand Down

0 comments on commit 1487046

Please sign in to comment.