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
77 changes: 71 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
branches: [ main, master, develop ]

jobs:
build-and-test:
name: Build and Test
build-and-test-core:
name: Build and Test dmsai (core)
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -19,12 +19,16 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Build dmsai
- name: Build dmsai core module
run: |
mkdir -p build
cd build
cmake .. -DDMOD_MODE=DMOD_MODULE
cmake --build .
# dmsai links against dmsai_port_if (headers only),
# not dmsai_port itself, so building only these two targets
# never touches src/port/*/port.c - safe to build natively here
# regardless of which CPU family the port defaults to.
cmake .. -DDMOD_MODE=DMOD_MODULE -DDMOD_TOOLS_NAME=arch/x86_64
cmake --build . --target dmsai test_dmsai

- name: Verify module files
run: |
Expand All @@ -38,5 +42,66 @@ jobs:
- name: Run tests with dmod_loader
run: |
export DMOD_DMF_DIR=$(pwd)/build/dmf
dmf-get install -d ${DMOD_DMF_DIR}/test_dmsai-local.dmd -y
dmod_loader build/dmf/test_dmsai.dmf

discover-cpu-families:
name: Discover CPU Families
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
cpu_families: ${{ steps.list-families.outputs.cpu_families }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: List available CPU families
id: list-families
run: |
# Find all CPU families by looking for directories containing port.c
CPU_FAMILIES=$(find src/port -mindepth 2 -maxdepth 2 -name "port.c" -type f -printf '%h\n' | \
xargs -n1 basename | \
sort | \
jq -R -s -c 'split("\n") | map(select(length > 0))')

echo "Found CPU families: $CPU_FAMILIES"
echo "cpu_families=$CPU_FAMILIES" >> $GITHUB_OUTPUT

build-dmsai:
name: Build dmsai for ${{ matrix.cpu_family }}
needs: discover-cpu-families
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
cpu_family: ${{ fromJson(needs.discover-cpu-families.outputs.cpu_families) }}

container:
image: chocotechnologies/dmod:1.0.4

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build dmsai for ${{ matrix.cpu_family }}
run: |
set -e
CPU_FAMILY="${{ matrix.cpu_family }}"
mkdir -p build_$CPU_FAMILY
cd build_$CPU_FAMILY

cmake .. -DDMOD_CPU_FAMILY="${CPU_FAMILY}"
cmake --build .

echo "Build completed for CPU family: ${CPU_FAMILY}"
ls -lh dmf/

- name: Verify dmsai_port module files
run: |
CPU_FAMILY="${{ matrix.cpu_family }}"
echo "Checking for dmsai_port module files for ${CPU_FAMILY}..."
ls -lh build_$CPU_FAMILY/dmf/
test -f build_$CPU_FAMILY/dmf/dmsai_port.dmf
test -f build_$CPU_FAMILY/dmf/dmsai_port_version.txt
echo "Module files present for ${CPU_FAMILY}"
103 changes: 42 additions & 61 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,37 @@ on:
types: [created]

jobs:
discover-architectures:
name: Discover Architectures
discover-cpu-families:
name: Discover CPU Families
runs-on: ubuntu-latest
permissions:
contents: read
container:
image: chocotechnologies/dmod:1.0.4
outputs:
architectures: ${{ steps.list-archs.outputs.architectures }}
cpu_families: ${{ steps.list-families.outputs.cpu_families }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Fetch dmod to discover architectures
run: |
# A plain `git clone` here (rather than configuring dmsai's
# own CMakeLists.txt via FetchContent, as before) so this step only
# ever depends on dmod itself - not on dmsai's
# dmod_link_modules() fetches of other modules, which this step has
# no business needing just to list dmod's supported architectures,
# and which previously made this discovery job (and therefore the
# whole release) fail outright whenever any of those unrelated
# external fetches hiccuped.
git clone --depth 1 https://github.com/choco-technologies/dmod.git dmod_discovery

- name: List available architectures
id: list-archs
- name: List available CPU families
id: list-families
run: |
# create JSON array
ARCHS=$(find dmod_discovery/configs/arch -name "tools-cfg.cmake" | \
sed "s|dmod_discovery/configs/arch/||g" | \
sed 's|/tools-cfg.cmake||g' | \
CPU_FAMILIES=$(find src/port -mindepth 2 -maxdepth 2 -name "port.c" -type f -printf '%h\n' | \
xargs -n1 basename | \
sort | \
jq -R -s -c 'split("\n") | map(select(length > 0))')

echo "Found architectures: $ARCHS"
echo "architectures=$ARCHS" >> $GITHUB_OUTPUT
echo "Found CPU families: $CPU_FAMILIES"
echo "cpu_families=$CPU_FAMILIES" >> $GITHUB_OUTPUT

build-release:
name: Build Release for ${{ matrix.arch_name }}
needs: discover-architectures
build-dmsai:
name: Build dmsai for ${{ matrix.cpu_family }}
needs: discover-cpu-families
runs-on: ubuntu-latest
permissions:
contents: write
strategy:
matrix:
arch_name: ${{ fromJson(needs.discover-architectures.outputs.architectures) }}
cpu_family: ${{ fromJson(needs.discover-cpu-families.outputs.cpu_families) }}

container:
image: chocotechnologies/dmod:1.0.4
Expand All @@ -62,61 +47,63 @@ jobs:
- name: Extract version from tag
id: get_version
run: |
# Extract version from tag (e.g., v1.2 -> 1.2)
VERSION="${{ github.event.release.tag_name }}"
VERSION="${VERSION#v}" # Remove 'v' prefix if present
VERSION="${VERSION#v}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"

- name: Build dmsai for ${{ matrix.arch_name }}
- name: Build dmsai for ${{ matrix.cpu_family }}
run: |
set -e
ARCH_DIR_NAME=$(echo "${{ matrix.arch_name }}" | sed 's|/|-|')
echo "ARCH_DIR_NAME=$ARCH_DIR_NAME" >> $GITHUB_ENV
echo "ARTIFACT_NAME=release-$ARCH_DIR_NAME" >> $GITHUB_ENV
mkdir -p build_$ARCH_DIR_NAME
cd build_$ARCH_DIR_NAME

# DMOD_DMR_PATH is already set in CMakeLists.txt, so this build also
# assembles build_$ARCH_DIR_NAME/packages/<module>/ for every module
# defined in this repo's CMake config - nothing left to do here but
# discover whatever got packaged, add release notes, and zip it.
cmake .. -DDMOD_TOOLS_NAME=arch/${{ matrix.arch_name }} -DDMOD_MODULE_VERSION="${{ steps.get_version.outputs.version }}"
CPU_FAMILY="${{ matrix.cpu_family }}"
BUILD_NAME="port-${CPU_FAMILY}"
echo "BUILD_NAME=$BUILD_NAME" >> $GITHUB_ENV
echo "ARTIFACT_NAME=release-$BUILD_NAME" >> $GITHUB_ENV
mkdir -p build_$BUILD_NAME
cd build_$BUILD_NAME

# DMOD_DMR_PATH is already set for both dmsai and
# dmsai_port in their respective CMakeLists.txt, so this
# build also assembles packages/<module>/ for every module defined
# in this repo (normally dmsai and dmsai_port, but
# this discovers whatever is actually there).
cmake .. \
-DDMOD_MODULE_VERSION="${{ steps.get_version.outputs.version }}" \
-DDMOD_CPU_FAMILY="${CPU_FAMILY}"

cmake --build .

echo "Build completed for ${{ matrix.arch_name }}"
ls -la packages/
echo "Build completed for CPU family: ${CPU_FAMILY}"
ls -la packages/ || echo "No packages directory"

- name: Add release notes and create release archives
run: |
set -e
BUILD_DIR="build_$ARCH_DIR_NAME"
BUILD_DIR="build_$BUILD_NAME"
TAG="${{ github.event.release.tag_name }}"
CPU="${{ matrix.cpu_family }}"
PACKAGES_DIR="$BUILD_DIR/packages"

if [ ! -d "$PACKAGES_DIR" ] || [ -z "$(ls -A "$PACKAGES_DIR")" ]; then
echo "Error: no packages found in $PACKAGES_DIR"
exit 1
fi

# A repo may define more than one module (e.g. a core + port split,
# or several independent modules) - package every subdirectory
# found under packages/, not just dmsai.
: > package-names.txt
for pkg_dir in "$PACKAGES_DIR"/*/; do
pkg=$(basename "$pkg_dir")
echo "$pkg" >> package-names.txt

echo "${{ github.event.release.body }}" > "${pkg_dir}RELEASE_NOTES.txt"
(cd "$pkg_dir" && zip -r "${OLDPWD}/${pkg}-${TAG}-${ARCH_DIR_NAME}.zip" .)
(cd "$pkg_dir" && zip -r "${OLDPWD}/${pkg}-${TAG}-${CPU}.zip" .)
done

echo "Created archives:"
ls -lh *-"${TAG}"-"${ARCH_DIR_NAME}".zip
ls -lh *-"${TAG}"-"${CPU}".zip
echo "Packages found:"
cat package-names.txt

- name: Upload artifact
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
Expand All @@ -127,7 +114,7 @@ jobs:

generate-versions-manifest:
name: Generate versions.dmm
needs: [discover-architectures, build-release]
needs: [discover-cpu-families, build-dmsai]
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -136,7 +123,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history to get all tags
fetch-depth: 0

- name: Download release artifacts
uses: actions/download-artifact@v4
Expand All @@ -150,10 +137,7 @@ jobs:
echo "# Generated automatically by CI" >> versions.dmm
echo "" >> versions.dmm

# Get all version tags (starting with 'v') and extract version numbers
VERSIONS=$(git tag -l 'v*' | sed 's/^v//' | sort -V | tr '\n' ' ' | sed 's/ $//')

# Remove vlatest from the list if present
VERSIONS=$(echo $VERSIONS | sed 's/\blatest\b//g' | xargs)

if [ -z "$VERSIONS" ]; then
Expand All @@ -164,9 +148,6 @@ jobs:

echo "Found versions: $VERSIONS"

# Union of package names discovered across every architecture build
# (the same set is expected everywhere, but union is safe even if
# some packages only exist for a subset of architectures).
PACKAGES=$(cat artifacts/release-*/package-names.txt | sort -u)
echo "Found packages: $PACKAGES"

Expand All @@ -186,7 +167,7 @@ jobs:

upload-release-assets:
name: Upload Release Assets
needs: [build-release, generate-versions-manifest]
needs: [build-dmsai, generate-versions-manifest]
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"files.associations": {
"dmsai.h": "c",
"dmsai_port.h": "c"
},
"C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json",
"C_Cpp.intelliSenseEngine": "default",
"C_Cpp.errorSquiggles": "enabled"
Expand Down
37 changes: 26 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.18)

set(DMOD_CPU_FAMILY "stm32f7" CACHE STRING "Target CPU family")
include(${CMAKE_CURRENT_SOURCE_DIR}/src/port/${DMOD_CPU_FAMILY}/config.cmake)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(NOT DEFINED DMOD_MODULE_VERSION)
Expand Down Expand Up @@ -27,7 +30,7 @@ set(DMOD_BUILD_TEMPLATES OFF CACHE BOOL "Build templates")
FetchContent_MakeAvailable(dmod)

project(dmsai VERSION ${DMOD_MODULE_VERSION}
DESCRIPTION "dmsai DMOD application module"
DESCRIPTION "dmsai DMOD library module"
LANGUAGES C CXX)

set(DMOD_DIR ${dmod_SOURCE_DIR} CACHE PATH "DMOD source directory")
Expand All @@ -42,32 +45,44 @@ set(DMOD_MODULE_NAME dmsai)
set(DMOD_AUTHOR_NAME "Patryk Kubiak")

# Stack size for the module (should be integer)
set(DMOD_STACK_SIZE 4096)

# Priority for the thread of the module (should be integer)
set(DMOD_PRIORITY 0)
set(DMOD_STACK_SIZE 1024)

# Path to the .dmr file - enables release package creation in build/packages/
set(DMOD_DMR_PATH ${CMAKE_CURRENT_SOURCE_DIR}/dmsai.dmr)

# List of MAL interfaces implemented by this module (leave empty if none)
set(DMOD_MAL_IMPLS )

# List of DIF interfaces implemented by this module (leave empty if none)
set(DMOD_DIF_IMPLS )

#
# dmod_add_executable - create an executable module
# it has the same signature as add_executable,
# dmod_add_library - create a library module
# it has the same signature as add_library
# and can be used in the same way after the creation
# (for example, to link libraries)
#
dmod_add_executable(${DMOD_MODULE_NAME} ${DMOD_MODULE_VERSION}
dmod_add_library(${DMOD_MODULE_NAME} ${DMOD_MODULE_VERSION}
# List of source files - can include C and C++ files
src/dmsai.c
src/dmsai_private.c
)

target_include_directories(${DMOD_MODULE_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_include_directories(${DMOD_MODULE_NAME}_if INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/include
)

# To depend on another module's headers, use:
# dmod_link_modules(${DMOD_MODULE_NAME}
# other_module@1.0
# )
dmod_link_modules(${DMOD_MODULE_NAME}
dmini
dmdrvi
)

add_subdirectory(src/port)
target_link_libraries(${DMOD_MODULE_NAME} ${DMOD_MODULE_NAME}_port_if)
enable_testing()
add_subdirectory(tests)
Loading
Loading