Skip to content

Commit

Permalink
Host (and ESP-IDF) build; less memory usage; edge_nal::TcpConnect i…
Browse files Browse the repository at this point in the history
…mpl (#59)

* (WIP) Host and ESP-IDF build

* (WIP) Host and ESP-IDF build

* Move the mbedtls submodule inside esp-mbedtls-sys or else cargo publish won't work

* xtask buildable

* Remove targets dir from xtask; fix a bug where sys was constantly rebuilt

* WIP - debugging and getting it to run

* WIP - no extra buffers

* No extra buffer works (tested on host only)

* Compatibility with ESP-IDF

* Compatibility with ESP-IDF

* WIP: Baremetal build

* Baremetal build works

* Rename Crypto to Tls; examples build again

* Make the examples deps all optional, or else the root workspace does not build on non-baremetal

* New example: crypto_self_test_std (timings for host and ESP-IDF)

* Documentation; Rename token to tls_ref

* Fix the build artefacts for RiscV; implement alignment checker

* Fix the build for MbedTLS 3.4 which does not recognize MBEDTLS_CONFIG_FILE

* cargo fmt; build

* Add crypto-self-test examples

* Test build for ESP IDF too

* Need to init the mbedtls submodule

* Temporarly comment out the ESP IDF task until I grok justfile

* Temporarly comment out the ESP IDF task until I grok justfile

* A fix for MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET in mbedtls versions < 3.6

* Depending on a custom version of cmake-rs is no longer necessary

* Fix sync coce not working

* fmt

* Enable debug on xtensa; rebuild baremetal libs

* fmt

* Raise MSRV to 1.82; put license key in all Cargo.toml files

* Handle stream EOF
  • Loading branch information
ivmarkov authored Dec 24, 2024
1 parent d5e29f8 commit 1431835
Show file tree
Hide file tree
Showing 91 changed files with 7,048 additions and 1,698 deletions.
22 changes: 22 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
[build]
# Build on host
#target = "x86_64-unknown-linux-gnu"
# Build on target firmware with baremetal
#target = "xtensa-esp32-none-elf"
#target = "xtensa-esp32s2-none-elf"
#target = "xtensa-esp32s3-none-elf"
#target = "riscv32imc-unknown-none-elf"
# Build on target firmware with ESP IDF
#target = "xtensa-esp32-espidf"
#target = "xtensa-esp32s2-espidf"
#target = "xtensa-esp32s3-espidf"
#target = "riscv32imc-esp-espidf"

[target.xtensa-esp32-none-elf]
runner = "espflash flash --monitor --baud 921600"

Expand Down Expand Up @@ -37,8 +51,16 @@ rustflags = [
"-C", "link-arg=-Trom_functions.x",
]

[target.'cfg(target_os = "espidf")']
linker = "ldproxy"
runner = "espflash flash --monitor"
rustflags = [ "--cfg", "espidf_time64"]

[unstable]
# Enable this when building for baremetal
build-std = ["core", "alloc"]
# Enable this when building on the host machine or for ESP-IDF
#build-std = ["std", "panic_abort"]

[alias]
xtask = "run --manifest-path ./xtask/Cargo.toml --"
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ jobs:
components: rust-src,rustfmt
- uses: esp-rs/xtensa-toolchain@v1.5
with:
ldproxy: false
ldproxy: true
override: false
- uses: Swatinem/rust-cache@v2
- uses: extractions/setup-just@v1
with:
just-version: 1.13.0

- name: mbedtls init
run: git submodule update --init --recursive

- name: check
run: just
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ Cargo.lock
# You should copy the template and not modify `settings.json`
.vscode/settings.json

.embuild

tmpsrc
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "mbedtls"]
path = mbedtls
path = esp-mbedtls-sys/mbedtls
url = https://github.com/espressif/mbedtls
104 changes: 52 additions & 52 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["bjoernQ <bjoern.quentin@mobile-j.de>"]
edition = "2021"
license = "MIT OR Apache-2.0"
rust-version = "1.75"
rust-version = "1.82"

[profile.release]
debug = true
Expand All @@ -16,19 +16,21 @@ opt-level = "s"
opt-level = 3

[profile.dev]
debug = true
lto = "fat"
opt-level = "z"

[profile.dev.package.esp-wifi]
opt-level = 3

