From a927d8bbb8546067c5b0b80c6aaba509c26672b8 Mon Sep 17 00:00:00 2001 From: Peter M Date: Sun, 8 Mar 2026 11:13:49 +0100 Subject: [PATCH] Fix esp32 system_architecture reporting Current codebase outputs: <<"Generic--">> Generic_unix AtomVM outputs <<"Darwin-25.3.0-arm64">> this outputs: <<"esp_idf-5.4.1-xtensa">> I assume we should add same for rp2/stm32 - but that is for another PR. Signed-off-by: Peter M --- CHANGELOG.md | 1 + src/libAtomVM/CMakeLists.txt | 12 ++++++ src/libAtomVM/version.h.in | 6 +-- .../esp32/components/libatomvm/CMakeLists.txt | 8 ++++ .../test/main/test_erl_sources/CMakeLists.txt | 2 + .../test_system_architecture.erl | 37 +++++++++++++++++++ src/platforms/esp32/test/main/test_main.c | 6 +++ 7 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 src/platforms/esp32/test/main/test_erl_sources/test_system_architecture.erl diff --git a/CHANGELOG.md b/CHANGELOG.md index 74deb1433c..962263b0ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -119,6 +119,7 @@ table. ### Fixed - ESP32: improved sntp sync speed from a cold boot. +- ESP32: fixed `erlang:system_info(system_architecture)` to report `esp_idf--` - Fixed `gen_server` internal messages to match OTP so it works across erlang distribution - Utilize reserved `phy_init` partition on ESP32 to store wifi calibration for faster connections. - Support for zero count in `lists:duplicate/2`. diff --git a/src/libAtomVM/CMakeLists.txt b/src/libAtomVM/CMakeLists.txt index 8fdb354b65..8a0e6223da 100644 --- a/src/libAtomVM/CMakeLists.txt +++ b/src/libAtomVM/CMakeLists.txt @@ -310,6 +310,18 @@ else() set(ATOMVM_VERSION ${ATOMVM_BASE_VERSION}) endif() +if (NOT DEFINED AVM_SYSTEM_NAME) + set(AVM_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}") +endif() + +if (NOT DEFINED AVM_SYSTEM_VERSION) + set(AVM_SYSTEM_VERSION "${CMAKE_SYSTEM_VERSION}") +endif() + +if (NOT DEFINED AVM_SYSTEM_ARCHITECTURE) + set(AVM_SYSTEM_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}") +endif() + # Add include to directory where avm_version.h is generated so targets linking # libAtomVM can access it target_include_directories(libAtomVM PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/libAtomVM/version.h.in b/src/libAtomVM/version.h.in index 85849a042a..8095cceb6e 100644 --- a/src/libAtomVM/version.h.in +++ b/src/libAtomVM/version.h.in @@ -18,7 +18,7 @@ * SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later */ -#define SYSTEM_NAME "${CMAKE_SYSTEM_NAME}" -#define SYSTEM_VERSION "${CMAKE_SYSTEM_VERSION}" -#define SYSTEM_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}" +#define SYSTEM_NAME "${AVM_SYSTEM_NAME}" +#define SYSTEM_VERSION "${AVM_SYSTEM_VERSION}" +#define SYSTEM_ARCHITECTURE "${AVM_SYSTEM_ARCHITECTURE}" #define ATOMVM_VERSION "${ATOMVM_VERSION}" diff --git a/src/platforms/esp32/components/libatomvm/CMakeLists.txt b/src/platforms/esp32/components/libatomvm/CMakeLists.txt index e233b69a12..53e6d03fc3 100644 --- a/src/platforms/esp32/components/libatomvm/CMakeLists.txt +++ b/src/platforms/esp32/components/libatomvm/CMakeLists.txt @@ -24,6 +24,14 @@ idf_component_register(INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../lib # "pedantic" flag should be disabled rather poluting diagnostics with warnings caused from 3rd party option(AVM_PEDANTIC_WARNINGS "Pedantic compiler warnings" OFF) +set(AVM_SYSTEM_NAME "esp_idf") +set(AVM_SYSTEM_VERSION "${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}.${IDF_VERSION_PATCH}") +if (CONFIG_IDF_TARGET_ARCH_RISCV) + set(AVM_SYSTEM_ARCHITECTURE "riscv32") +else() + set(AVM_SYSTEM_ARCHITECTURE "xtensa") +endif() + add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../../../../libAtomVM" "libAtomVM") # Add directory with platform_atomic.h if we mean to use it diff --git a/src/platforms/esp32/test/main/test_erl_sources/CMakeLists.txt b/src/platforms/esp32/test/main/test_erl_sources/CMakeLists.txt index 544ddd2054..0c1e817ef0 100644 --- a/src/platforms/esp32/test/main/test_erl_sources/CMakeLists.txt +++ b/src/platforms/esp32/test/main/test_erl_sources/CMakeLists.txt @@ -74,6 +74,7 @@ compile_erlang(test_rtc_slow) compile_erlang(test_select) compile_erlang(test_socket) compile_erlang(test_ssl) +compile_erlang(test_system_architecture) compile_erlang(test_time_and_processes) compile_erlang(test_twdt) compile_erlang(test_tz) @@ -96,6 +97,7 @@ set(erlang_test_beams test_select.beam test_socket.beam test_ssl.beam + test_system_architecture.beam test_time_and_processes.beam test_twdt.beam test_tz.beam diff --git a/src/platforms/esp32/test/main/test_erl_sources/test_system_architecture.erl b/src/platforms/esp32/test/main/test_erl_sources/test_system_architecture.erl new file mode 100644 index 0000000000..884da144e7 --- /dev/null +++ b/src/platforms/esp32/test/main/test_erl_sources/test_system_architecture.erl @@ -0,0 +1,37 @@ +% +% This file is part of AtomVM. +% +% Copyright 2026 Peter M. Mehlsen +% +% Licensed under the Apache License, Version 2.0 (the "License"); +% you may not use this file except in compliance with the License. +% You may obtain a copy of the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, +% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +% See the License for the specific language governing permissions and +% limitations under the License. +% +% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later +% + +-module(test_system_architecture). +-export([start/0]). + +start() -> + SystemArchitecture = erlang:system_info(system_architecture), + <<"esp_idf-", _/binary>> = SystemArchitecture, + ok = + case binary:match(SystemArchitecture, <<"-xtensa">>) of + {_, _} -> + ok; + nomatch -> + case binary:match(SystemArchitecture, <<"-riscv32">>) of + {_, _} -> ok + end + end, + nomatch = binary:match(SystemArchitecture, <<"-esp32">>), + ok. diff --git a/src/platforms/esp32/test/main/test_main.c b/src/platforms/esp32/test/main/test_main.c index 809ad06df1..bf916479f6 100644 --- a/src/platforms/esp32/test/main/test_main.c +++ b/src/platforms/esp32/test/main/test_main.c @@ -506,6 +506,12 @@ TEST_CASE("test_time_and_processes", "[test_run]") TEST_ASSERT(term_to_int(ret_value) == 6); } +TEST_CASE("test_system_architecture", "[test_run]") +{ + term ret_value = avm_test_case("test_system_architecture.beam"); + TEST_ASSERT(ret_value == OK_ATOM); +} + TEST_CASE("test_tz", "[test_run]") { term ret_value = avm_test_case("test_tz.beam");