Skip to content

Commit 7a79a64

Browse files
committed
emscripten: support MbedTLS 4 in build and CI
Make the fetched MbedTLS version configurable and extend the wasm jobs to exercise both mbedtls3 and mbedtls4 builds while keeping release artifacts on the mbedtls3 path. Update the Emscripten build to link against MbedTLS::mbedtls, guard the legacy entropy helpers to pre-4.x builds, and switch the PSA feature probes to compile-only checks so they work with fetched and custom MbedTLS targets. Install the Python modules required by the MbedTLS 4 generators in the Emscripten CI container so the tf-psa-crypto build completes. Signed-off-by: Peter M <petermm@gmail.com>
1 parent dbee591 commit 7a79a64

4 files changed

Lines changed: 48 additions & 16 deletions

File tree

.github/workflows/wasm-build.yaml

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,21 @@ jobs:
107107
needs: compile_tests
108108
runs-on: ubuntu-24.04
109109
container: emscripten/emsdk
110+
strategy:
111+
fail-fast: false
112+
matrix:
113+
include:
114+
- mbedtls_label: "mbedtls3"
115+
mbedtls_git_tag: "v3.6.3.1"
116+
- mbedtls_label: "mbedtls4"
117+
mbedtls_git_tag: "v4.0.0"
110118

111119
steps:
112120
- name: Checkout repo
113121
uses: actions/checkout@v4
114122

115123
- name: "Install deps"
116-
run: sudo apt update -y && sudo apt install -y cmake gperf
124+
run: sudo apt update -y && sudo apt install -y cmake gperf python3-jinja2 python3-jsonschema
117125

118126
- name: Build
119127
shell: bash
@@ -122,7 +130,7 @@ jobs:
122130
set -euo pipefail
123131
mkdir build
124132
cd build
125-
emcmake cmake ..
133+
emcmake cmake .. -DAVM_FETCH_MBEDTLS_GIT_TAG=${{ matrix.mbedtls_git_tag }}
126134
emmake make -j
127135
128136
- name: Download AtomVM and test modules
@@ -147,7 +155,7 @@ jobs:
147155
node src/AtomVM.js ../../../../build/tests/erlang_tests/test_crypto.beam
148156
149157
- name: "Rename and write sha256sum (node)"
150-
if: startsWith(github.ref, 'refs/tags/')
158+
if: startsWith(github.ref, 'refs/tags/') && matrix.mbedtls_label == 'mbedtls3'
151159
shell: bash
152160
working-directory: src/platforms/emscripten/build/src
153161
run: |
@@ -160,7 +168,7 @@ jobs:
160168
161169
- name: "Release (node)"
162170
uses: softprops/action-gh-release@v1
163-
if: startsWith(github.ref, 'refs/tags/')
171+
if: startsWith(github.ref, 'refs/tags/') && matrix.mbedtls_label == 'mbedtls3'
164172
with:
165173
draft: true
166174
fail_on_unmatched_files: true
@@ -181,14 +189,20 @@ jobs:
181189
strategy:
182190
fail-fast: false
183191
matrix:
184-
language: ["javascript-typescript"]
192+
include:
193+
- language: "javascript-typescript"
194+
mbedtls_label: "mbedtls3"
195+
mbedtls_git_tag: "v3.6.3.1"
196+
- language: "javascript-typescript"
197+
mbedtls_label: "mbedtls4"
198+
mbedtls_git_tag: "v4.0.0"
185199

186200
steps:
187201
- name: Checkout repo
188202
uses: actions/checkout@v4
189203

190204
- name: "Install deps"
191-
run: sudo apt update -y && sudo apt install -y cmake gperf
205+
run: sudo apt update -y && sudo apt install -y cmake gperf python3-jinja2 python3-jsonschema
192206

193207
- name: "Initialize CodeQL"
194208
uses: github/codeql-action/init@v3
@@ -204,7 +218,7 @@ jobs:
204218
set -euo pipefail
205219
mkdir build
206220
cd build
207-
emcmake cmake .. -DAVM_EMSCRIPTEN_ENV=web
221+
emcmake cmake .. -DAVM_EMSCRIPTEN_ENV=web -DAVM_FETCH_MBEDTLS_GIT_TAG=${{ matrix.mbedtls_git_tag }}
208222
emmake make -j
209223
210224
- name: "Perform CodeQL Analysis"
@@ -213,7 +227,7 @@ jobs:
213227
- name: Upload wasm build for web
214228
uses: actions/upload-artifact@v4
215229
with:
216-
name: atomvm-js-web
230+
name: atomvm-js-web-${{ matrix.mbedtls_label }}
217231
path: |
218232
src/platforms/emscripten/build/**/*.wasm
219233
src/platforms/emscripten/build/**/*.js
@@ -222,6 +236,12 @@ jobs:
222236
wasm_test_web:
223237
needs: [compile_tests, wasm_build_web]
224238
runs-on: ubuntu-24.04
239+
strategy:
240+
fail-fast: false
241+
matrix:
242+
include:
243+
- mbedtls_label: "mbedtls3"
244+
- mbedtls_label: "mbedtls4"
225245
steps:
226246
- name: Checkout repo
227247
uses: actions/checkout@v4
@@ -235,7 +255,7 @@ jobs:
235255
- name: Download wasm build for web
236256
uses: actions/download-artifact@v4
237257
with:
238-
name: atomvm-js-web
258+
name: atomvm-js-web-${{ matrix.mbedtls_label }}
239259
path: src/platforms/emscripten/build
240260