[dependencies]
esp-hal = { version = "0.21.0" }
esp-backtrace = { version = "0.14.0", features = [
esp-hal = { version = "0.21.0", optional = true }
esp-backtrace = { version = "0.14.0", optional = true, features = [
"panic-handler",
"println",
"exception-handler",
] }
esp-println = { version = "0.12.0", features = ["log"] }
esp-println = { version = "0.12.0", optional = true, features = ["log"] }
esp-hal-embassy = { version = "0.4.0", optional = true }

embassy-time = { version = "0.3.0", optional = true }
Expand All @@ -43,9 +45,8 @@ embassy-net = { version = "0.4.0", features = [
"medium-ethernet",
], optional = true }


esp-wifi = { version = "0.10.1", features = ["phy-enable-usb", "wifi-default"] }
smoltcp = { version = "0.11.0", default-features = false, features = [
esp-wifi = { version = "0.10.1", optional = true, features = ["phy-enable-usb", "wifi-default", "sys-logs"] }
smoltcp = { version = "0.11.0", optional = true, default-features = false, features = [
"proto-igmp",
"proto-ipv4",
"socket-tcp",
Expand All @@ -58,7 +59,7 @@ smoltcp = { version = "0.11.0", default-features = false, features = [
] }
log = "0.4.16"
embedded-io = "0.6.1"
embedded-io-async = { version = "0.6.0", optional = true }
embedded-io-async = "0.6.0"
heapless = "0.8.0"
critical-section = "1.0.1"
static_cell = { version = "2.1", features = ["nightly"] }
Expand All @@ -69,91 +70,90 @@ edge-http = { version = "0.3.0", optional = true }
edge-nal = { version = "0.3.0", optional = true }
edge-nal-embassy = { version = "0.3.0", optional = true }
cfg-if = "1.0.0"
esp-alloc = "0.5.0"
esp-alloc = { version = "0.5.0", optional = true}
enumset = { version = "1", default-features = false }

[target.'cfg(target_os = "espidf")'.dependencies]
esp-idf-svc = { version = "0.49.1", features = ["binstart"] }

[[example]]
name = "crypto_self_test"
required-features = ["esp-wifi/sys-logs"]
required-features = ["examples"]

[[example]]
name = "crypto_self_test_std"

[[example]]
name = "async_client"
required-features = ["async"]
required-features = ["examples-async"]

[[example]]
name = "async_client_mTLS"
required-features = ["async"]
required-features = ["examples-async"]

[[example]]
name = "async_server"
required-features = ["async"]
required-features = ["examples-async"]

[[example]]
name = "async_server_mTLS"
required-features = ["async"]
required-features = ["examples-async"]

[[example]]
name = "edge_server"
required-features = ["async", "edge-server"]
required-features = ["examples-async", "edge-http"]

[features]
examples = ["esp-hal", "esp-backtrace", "esp-println", "esp-wifi", "smoltcp", "esp-alloc"]
examples-async = ["examples", "esp-hal-embassy", "embassy-time", "embassy-executor", "embassy-net", "edge-http", "edge-nal", "edge-nal-embassy", "esp-wifi/async", "esp-wifi/embassy-net", "esp-mbedtls/async", "esp-mbedtls/edge-nal"]
examples-std = ["critical-section/std"]

esp32 = [
"esp-hal/esp32",
"esp-hal?/esp32",
"esp-hal-embassy?/esp32",
"esp-backtrace/esp32",
"esp-println/esp32",
"esp-wifi/esp32",
"esp-backtrace?/esp32",
"esp-println?/esp32",
"esp-wifi?/esp32",
"esp-mbedtls/esp32",
]
esp32c3 = [
"esp-hal/esp32c3",
"esp-hal?/esp32c3",
"esp-hal-embassy?/esp32c3",
"esp-backtrace/esp32c3",
"esp-println/esp32c3",
"esp-wifi/esp32c3",
"esp-backtrace?/esp32c3",
"esp-println?/esp32c3",
"esp-wifi?/esp32c3",
"esp-mbedtls/esp32c3",
]
esp32s2 = [
"esp-hal/esp32s2",
"esp-hal?/esp32s2",
"esp-hal-embassy?/esp32s2",
"esp-backtrace/esp32s2",
"esp-println/esp32s2",
"esp-wifi/esp32s2",
"esp-backtrace?/esp32s2",
"esp-println?/esp32s2",
"esp-wifi?/esp32s2",
"esp-mbedtls/esp32s2",
]
esp32s3 = [
"esp-hal/esp32s3",
"esp-hal?/esp32s3",
"esp-hal-embassy?/esp32s3",
"esp-backtrace/esp32s3",
"esp-println/esp32s3",
"esp-wifi/esp32s3",
"esp-backtrace?/esp32s3",
"esp-println?/esp32s3",
"esp-wifi?/esp32s3",
"esp-mbedtls/esp32s3",
]
async = [
"esp-wifi/async",
"esp-wifi/embassy-net",
"embassy-executor",
"embassy-net",
"embassy-time",
"dep:embedded-io-async",
"esp-mbedtls/async",
"esp-hal-embassy",
]

# Helper feature to enable all dependencies required for edge-net
edge-server = [
"edge-nal",
"edge-nal-embassy",
"edge-http",
"esp-mbedtls/edge-nal",
]
[build-dependencies]
embuild = { version = "0.32", features = ["espidf"] }

# Patch until new release
[patch.crates-io]
edge-http = { git = "https://github.com/ivmarkov/edge-net", rev = "722f92ac0fffd0cb1e1ce76086cca58df6eb49ee" }
edge-nal = { git = "https://github.com/ivmarkov/edge-net", rev = "722f92ac0fffd0cb1e1ce76086cca58df6eb49ee" }
edge-nal-embassy = { git = "https://github.com/ivmarkov/edge-net", rev = "722f92ac0fffd0cb1e1ce76086cca58df6eb49ee" }
edge-http = { git = "https://github.com/ivmarkov/edge-net" }
edge-nal = { git = "https://github.com/ivmarkov/edge-net" }
edge-nal-embassy = { git = "https://github.com/ivmarkov/edge-net" }
esp-idf-svc = { git = "https://github.com/esp-rs/esp-idf-svc" }
esp-idf-hal = { git = "https://github.com/esp-rs/esp-idf-hal" }
esp-idf-sys = { git = "https://github.com/esp-rs/esp-idf-sys" }

# Patch before 0.6.0 got yanked
embassy-executor = { git = "https://github.com/embassy-rs/embassy", rev = "886580179ff250e15b0fad6448e8ebed6cdabf2b" }
embassy-time-driver = { git = "https://github.com/embassy-rs/embassy", rev = "886580179ff250e15b0fad6448e8ebed6cdabf2b" }
embassy-time-queue-driver = { git = "https://github.com/embassy-rs/embassy", rev = "886580179ff250e15b0fad6448e8ebed6cdabf2b" }
embassy-time-queue-driver = { git = "https://github.com/embassy-rs/embassy", rev = "886580179ff250e15b0fad6448e8ebed6cdabf2b" }
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
if std::env::var("CARGO_CFG_TARGET_OS").unwrap().as_str() == "espidf" {
embuild::espidf::sysenv::output();
}
}
31 changes: 25 additions & 6 deletions esp-mbedtls-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,36 @@
name = "esp-mbedtls-sys"
version = "0.1.0"
edition = "2021"
links = "mbedtls"
license = "MIT OR Apache-2.0"
rust-version = "1.82"

[build-dependencies]
anyhow = "1.0.68"
anyhow = "1.0.68"
bindgen = "0.68.1"
env_logger = "0.10.0"
log = "0.4.17"
cmake = "0.1.52"
fs_extra = "1.3.0"
embuild = "0.32"

[dependencies]
# For malloc/free
# TODO: Replace with `esp-alloc` once `esp-alloc` starts to provide `malloc` and `free` in future
# ... or switch to our own `mbedtls_malloc/free`
esp-wifi = { version = "0.10.1", default-features = false, optional = true }

# ESP-IDF: The mbedtls lib distributed with ESP-IDF is used
[target.'cfg(target_os = "espidf")'.dependencies]
esp-idf-sys = { version = "0.35", default-features = false }

# All other platforms: mbedtls libs and bindings are created on the fly

[features]
default = []

# Exactly *one* chip MUST be selected via its feature:
esp32 = []
esp32c3 = []
esp32s2 = []
esp32s3 = []
# ESP-HAL: Exactly *one* chip MUST be selected via its feature:
esp32 = ["esp-wifi/esp32"]
esp32c3 = ["esp-wifi/esp32c3"]
esp32s2 = ["esp-wifi/esp32s2"]
esp32s3 = ["esp-wifi/esp32s3"]
Loading

0 comments on commit 1431835

Please sign in to comment.