Skip to content

Commit 793f7bd

Browse files
ivmarkovAnthonyGrondingithub-actions[bot]
authored
Large Refactoring (#95)
* wip: Share parsed `mbedtls_x509_crt` and `mbedtls_pk_context` between sessions * feat: Add no-copy support for X509 parsing. Expose auth_mode parameter - Session now exposes an optional `auth_mode` parameter to select the certificate verification mode. - Update Certificates to handle no-copy variants of certificates parsing. - Add DER certificates for testing no-copy variants * refactor: Use struct to pass configuration to a session * feat: Expose parsed X509 certificates and add extra impls to generated bindings * fix: Improve lifetime management for Session certificates - Remove duplicate justfile step for faster building * refactor: Use `mbedtls_calloc()` and `mbedtls_free()` alias for memory management * feat: Make `Certificates` Send * chore: auto-push built libraries * refactor: Make `Certificates` take references * Unify everything into SessionConfig * Option to split the async session into a read and write halves * External rng; support for defmt * defmt * Make the async code non-optional * Split into modules * Move examples into their own crates; remove esp-hal dependencies from the examples; STD examples; testing and bugfixing * Streamline the error story; apply Clippy * New HAL-neutral HW-accel framework * Restore the workspace Cargo.toml and the xtask alias * esp - expmod * Re-export the sys crate * Make the build of esp-mbedtls-sys cpu-arch-specific but NOT mcu-specific * Move all hooking and HW accel to esp-mbedtls-sys * Move the self-tests to esp-mbedtls-sys * Update READMEs * Fix merr to return the non-negative result * Restore the crypto self tests on the esp32 chips (with HW accel) * Enlarge sha work area sizes for esp32 * Bugfixing * Reduce the accel installation noise * Fix software fallbacks for xtensa and riscv32 * Fix the exp_mod return type * esp server example * Unify the embassy_net bootstrapping code for all esp examples * Working esp server examples * Update certs and examples READMEs * Replace all mentions of OpenThread with MbedTLS * Install and run espup manually so that we enable the Espressif RISCV toolchain * Fix CI * Clippy * fmt; fix CI * Fix CI * Address code review comments * Rename a forgotten openthread mentioning * Fix a typo * Address review feedback * Do not allocate larger space for sha, because sha HW accel is not enabled for the esp32 anyway * Always build esp-hal with opt-level 3 as this affects HW accel --------- Co-authored-by: Anthony Grondin <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 35e8ccd commit 793f7bd

File tree

135 files changed

+59016
-57359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+59016
-57359
lines changed

.cargo/config.toml

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,2 @@
1-
[build]
2-
# Build on host
3-
#target = "x86_64-unknown-linux-gnu"
4-
# Build on target firmware with baremetal
5-
#target = "xtensa-esp32-none-elf"
6-
#target = "xtensa-esp32s2-none-elf"
7-
#target = "xtensa-esp32s3-none-elf"
8-
#target = "riscv32imc-unknown-none-elf"
9-
# Build on target firmware with ESP IDF
10-
#target = "xtensa-esp32-espidf"
11-
#target = "xtensa-esp32s2-espidf"
12-
#target = "xtensa-esp32s3-espidf"
13-
#target = "riscv32imc-esp-espidf"
14-
15-
[target.xtensa-esp32-none-elf]
16-
runner = "espflash flash --monitor --baud 921600"
17-
18-
rustflags = [
19-
"-C", "link-arg=-Tlinkall.x",
20-
"-C", "link-arg=-nostartfiles",
21-
]
22-
23-
[target.riscv32imc-unknown-none-elf]
24-
runner = "espflash flash --monitor --baud 921600"
25-
26-
rustflags = [
27-
"-C", "link-arg=-Tlinkall.x",
28-
29-
# Required to obtain backtraces (e.g. when using the "esp-backtrace" crate.)
30-
# NOTE: May negatively impact performance of produced code
31-
"-C", "force-frame-pointers",
32-
]
33-
34-
[target.riscv32imac-unknown-none-elf]
35-
runner = "espflash flash --monitor --baud 921600"
36-
37-
rustflags = [
38-
"-C", "link-arg=-Tlinkall.x",
39-
40-
# Required to obtain backtraces (e.g. when using the "esp-backtrace" crate.)
41-
# NOTE: May negatively impact performance of produced code
42-
"-C", "force-frame-pointers",
43-
]
44-
45-
[target.xtensa-esp32s2-none-elf]
46-
runner = "espflash flash --monitor --baud 921600"
47-
48-
rustflags = [
49-
#"-C", "linker=rust-lld",
50-
"-C", "link-arg=-Tlinkall.x",
51-
]
52-
53-
[target.xtensa-esp32s3-none-elf]
54-
runner = "espflash flash --monitor --baud 921600"
55-
56-
rustflags = [
57-
"-C", "link-arg=-Tlinkall.x",
58-
"-C", "link-arg=-nostartfiles",
59-
]
60-
61-
[target.'cfg(target_os = "espidf")']
62-
linker = "ldproxy"
63-
runner = "espflash flash --monitor"
64-
rustflags = [ "--cfg", "espidf_time64"]
65-
66-
[unstable]
67-
# Enable this when building for baremetal
68-
build-std = ["core", "alloc"]
69-
# Enable this when building on the host machine or for ESP-IDF
70-
#build-std = ["std", "panic_abort"]
71-
721
[alias]
732
xtask = "run --manifest-path ./xtask/Cargo.toml --"
74-
75-
76-
# Alias' for quickly building for different chips or running examples
77-
# By default we enable
78-
# - `default` HAL features to set up basic chip specific settings
79-
esp32 = "run --release --features esp32 --target xtensa-esp32-none-elf --features esp-hal/default"
80-
esp32s2 = "run --release --features esp32s2 --target xtensa-esp32s2-none-elf --features esp-hal/default"
81-
esp32s3 = "run --release --features esp32s3 --target xtensa-esp32s3-none-elf --features esp-hal/default"
82-
esp32c3 = "run --release --features esp32c3 --target riscv32imc-unknown-none-elf --features esp-hal/default"
83-
esp32c6 = "run --release --features esp32c6 --target riscv32imac-unknown-none-elf --features esp-hal/default"
84-
85-
besp32 = "build --release --features esp32 --target xtensa-esp32-none-elf --features esp-hal/default"
86-
besp32s2 = "build --release --features esp32s2 --target xtensa-esp32s2-none-elf --features esp-hal/default"
87-
besp32s3 = "build --release --features esp32s3 --target xtensa-esp32s3-none-elf --features esp-hal/default"
88-
besp32c3 = "build --release --features esp32c3 --target riscv32imc-unknown-none-elf --features esp-hal/default"
89-
besp32c6 = "build --release --features esp32c6 --target riscv32imac-unknown-none-elf --features esp-hal/default"

.github/workflows/ci.yml

Lines changed: 157 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# This CI optionally builds libraries and then builds examples against them.
1+
# This CI builds the `esp-mbedtls*` crates and their examples.
22
#
33
# If a change is detected within `esp-mbedtls-sys/`, a rebuild is triggered and this CI will automatically
44
# rebuild the libraries using the xtask. Then the tests are executed against the rebuilt libraries.
55
#
6-
# If no rebuild occurs, the tests are executed against the current libraries.
6+
# If no rebuild occurs, the examples are built against the latest libraries present in the main branch.
77
#
88
# The libraries are pushed on either of these conditions:
99
# 1. The PR is labelled with `rebuild-libs`.
@@ -12,7 +12,7 @@
1212
# When pushing a PR that would trigger a rebuild, the libraries get automatically
1313
# pushed to the main branch after successful testing.
1414

15-
name: Build (optional) and test examples
15+
name: CI
1616

1717
on:
1818
pull_request:
@@ -41,14 +41,12 @@ concurrency:
4141
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
4242

4343
jobs:
44-
build-test:
44+
build:
45+
name: Build
4546
runs-on: ubuntu-latest
4647
permissions: read-all
47-
outputs:
48-
upload-libs: ${{ steps.detect-changes.outputs.libs == 'true' }}
4948

5049
steps:
51-
# ==== Setup ====
5250
- uses: actions/checkout@v4
5351

5452
- name: mbedtls init
@@ -60,11 +58,57 @@ jobs:
6058
toolchain: stable
6159
components: rust-src,rustfmt
6260

63-
- uses: Swatinem/rust-cache@v2
61+
# TODO: Double-check and uncomment
62+
# - uses: Swatinem/rust-cache@v2
63+
# with:
64+
# workspaces: |
65+
# ./
66+
# xtask
67+
68+
- name: Fmt Check
69+
run: cargo fmt -- --check
70+
71+
- name: Clippy
72+
run: cargo clippy -- -D warnings
73+
74+
- name: Build
75+
run: cargo build
76+
77+
- name: Fmt Check - STD Examples
78+
run: cd examples/std; cargo fmt -- --check
79+
80+
- name: Clippy - STD Examples
81+
run: cd examples/std; cargo clippy -- -D warnings
82+
83+
- name: Build - STD Examples
84+
run: cd examples/std; cargo build
85+
86+
build-mbedtls:
87+
name: Build MbedTLS
88+
runs-on: ubuntu-latest
89+
permissions: read-all
90+
needs: build
91+
outputs:
92+
upload-libs: ${{ steps.detect-changes.outputs.libs == 'true' }}
93+
94+
steps:
95+
- uses: actions/checkout@v4
96+
97+
- name: mbedtls init
98+
run: git submodule update --init --recursive
99+
100+
- uses: dtolnay/rust-toolchain@v1
64101
with:
65-
workspaces: |
66-
./
67-
xtask
102+
target: x86_64-unknown-linux-gnu
103+
toolchain: nightly
104+
components: rust-src,rustfmt
105+
106+
# TODO: Double-check and uncomment
107+
# - uses: Swatinem/rust-cache@v2
108+
# with:
109+
# workspaces: |
110+
# ./
111+
# xtask
68112

69113
- name: Detect esp-mbedtls-sys/ changes
70114
uses: dorny/paths-filter@v3
@@ -74,41 +118,51 @@ jobs:
74118
libs:
75119
- 'esp-mbedtls-sys/**'
76120
77-
- name: Install Rust for Xtensa and Espressif LLVM installation (optional)
78-
uses: esp-rs/[email protected]
79-
with:
80-
ldproxy: true
81-
override: false
82-
extended-llvm: ${{
83-
steps.detect-changes.outputs.libs == 'true' ||
84-
contains(github.event.pull_request.labels.*.name, 'rebuild-libs')
85-
}}
86-
87-
# ==== Build libs ====
88-
- name: Build libraries and bindings
121+
- name: Detect host target triple
122+
run: |
123+
export HOST_TARGET=$(rustup show | grep "Default host" | sed -e 's/.* //')
124+
echo "HOST_TARGET=$HOST_TARGET" >> $GITHUB_ENV
125+
126+
- name: Install espup
127+
run: |
128+
curl -LO https://github.com/esp-rs/espup/releases/latest/download/espup-${{ env.HOST_TARGET }}.zip
129+
unzip -o espup-${{ env.HOST_TARGET }}.zip -d "$HOME/.cargo/bin"
130+
chmod +x "$HOME/.cargo/bin/espup"*
131+
echo "ESPUP_EXPORT_FILE=$HOME/exports" >> $GITHUB_ENV
132+
133+
- name: Install espup toolchains (xtensa and riscv)
134+
run: |
135+
source "$HOME/.cargo/env"
136+
"$HOME/.cargo/bin/espup" install -e -r
137+
source "$HOME/exports"
138+
echo "$PATH" >> "$GITHUB_PATH"
139+
echo "LIBCLANG_PATH=${LIBCLANG_PATH}" >> "$GITHUB_ENV"
140+
echo "CLANG_PATH=${CLANG_PATH}" >> "$GITHUB_ENV"
141+
142+
# TODO: Remove the manual espup installation and run once the action below
143+
# supports the `-r` flag to install the Espressif RISCV GCC toolchain
144+
# See https://github.com/esp-rs/xtensa-toolchain/issues/45 for more info
145+
# - name: Install Rust for Xtensa and Espressif LLVM installation (optional)
146+
# uses: esp-rs/[email protected]
147+
# with:
148+
# ldproxy: true
149+
# override: false
150+
# extended-llvm: ${{
151+
# steps.detect-changes.outputs.libs == 'true' ||
152+
# contains(github.event.pull_request.labels.*.name, 'rebuild-libs')
153+
# }}
154+
155+
- name: Build MbedTLS libraries and bindings
89156
if: |
90157
steps.detect-changes.outputs.libs == 'true' ||
91158
contains(github.event.pull_request.labels.*.name, 'rebuild-libs')
92159
run: |
93160
rm -rf esp-mbedtls-sys/libs/*
94-
cargo +stable xtask gen
95-
96-
# ==== Test ====
97-
# If the libs are rebuilt, the tests are executed against the new libraries,
98-
# else they get executed against the latest version in HEAD
99-
100-
# Tests requires nightly riscv32imc-unknown-none-elf to be installed
101-
- uses: dtolnay/rust-toolchain@v1
102-
with:
103-
target: riscv32imc-unknown-none-elf
104-
toolchain: nightly
105-
components: rust-src,rustfmt
106-
- uses: extractions/setup-just@v1
107-
with:
108-
just-version: 1.13.0
109-
110-
- name: check
111-
run: just
161+
cargo +stable xtask gen xtensa-esp32-none-elf
162+
cargo +stable xtask gen xtensa-esp32s2-none-elf
163+
cargo +stable xtask gen xtensa-esp32s3-none-elf
164+
cargo +stable xtask gen -e riscv32imc-unknown-none-elf
165+
cargo +stable xtask gen -e riscv32imac-unknown-none-elf
112166
113167
- name: Upload libraries artifacts for commit
114168
if: |
@@ -123,17 +177,77 @@ jobs:
123177
esp-mbedtls-sys/libs
124178
esp-mbedtls-sys/src
125179
180+
build-mcu:
181+
name: Build-MCU
182+
runs-on: ubuntu-latest
183+
permissions: read-all
184+
needs: build-mbedtls
185+
strategy:
186+
fail-fast: false
187+
matrix:
188+
mcu:
189+
- [esp, esp32, xtensa-esp32-none-elf]
190+
- [esp, esp32s2, xtensa-esp32s2-none-elf]
191+
- [esp, esp32s3, xtensa-esp32s3-none-elf]
192+
- [esp, esp32c2, riscv32imc-unknown-none-elf]
193+
- [esp, esp32c3, riscv32imc-unknown-none-elf]
194+
- [esp, esp32c6, riscv32imac-unknown-none-elf]
195+
# No Wifi support on esp32h2
196+
# - [esp, esp32h2, riscv32imac-unknown-none-elf]
197+
steps:
198+
- uses: actions/checkout@v4
199+
200+
- uses: dtolnay/rust-toolchain@v1
201+
with:
202+
target: x86_64-unknown-linux-gnu
203+
toolchain: nightly
204+
components: rust-src,rustfmt,clippy
205+
206+
- name: Install MCU target
207+
if: startsWith(matrix.mcu[2], 'riscv32')
208+
run: rustup target add ${{ matrix.mcu[2] }}
209+
210+
- name: Install Rust for Xtensa
211+
if: startsWith(matrix.mcu[2], 'xtensa-')
212+
uses: esp-rs/[email protected]
213+
with:
214+
default: true
215+
ldproxy: false
216+
217+
# TODO: Double-check and uncomment
218+
# - uses: Swatinem/rust-cache@v2
219+
# with:
220+
# workspaces: |
221+
# ./
222+
# xtask
223+
224+
- name: Clippy
225+
run: cargo clippy --features accel-${{ matrix.mcu[1] }} --target ${{ matrix.mcu[2] }} -Zbuild-std=core,alloc,panic_abort -- -D warnings
226+
227+
- name: Build
228+
run: cargo build --features accel-${{ matrix.mcu[1] }} --target ${{ matrix.mcu[2] }} -Zbuild-std=core,alloc,panic_abort
229+
230+
- name: Fmt Check - Examples
231+
run: cd examples/${{ matrix.mcu[0] }}; cargo fmt -- --check
232+
233+
- name: Clippy - Examples
234+
run: export WIFI_SSID=ssid; export WIFI_PASS=pass; cd examples/${{ matrix.mcu[0] }}; cargo clippy --no-default-features --features ${{ matrix.mcu[1] }} --target ${{ matrix.mcu[2] }} -Zbuild-std=core,alloc,panic_abort -- -D warnings
235+
236+
- name: Build - Examples
237+
run: export WIFI_SSID=ssid; export WIFI_PASS=pass; cd examples/${{ matrix.mcu[0] }}; cargo build --no-default-features --features ${{ matrix.mcu[1] }} --target ${{ matrix.mcu[2] }} -Zbuild-std=core,alloc,panic_abort
238+
126239
# If libraries are rebuilt and tests are successful, we upload them in a specific job
127240
# that has write access to prevent security breaches, and unwanted use of the token
128241
commit-libs:
242+
name: Commit MbedTLS libs
129243
runs-on: ubuntu-latest
130244
permissions:
131245
contents: write
132-
needs: build-test
246+
needs: build-mcu
133247
# TODO: Currently GitHub doesn't allow pushing to a forked repo's branch when running an action on a PR to upstream.
134248
if: |
135249
github.event.pull_request.head.repo.full_name == github.repository &&
136-
((needs.build-test.outputs.upload-libs &&
250+
((needs.build-mbedtls.outputs.upload-libs &&
137251
github.ref == 'refs/heads/main') ||
138252
contains(github.event.pull_request.labels.*.name, 'rebuild-libs'))
139253
steps:

0 commit comments

Comments
 (0)