From 5b4cf540a965c75e151c8938763d0c1e95faff6b Mon Sep 17 00:00:00 2001 From: Davide Bettio Date: Tue, 21 Nov 2023 19:00:50 +0100 Subject: [PATCH 1/2] cmake: allow using static (.a) mbedtls This option will be used when building Linux artifacts that are published later on GitHub releases. Signed-off-by: Davide Bettio --- CMakeModules/MbedTLS.cmake | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/CMakeModules/MbedTLS.cmake b/CMakeModules/MbedTLS.cmake index 52f0409d1..c2e926e93 100644 --- a/CMakeModules/MbedTLS.cmake +++ b/CMakeModules/MbedTLS.cmake @@ -33,6 +33,8 @@ # If it doesn't work, search for MBEDTLS_VERSION_NUMBER symbol as well as # the three libraries we need with check_symbol_exists and find_library +option(AVM_STATIC_MBEDTLS "Static link Mbed-TLS." OFF) + if (MBEDTLS_ROOT_DIR) set(MbedTLS_FOUND TRUE) if (NOT MBEDTLS_LIBRARIES_DIR) @@ -40,6 +42,10 @@ if (MBEDTLS_ROOT_DIR) endif() message(STATUS "Will use MbedTLS from ${MBEDTLS_ROOT_DIR} and ${MBEDTLS_LIBRARIES_DIR}") + if (AVM_STATIC_MBEDTLS) + message(FATAL_ERROR "AVM_STATIC_MBEDTLS not supported with MbedTLS root dir option") + endif() + add_library(MbedTLS::mbedcrypto SHARED IMPORTED) set_target_properties(MbedTLS::mbedcrypto PROPERTIES IMPORTED_LOCATION "${MBEDTLS_LIBRARIES_DIR}/libmbedcrypto${CMAKE_SHARED_LIBRARY_SUFFIX}" @@ -64,12 +70,26 @@ else() find_package(MbedTLS QUIET) if (MbedTLS_FOUND) message(STATUS "Found MbedTLS package ${MbedTLS_FOUND}") + + if (AVM_STATIC_MBEDTLS) + message(FATAL_ERROR "AVM_STATIC_MBEDTLS not supported with MbedTLS cmake package") + endif() else() + if (AVM_STATIC_MBEDTLS) + set(MBEDCRYPTO_LIB_NAME "libmbedcrypto.a") + set(MBEDX509_LIB "libmbedx509.a") + set(MBEDTLS_LIB "libmbedtls.a") + else() + set(MBEDCRYPTO_LIB_NAME "mbedcrypto") + set(MBEDX509_LIB "mbedx509") + set(MBEDTLS_LIB "mbedtls") + endif() + include(CheckSymbolExists) check_symbol_exists(MBEDTLS_VERSION_NUMBER "mbedtls/version.h" HAVE_MBEDTLS_VERSION_NUMBER) - find_library(MBEDCRYPTO mbedcrypto) - find_library(MBEDX509 mbedx509) - find_library(MBEDTLS mbedtls) + find_library(MBEDCRYPTO NAMES ${MBEDCRYPTO_LIB_NAME}) + find_library(MBEDX509 NAMES ${MBEDX509_LIB}) + find_library(MBEDTLS NAMES ${MBEDTLS_LIB}) if (HAVE_MBEDTLS_VERSION_NUMBER AND NOT ${MBEDCRYPTO} STREQUAL "MBEDCRYPTO-NOTFOUND" AND NOT ${MBEDX509} STREQUAL "MBEDX509-NOTFOUND" From db86ddc6cc6a7a02e1857a407a27192ed88d1a05 Mon Sep 17 00:00:00 2001 From: Davide Bettio Date: Wed, 22 Nov 2023 00:25:14 +0100 Subject: [PATCH 2/2] Add additional x86_64 build that doesn't require mbedtls Builtin (static) mbedtls will allow to try AtomVM on most recent x86_64 Linux systems with less friction. Signed-off-by: Davide Bettio --- .github/workflows/build-linux-artifacts.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/build-linux-artifacts.yaml b/.github/workflows/build-linux-artifacts.yaml index bca1a03b7..d395e3cc6 100644 --- a/.github/workflows/build-linux-artifacts.yaml +++ b/.github/workflows/build-linux-artifacts.yaml @@ -120,6 +120,22 @@ jobs: tag: "22.04" cflags: "" + - arch: "x86_64" + build_name: "linux-x86_64-static-mbedtls" + docker_image: "ubuntu" + platform: "amd64" + tag: "18.04" + cflags: "" + cmake_opts: "-DAVM_STATIC_MBEDTLS=ON" + install_deps: | + apt update && + apt install -y file gcc g++ binutils make doxygen gperf zlib1g-dev libmbedtls-dev wget tzdata && + apt purge -y cmake && + wget https://cmake.org/files/v3.13/cmake-3.13.5-Linux-x86_64.tar.gz && + tar xf cmake-3.13.5-Linux-x86_64.tar.gz && + mv cmake-3.13.5-Linux-x86_64 /opt/cmake-3.13.5 && + ln -sf /opt/cmake-3.13.5/bin/* /usr/bin/ + - arch: "x86_64" build_name: "linux-x86_64" docker_image: "ubuntu"