Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions Dockerfile.build_firmware
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,34 @@ RUN --mount=type=bind,target=/src,source=.,readonly \
set -euo pipefail; \
mkdir -p /output; \
LIBRMCS_PROJECT_VERSION="$(.scripts/generate_version)"; \
LIBRMCS_DEBUG_ASSERTS=1; \
FIRMWARE_CMAKE_PRESET=debug; \
LIBRMCS_ARTIFACT_SUFFIX=-debug; \
if [[ "${LIBRMCS_PROJECT_VERSION}" =~ ^[0-9]+(\.[0-9]+)*$ ]]; then \
LIBRMCS_DEBUG_ASSERTS=0; \
FIRMWARE_CMAKE_PRESET=release; \
LIBRMCS_ARTIFACT_SUFFIX=; \
fi; \
for board in rmcs_board; do \
for variant in pro lite; do \
build_dir="/tmp/build-${board}-${variant}"; \
artifact_name="${board}-${variant}"; \
cmake --preset release -S "firmware/${board}" -B "${build_dir}" -DBOARD="${variant}"; \
cmake --preset "${FIRMWARE_CMAKE_PRESET}" -S "firmware/${board}" -B "${build_dir}" -DBOARD="${variant}" -DLIBRMCS_DEBUG_ASSERTS="${LIBRMCS_DEBUG_ASSERTS}"; \
cmake --build "${build_dir}"; \
cp "${build_dir}/bootloader/output/rmcs_board_bootloader.elf" \
"/output/librmcs-bootloader-${artifact_name}.elf"; \
"/output/librmcs-bootloader-${artifact_name}${LIBRMCS_ARTIFACT_SUFFIX}.elf"; \
cp "${build_dir}/app/output/rmcs_board_app.dfu" \
"/output/librmcs-firmware-${artifact_name}-${LIBRMCS_PROJECT_VERSION}.dfu"; \
"/output/librmcs-firmware-${artifact_name}-${LIBRMCS_PROJECT_VERSION}${LIBRMCS_ARTIFACT_SUFFIX}.dfu"; \
done; \
done; \
for board in c_board; do \
build_dir="/tmp/build-${board}"; \
cmake --preset release -S "firmware/${board}" -B "${build_dir}"; \
cmake --preset "${FIRMWARE_CMAKE_PRESET}" -S "firmware/${board}" -B "${build_dir}" -DLIBRMCS_DEBUG_ASSERTS="${LIBRMCS_DEBUG_ASSERTS}"; \
cmake --build "${build_dir}"; \
cp "${build_dir}/bootloader/${board}_bootloader.elf" \
"/output/librmcs-bootloader-${board}.elf"; \
"/output/librmcs-bootloader-${board}${LIBRMCS_ARTIFACT_SUFFIX}.elf"; \
cp "${build_dir}/app/${board}_app.dfu" \
"/output/librmcs-firmware-${board}-${LIBRMCS_PROJECT_VERSION}.dfu"; \
"/output/librmcs-firmware-${board}-${LIBRMCS_PROJECT_VERSION}${LIBRMCS_ARTIFACT_SUFFIX}.dfu"; \
done

FROM scratch AS output
Expand Down
22 changes: 18 additions & 4 deletions Dockerfile.build_sdk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cmake_minimum_required(VERSION 3.28)
project(librmcs_wrapper VERSION 3 LANGUAGES C CXX)
set(LIBRMCS_PROJECT_VERSION "__LIBRMCS_PROJECT_VERSION_PLACEHOLDER__")
set(LIBRMCS_DEBIAN_VERSION "__LIBRMCS_DEBIAN_VERSION_PLACEHOLDER__")
set(LIBRMCS_DEBUG_ASSERTS __LIBRMCS_DEBUG_ASSERTS_PLACEHOLDER__)
add_subdirectory(host)
EOF