241261
- name: Download emscripten test modules
@@ -270,7 +290,7 @@ jobs:
270290
retention-days: 7
271291

272292
- name: "Rename and write sha256sum (web)"
273-
if: startsWith(github.ref, 'refs/tags/')
293+
if: startsWith(github.ref, 'refs/tags/') && matrix.mbedtls_label == 'mbedtls3'
274294
shell: bash
275295
working-directory: src/platforms/emscripten/build/src
276296
run: |
@@ -283,7 +303,7 @@ jobs:
283303
284304
- name: "Release (web)"
285305
uses: softprops/action-gh-release@v1
286-
if: startsWith(github.ref, 'refs/tags/')
306+
if: startsWith(github.ref, 'refs/tags/') && matrix.mbedtls_label == 'mbedtls3'
287307
with:
288308
draft: true
289309
fail_on_unmatched_files: true

CMakeModules/FetchMbedTLS.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020

2121
include(FetchContent)
2222

23+
set(AVM_FETCH_MBEDTLS_GIT_TAG "v3.6.3.1" CACHE STRING "MbedTLS git tag to fetch for Emscripten builds")
24+
2325
FetchContent_Declare(
2426
mbedtls
2527
GIT_REPOSITORY http://github.com/mbed-TLS/mbedtls.git
26-
GIT_TAG v3.6.3.1
28+
GIT_TAG ${AVM_FETCH_MBEDTLS_GIT_TAG}
2729
GIT_SHALLOW 1
2830
)
2931

src/platforms/emscripten/src/lib/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,24 @@ target_compile_features(libAtomVM${PLATFORM_LIB_SUFFIX} PUBLIC c_std_11)
4747

4848
target_link_libraries(libAtomVM${PLATFORM_LIB_SUFFIX} PUBLIC libAtomVM)
4949
target_compile_definitions(libAtomVM${PLATFORM_LIB_SUFFIX} PUBLIC ATOMVM_HAS_MBEDTLS)
50-
target_link_libraries(libAtomVM${PLATFORM_LIB_SUFFIX} PUBLIC MbedTLS::mbedcrypto)
50+
target_link_libraries(libAtomVM${PLATFORM_LIB_SUFFIX} PUBLIC MbedTLS::mbedtls)
5151
include(CheckCSourceCompiles)
52-
get_target_property(_mbedcrypto_includes MbedTLS::mbedcrypto INTERFACE_INCLUDE_DIRECTORIES)
53-
set(CMAKE_REQUIRED_INCLUDES ${_mbedcrypto_includes})
52+
get_target_property(_mbedtls_includes MbedTLS::mbedtls INTERFACE_INCLUDE_DIRECTORIES)
53+
set(CMAKE_REQUIRED_INCLUDES ${_mbedtls_includes})
54+
set(_avm_try_compile_target_type ${CMAKE_TRY_COMPILE_TARGET_TYPE})
55+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
5456
check_c_source_compiles("
5557
#include <mbedtls/version.h>
5658
#ifndef MBEDTLS_PSA_CRYPTO_C
5759
#error PSA Crypto not available
5860
#endif
61+
#include <psa/crypto.h>
5962
int main(void) { return 0; }
6063
" HAVE_PSA_CRYPTO)
64+
set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_avm_try_compile_target_type})
6165
unset(CMAKE_REQUIRED_INCLUDES)
62-
unset(_mbedcrypto_includes)
66+
unset(_avm_try_compile_target_type)
67+
unset(_mbedtls_includes)
6368
if (HAVE_PSA_CRYPTO)
6469
target_compile_definitions(libAtomVM${PLATFORM_LIB_SUFFIX} PUBLIC HAVE_PSA_CRYPTO)
6570
endif()

src/platforms/emscripten/src/lib/sys.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ term sys_get_info(Context *ctx, term key)
771771
return UNDEFINED_ATOM;
772772
}
773773

774+
#ifdef ATOMVM_HAS_MBEDTLS
775+
#if MBEDTLS_VERSION_NUMBER < 0x04000000
774776
int sys_mbedtls_entropy_func(void *entropy, unsigned char *buf, size_t size)
775777
{
776778
#ifndef MBEDTLS_THREADING_C
@@ -837,3 +839,6 @@ void sys_mbedtls_ctr_drbg_context_unlock(GlobalContext *global)
837839
struct EmscriptenPlatformData *platform = global->platform_data;
838840
SMP_MUTEX_UNLOCK(platform->random_mutex);
839841
}
842+
#endif
843+
844+
#endif

0 commit comments

Comments
 (0)