Skip to content

Commit

Permalink
Revert "Revert "Update to new crates; simplify advanced options""
Browse files Browse the repository at this point in the history
This reverts commit 574e57b.
  • Loading branch information
ivmarkov committed Oct 17, 2023
1 parent 574e57b commit 15062de
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 94 deletions.
36 changes: 14 additions & 22 deletions cargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name = "{{project-name}}"
version = "0.1.0"
authors = ["{{authors}}"]
edition = "2021"
resolver = "2"
rust-version = "1.66"
rust-version = "1.71"

[profile.release]
opt-level = "s"
Expand All @@ -13,32 +12,25 @@ opt-level = "s"
debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"

{% if hal %}
[features]
{% if std and hal == "Yes (default features)" %}
default = ["std", "hal", "esp-idf-sys/native"]
{% elsif std and hal == "Yes (all features)" %}
default = ["all", "hal", "esp-idf-sys/native"]
{% elsif std %}
default = ["std", "esp-idf-sys/native"]
{% if std %}
default = ["std", "embassy", "esp-idf-sys/native"]
{% else %}
default = ["esp-idf-sys/native", "esp-idf-sys/panic_handler", "esp-idf-sys/alloc_handler", "esp-idf-sys/libstart"]
default = ["alloc", "embassy", "esp-idf-svc/native", "esp-idf-svc/panic_handler", "esp-idf-svc/alloc_handler", "esp-idf-svc/libstart"]
{% endif %}

pio = ["esp-idf-sys/pio"]
all = ["std", "nightly", "experimental", "embassy"]
hal = ["esp-idf-hal", "embedded-svc", "esp-idf-svc"]
std = ["alloc", "esp-idf-sys/std", "esp-idf-sys/binstart", "embedded-svc?/std", "esp-idf-hal?/std", "esp-idf-svc?/std"]
alloc = ["embedded-svc?/alloc", "esp-idf-hal?/alloc", "esp-idf-svc?/alloc"]
nightly = ["embedded-svc?/nightly", "esp-idf-svc?/nightly"] # Future: "esp-idf-hal?/nightly"
experimental = ["embedded-svc?/experimental", "esp-idf-svc?/experimental"]
embassy = ["esp-idf-hal?/embassy-sync", "esp-idf-hal?/critical-section", "esp-idf-hal?/edge-executor", "esp-idf-svc?/embassy-time-driver", "esp-idf-svc?/embassy-time-isr-queue"]
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]
log = { version = "0.4.17", default-features = false }
esp-idf-sys = { version = "0.33", default-features = false }
esp-idf-hal = { version = "0.41", optional = true, default-features = false }
esp-idf-svc = { version = "0.46", optional = true, default-features = false }
embedded-svc = { version = "0.25", optional = true, default-features = false }
esp-idf-svc = { version = "0.47", default-features = false }