Expand All @@ -25,26 +26,39 @@ WORKDIR /src-full
RUN --mount=type=bind,target=/src-full,source=.,readonly \
LIBRMCS_PROJECT_VERSION=$(.scripts/generate_version) \
&& LIBRMCS_DEBIAN_VERSION=$(.scripts/generate_version --format debian) \
&& echo "LIBRMCS_PROJECT_VERSION=${LIBRMCS_PROJECT_VERSION}" >> /env.sh \
&& echo "LIBRMCS_DEBIAN_VERSION=${LIBRMCS_DEBIAN_VERSION}" >> /env.sh \
&& LIBRMCS_DEBUG_ASSERTS=1 \
&& SDK_CMAKE_PRESET=linux-debug \
&& LIBRMCS_ARTIFACT_SUFFIX=-debug \
&& if [[ "${LIBRMCS_PROJECT_VERSION}" =~ ^[0-9]+(\.[0-9]+)*$ ]]; then \
LIBRMCS_DEBUG_ASSERTS=0; \
SDK_CMAKE_PRESET=linux-release; \
LIBRMCS_ARTIFACT_SUFFIX=; \
fi \
&& printf 'LIBRMCS_PROJECT_VERSION=%s\n' "${LIBRMCS_PROJECT_VERSION}" >> /env.sh \
&& printf 'LIBRMCS_DEBIAN_VERSION=%s\n' "${LIBRMCS_DEBIAN_VERSION}" >> /env.sh \
&& printf 'LIBRMCS_DEBUG_ASSERTS=%s\n' "${LIBRMCS_DEBUG_ASSERTS}" >> /env.sh \
&& printf 'SDK_CMAKE_PRESET=%s\n' "${SDK_CMAKE_PRESET}" >> /env.sh \
&& printf 'LIBRMCS_ARTIFACT_SUFFIX=%s\n' "${LIBRMCS_ARTIFACT_SUFFIX}" >> /env.sh \
&& cp -r core host LICENSE /src \
&& sed -i "s/__LIBRMCS_PROJECT_VERSION_PLACEHOLDER__/${LIBRMCS_PROJECT_VERSION}/g" \
/src/CMakeLists.txt \
&& sed -i "s/__LIBRMCS_DEBIAN_VERSION_PLACEHOLDER__/${LIBRMCS_DEBIAN_VERSION}/g" \
/src/CMakeLists.txt \
&& sed -i "s/__LIBRMCS_DEBUG_ASSERTS_PLACEHOLDER__/${LIBRMCS_DEBUG_ASSERTS}/g" \
/src/CMakeLists.txt

WORKDIR /output

RUN source /env.sh \
&& if [ "${WITH_SOURCE}" = "true" ]; then \
SDK_SRC_NAME=librmcs-sdk-src-${LIBRMCS_PROJECT_VERSION}; \
SDK_SRC_NAME=librmcs-sdk-src-${LIBRMCS_PROJECT_VERSION}${LIBRMCS_ARTIFACT_SUFFIX}; \
cp -r /src ${SDK_SRC_NAME}; \
zip -r ${SDK_SRC_NAME}.zip ${SDK_SRC_NAME}; \
rm -rf ${SDK_SRC_NAME}; \
fi