[build-dependencies]
embuild = "0.31.2"
embuild = "0.31.3"
{% endif %}
9 changes: 4 additions & 5 deletions cargo/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Necessary because of this issue: https://github.com/rust-lang/cargo/issues/9641
fn main() -> Result<(), Box<dyn std::error::Error>> {
embuild::build::CfgArgs::output_propagated("ESP_IDF")?;
embuild::build::LinkArgs::output_propagated("ESP_IDF")?;
Ok(())
{%- if hal %}
fn main() {
embuild::espidf::sysenv::output();
}
{%- endif %}
13 changes: 6 additions & 7 deletions cargo/cargo-generate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ type = "bool"
prompt = "Configure advanced template options?"
default = false

[conditional.'advanced'.placeholders.std]
[conditional.'advanced'.placeholders.hal]
type = "bool"
prompt = "Enable HAL support?"
default = true

[conditional.'hal'.placeholders.std]
type = "bool"
prompt = "Enable STD support?"
default = true
Expand All @@ -43,12 +48,6 @@ type = "bool"
prompt = "Configure project to support Wokwi simulation with Wokwi VS Code extension?"
default = false

[conditional.'std'.placeholders.hal]
type = "string"
prompt = "Include esp-idf-hal/esp-idf-svc?"
choices = ["No", "Yes (default features)", "Yes (all features)"]
default = "Yes (default features)"

[conditional.'advanced'.placeholders.ci]
type = "bool"
prompt = "Add CI files for GitHub Action?"
Expand Down
2 changes: 1 addition & 1 deletion cargo/pre-script.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ for key in target_properties.keys() {

let advanced = variable::get("advanced");
if !advanced {
variable::set("hal", true);
variable::set("std", true);
if target == "esp32" || target == "esp32s2" || target == "esp32s3" || target == "esp32c3" {
variable::set("espidfver", "v4.4");
Expand All @@ -60,5 +61,4 @@ if !advanced {
}
variable::set("devcontainer", false);
variable::set("wokwi", false);
variable::set("hal", "Yes (default features)");
}
2 changes: 1 addition & 1 deletion cargo/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Rust often needs a bit of an extra main task stack size compared to C (the default is 3K)
CONFIG_ESP_MAIN_TASK_STACK_SIZE=7000
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8000

# Use this to set FreeRTOS kernel tick frequency to 1000 Hz (100 Hz by default).
# This allows to use 1 ms granuality for thread sleeps (10 ms by default).
Expand Down
20 changes: 10 additions & 10 deletions cargo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
#![no_std]
#![no_main]
{% endunless -%}
use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported
{%- if std and hal != "No" %}
use log::*;
{% endif %}

{%- if hal %}
{%- unless std %}
#[no_mangle]
{%- endunless %}
fn main() {
// It is necessary to call this function once. Otherwise some patches to the runtime
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
esp_idf_sys::link_patches();
{%- if std and hal == "No" %}
println!("Hello, world!");
{%- elsif std and hal != "No" %}
esp_idf_svc::sys::link_patches();

// Bind the log crate to the ESP Logging facilities
esp_idf_svc::log::EspLogger::initialize_default();

info!("Hello, world!");
{%- endif %}
log::info!("Hello, world!");
}
{%- else %}
#[no_mangle]
extern "C" fn app_main() -> i32 {
42
}
{%- endif %}
25 changes: 21 additions & 4 deletions cmake/cargo-generate.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
[template]
cargo_generate_version = ">=0.10.0"
cargo_generate_version = ">=0.17.4"

[placeholders]
toolchain = { type = "string", prompt = "Rust toolchain (beware: nightly works only for esp32c3!)", choices = ["esp", "nightly"], default = "esp" }
std = { type = "bool", prompt = "STD support", default = true }
[placeholders.advanced]
type = "bool"
prompt = "Configure advanced template options?"
default = false

[conditional.'advanced'.placeholders.toolchain]
type = "string"
prompt = "Rust toolchain (beware: nightly works only for riscv MCUs!)"
choices = ["esp", "nightly"]
default = "esp"

[conditional.'advanced'.placeholders.hal]
type = "bool"
prompt = "Enable HAL support?"
default = true

[conditional.'advanced'.placeholders.std]
type = "bool"
prompt = "Enable STD support?"
default = true
36 changes: 14 additions & 22 deletions cmake/components/rust-{{project-name}}/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name = "rust-{{project-name}}"
version = "0.1.0"
authors = ["{{authors}}"]
edition = "2021"
resolver = "2"
rust-version = "1.66"
rust-version = "1.71"

[lib]
crate-type = ["staticlib"]
Expand All @@ -16,32 +15,25 @@ opt-level = "s"
debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"

{% if hal %}
[features]
{% if std and hal == "Yes (default features)" %}
default = ["std", "hal", "esp-idf-sys/native"]
{% elsif std and hal == "Yes (all features)" %}
default = ["all", "hal", "esp-idf-sys/native"]
{% elsif std %}
default = ["std", "esp-idf-sys/native"]
{% if std %}
default = ["std", "embassy", "esp-idf-sys/native"]
{% else %}
default = ["esp-idf-sys/native", "esp-idf-sys/panic_handler", "esp-idf-sys/alloc_handler"]
default = ["alloc", "embassy", "esp-idf-svc/native", "esp-idf-svc/panic_handler", "esp-idf-svc/alloc_handler", "esp-idf-svc/libstart"]
{% endif %}

pio = ["esp-idf-sys/pio"]
all = ["std", "nightly", "experimental", "embassy"]
hal = ["esp-idf-hal", "embedded-svc", "esp-idf-svc"]
std = ["alloc", "esp-idf-sys/std", "embedded-svc?/std", "esp-idf-hal?/std", "esp-idf-svc?/std"]
alloc = ["embedded-svc?/alloc", "esp-idf-hal?/alloc", "esp-idf-svc?/alloc"]
nightly = ["embedded-svc?/nightly", "esp-idf-svc?/nightly"] # Future: "esp-idf-hal?/nightly"
experimental = ["embedded-svc?/experimental", "esp-idf-svc?/experimental"]
embassy = ["esp-idf-hal?/embassy-sync", "esp-idf-hal?/critical-section", "esp-idf-hal?/edge-executor", "esp-idf-svc?/embassy-time-driver", "esp-idf-svc?/embassy-time-isr-queue"]
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]
log = { version = "0.4.17", default-features = false }
esp-idf-sys = { version = "0.33", default-features = false }
esp-idf-hal = { version = "0.41", optional = true, default-features = false }
esp-idf-svc = { version = "0.46", optional = true, default-features = false }
embedded-svc = { version = "0.25", optional = true, default-features = false }
esp-idf-svc = { version = "0.47", default-features = false }

[build-dependencies]
embuild = "0.31.2"
embuild = "0.31.3"
{% endif %}
8 changes: 4 additions & 4 deletions cmake/components/rust-{{project-name}}/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Necessary because of this issue: https://github.com/rust-lang/cargo/issues/9641
fn main() -> Result<(), Box<dyn std::error::Error>> {
embuild::build::CfgArgs::output_propagated("ESP_IDF")?;
Ok(())
{%- if hal %}
fn main() {
embuild::espidf::sysenv::output();
}
{%- endif %}
10 changes: 5 additions & 5 deletions cmake/components/rust-{{project-name}}/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[toolchain]
{% if toolchain == "esp" %}
channel = "esp"
{% endif %}
{% if toolchain == "nightly" %}
{% if arch == "riscv" -%}
channel = "nightly"
{% endif %}
components = ["rust-src"]
{% else -%}
channel = "esp"
{% endif %}
20 changes: 8 additions & 12 deletions cmake/components/rust-{{project-name}}/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
{% unless std -%}
#![no_std]
{% endunless -%}
use esp_idf_sys as _; // If using the `libstart` feature of `esp-idf-sys`, always keep this module imported
{%- if std and hal != "No" %}
use log::*;
{% endif %}

#[no_mangle]
extern "C" fn rust_main() -> i32 {
// Temporary. Will disappear once ESP-IDF 4.4 is released, but for now it is necessary to call this function once,
// or else some patches to the runtime implemented by esp-idf-sys might not link properly.
esp_idf_sys::link_patches();
{%- if std and hal == "No" %}
println!("Hello world from Rust!");
{%- elsif std and hal != "No" %}
{%- if hal %}
// It is necessary to call this function once. Otherwise some patches to the runtime
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
esp_idf_svc::sys::link_patches();

// Bind the log crate to the ESP Logging facilities
esp_idf_svc::log::EspLogger::initialize_default();

info!("Hello world from Rust!");
log::info!("Hello, world!");
{%- elif std %}
println!("Hello, world from Rust!");
{%- endif %}

42
}
2 changes: 1 addition & 1 deletion cmake/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Rust often needs a bit of an extra main task stack size compared to C (the default is 3K)
CONFIG_ESP_MAIN_TASK_STACK_SIZE=7000
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8000

# Workaround for https://github.com/espressif/esp-idf/issues/7631
#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=n
Expand Down

0 comments on commit 15062de

Please sign in to comment.