RUN source /env.sh \
&& cmake --preset linux-release -DBUILD_STATIC_LIBRMCS=OFF -B build /src \
&& cmake --preset "${SDK_CMAKE_PRESET}" -DBUILD_STATIC_LIBRMCS=OFF -B build /src \
&& cmake --build build \
&& cd build && cpack -G DEB && cd .. \
&& mv build/*.deb . \
Expand Down
26 changes: 15 additions & 11 deletions core/src/utility/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
#include <type_traits>
#include <utility>

#ifndef NDEBUG
#ifndef LIBRMCS_DEBUG_ASSERTS
# error "LIBRMCS_DEBUG_ASSERTS must be defined"
#endif

#if LIBRMCS_DEBUG_ASSERTS
# include <functional>
#endif

Expand All @@ -19,11 +23,11 @@ namespace librmcs::core::utility {

[[noreturn]] inline void
assert_failed_debug(const std::source_location& location = std::source_location::current()) {
#ifdef NDEBUG
#if LIBRMCS_DEBUG_ASSERTS
assert_func(location);
#else
(void)location;
std::unreachable();
#else
assert_func(location);
#endif
}

Expand All @@ -35,23 +39,23 @@ constexpr void assert_always(

constexpr void assert_debug(
bool condition, const std::source_location& location = std::source_location::current()) {
#ifdef NDEBUG
#if LIBRMCS_DEBUG_ASSERTS
assert_always(condition, location);
#else
[[assume(condition)]];
(void)location;
#else
assert_always(condition, location);
#endif
}

// Debug-only lazy assertion: The predicate is evaluated only in debug builds.
template <typename Condition>
requires std::is_nothrow_invocable_r_v<bool, Condition&&> inline void assert_debug_lazy(
Condition&& condition, const std::source_location& location = std::source_location::current()) {
#ifdef NDEBUG
(void)condition;
(void)location;
#else
#if LIBRMCS_DEBUG_ASSERTS
assert_always(static_cast<bool>(std::invoke(std::forward<Condition>(condition))), location);
#else
(void)std::forward<Condition>(condition);
(void)location;
#endif
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/utility/stack_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ class BasicStackAllocator<true> : private BasicStackAllocator<false> {
std::size_t lifo_check_depth_ = 0;
};

#ifdef NDEBUG
using StackAllocator = BasicStackAllocator<false>;
#else
#if LIBRMCS_DEBUG_ASSERTS
using StackAllocator = BasicStackAllocator<true>;
#else
using StackAllocator = BasicStackAllocator<false>;
#endif

} // namespace librmcs::core::utility
1 change: 1 addition & 0 deletions firmware/c_board/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function(c_board_apply_target_options target linker_file)

target_compile_definitions(${target} PRIVATE
LIBRMCS_PROJECT_VERSION_STRING="${LIBRMCS_PROJECT_VERSION}"
LIBRMCS_DEBUG_ASSERTS=${LIBRMCS_DEBUG_ASSERTS}
$<$<CONFIG:Release>:NDEBUG>
)

Expand Down
10 changes: 7 additions & 3 deletions firmware/c_board/bootloader/src/utility/assert.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#ifndef LIBRMCS_DEBUG_ASSERTS
# error "LIBRMCS_DEBUG_ASSERTS must be defined"
#endif

namespace librmcs::firmware::utility {

[[noreturn, gnu::always_inline]] inline void assert_failed_always() { __builtin_trap(); }
Expand All @@ -10,10 +14,10 @@ namespace librmcs::firmware::utility {
}

[[gnu::always_inline]] inline void assert_debug(bool condition) {
#ifdef NDEBUG
[[assume(condition)]];
#else
#if LIBRMCS_DEBUG_ASSERTS
assert_always(condition);
#else
[[assume(condition)]];
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions firmware/c_board/cmake/gcc-arm-none-eabi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TARGET_FLAGS}")
set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp -MMD -MP")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fdata-sections -ffunction-sections")

set(CMAKE_C_FLAGS_DEBUG "-Og -g3")
set(CMAKE_C_FLAGS_DEBUG "-O3 -g3")
set(CMAKE_C_FLAGS_RELEASE "-O3 -g0")
set(CMAKE_CXX_FLAGS_DEBUG "-Og -g3")
set(CMAKE_CXX_FLAGS_DEBUG "-O3 -g3")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g0")

set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions -fno-threadsafe-statics")
Expand Down
15 changes: 15 additions & 0 deletions firmware/common/cmake/librmcs_firmware.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ function(librmcs_setup_project_context)
)
endif()

set(debug_asserts "${LIBRMCS_DEBUG_ASSERTS}")
if("${debug_asserts}" STREQUAL "")
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower)
if(build_type_lower STREQUAL "release")
set(debug_asserts 0)
else()
set(debug_asserts 1)
endif()
endif()
if(NOT "${debug_asserts}" STREQUAL "0" AND NOT "${debug_asserts}" STREQUAL "1")
message(FATAL_ERROR "LIBRMCS_DEBUG_ASSERTS must be 0 or 1")
endif()

set(source_path_map "${SOURCE_PATH_MAP}")
if(HOST_DEBUGGER AND "${source_path_map}" STREQUAL "")
if(DEFINED ENV{HOST_WORKSPACE_FOLDER} AND NOT "$ENV{HOST_WORKSPACE_FOLDER}" STREQUAL "")
Expand All @@ -53,9 +66,11 @@ function(librmcs_setup_project_context)
endif()

message(STATUS "Librmcs project version: ${project_version}")
message(STATUS "Librmcs debug asserts: ${debug_asserts}")

set(LIBRMCS_PROJECT_ROOT "${project_root}" PARENT_SCOPE)
set(LIBRMCS_PROJECT_VERSION "${project_version}" PARENT_SCOPE)
set(LIBRMCS_DEBUG_ASSERTS "${debug_asserts}" PARENT_SCOPE)
set(LIBRMCS_SOURCE_PATH_MAP "${source_path_map}" PARENT_SCOPE)
set(LIBRMCS_SOURCE_PATH_MAP_COMPILE_OPTIONS "${prefix_map_compile_options}" PARENT_SCOPE)
endfunction()
Expand Down
1 change: 1 addition & 0 deletions firmware/rmcs_board/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function(add_rmcs_board_subbuild target_name source_subdir)
-DHOST_DEBUGGER=${HOST_DEBUGGER}
-DSOURCE_PATH_MAP=${LIBRMCS_SOURCE_PATH_MAP}
-DLIBRMCS_PROJECT_VERSION=${LIBRMCS_PROJECT_VERSION}
-DLIBRMCS_DEBUG_ASSERTS=${LIBRMCS_DEBUG_ASSERTS}
)
if(CMAKE_MAKE_PROGRAM)
list(APPEND configure_args -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM})
Expand Down
3 changes: 2 additions & 1 deletion firmware/rmcs_board/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ if(LIBRMCS_SOURCE_PATH_MAP_COMPILE_OPTIONS)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "debug")
sdk_compile_options(-Og)
sdk_compile_options(-O3)
endif()

sdk_compile_definitions(-DLIBRMCS_PROJECT_VERSION_STRING="${LIBRMCS_PROJECT_VERSION}")
sdk_compile_definitions(-DLIBRMCS_DEBUG_ASSERTS=${LIBRMCS_DEBUG_ASSERTS})
sdk_compile_definitions(-DCFG_TUSB_MCU=OPT_MCU_HPM)
sdk_compile_definitions(-DUSB_HOST_MCU_CORE=HPM_CORE0)

Expand Down
3 changes: 2 additions & 1 deletion firmware/rmcs_board/bootloader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if(LIBRMCS_SOURCE_PATH_MAP_COMPILE_OPTIONS)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "debug")
sdk_compile_options(-Og)
sdk_compile_options(-O3)
endif()

if(NOT "${BOARD_BOOTLOADER_MODE}" STREQUAL "auto"
Expand All @@ -62,6 +62,7 @@ else()
endif()

sdk_compile_definitions(-DLIBRMCS_PROJECT_VERSION_STRING="${LIBRMCS_PROJECT_VERSION}")
sdk_compile_definitions(-DLIBRMCS_DEBUG_ASSERTS=${LIBRMCS_DEBUG_ASSERTS})
sdk_compile_definitions(-DCFG_TUSB_MCU=OPT_MCU_HPM)
sdk_compile_definitions(-DUSB_HOST_MCU_CORE=HPM_CORE0)
sdk_compile_definitions(-DLIBRMCS_BOOTLOADER_MODE_AUTO=${bootloader_mode_auto})
Expand Down
10 changes: 7 additions & 3 deletions firmware/rmcs_board/bootloader/src/utility/assert.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#ifndef LIBRMCS_DEBUG_ASSERTS
# error "LIBRMCS_DEBUG_ASSERTS must be defined"
#endif

namespace librmcs::firmware::utility {

[[noreturn, gnu::always_inline]] inline void assert_failed_always() { __builtin_trap(); }
Expand All @@ -10,10 +14,10 @@ namespace librmcs::firmware::utility {
}

[[gnu::always_inline]] inline void assert_debug(bool condition) {
#ifdef NDEBUG
[[assume(condition)]];
#else
#if LIBRMCS_DEBUG_ASSERTS
assert_always(condition);
#else
[[assume(condition)]];
#endif
}

Expand Down
21 changes: 20 additions & 1 deletion host/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ if(NOT DEFINED LIBRMCS_PROJECT_VERSION OR LIBRMCS_PROJECT_VERSION STREQUAL "")
endif()
message(STATUS "Librmcs project version: ${LIBRMCS_PROJECT_VERSION}")

if(DEFINED LIBRMCS_DEBUG_ASSERTS AND NOT LIBRMCS_DEBUG_ASSERTS STREQUAL "")
if(NOT LIBRMCS_DEBUG_ASSERTS STREQUAL "0" AND NOT LIBRMCS_DEBUG_ASSERTS STREQUAL "1")
message(FATAL_ERROR "LIBRMCS_DEBUG_ASSERTS must be 0 or 1")
endif()
set(librmcs_debug_asserts_definition "LIBRMCS_DEBUG_ASSERTS=${LIBRMCS_DEBUG_ASSERTS}")
message(STATUS "Librmcs debug asserts: ${LIBRMCS_DEBUG_ASSERTS}")
else()
set(librmcs_debug_asserts_definition "LIBRMCS_DEBUG_ASSERTS=$<IF:$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>,$<CONFIG:MinSizeRel>>,0,1>")
message(STATUS "Librmcs debug asserts: per-config")
endif()

# Set C++ standard to C++23
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED True)
Expand Down Expand Up @@ -68,6 +79,7 @@ else()
endif()

target_compile_definitions(${PROJECT_NAME} PRIVATE LIBRMCS_PROJECT_VERSION_STRING="${LIBRMCS_PROJECT_VERSION}")
target_compile_definitions(${PROJECT_NAME} PRIVATE ${librmcs_debug_asserts_definition})
target_compile_definitions(${PROJECT_NAME} PRIVATE BUILDING_LIBRMCS)

target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../core/include)
Expand Down Expand Up @@ -161,7 +173,14 @@ if(UNIX AND NOT APPLE)
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")

string(TOLOWER "${CMAKE_BUILD_TYPE}" PACKAGE_BUILD_MODE)
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${LIBRMCS_PROJECT_VERSION}-${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}-${PACKAGE_BUILD_MODE}")
if(PACKAGE_BUILD_MODE STREQUAL "release"
OR PACKAGE_BUILD_MODE STREQUAL "relwithdebinfo"
OR PACKAGE_BUILD_MODE STREQUAL "minsizerel")
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${LIBRMCS_PROJECT_VERSION}-${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
else()
set(CPACK_PACKAGE_FILE_NAME
"${PROJECT_NAME}-${LIBRMCS_PROJECT_VERSION}-${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}-${PACKAGE_BUILD_MODE}")
endif()
Comment thread
coderabbitai[bot] marked this conversation as resolved.
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE")

include(CPack)
Expand Down
Loading