Skip to content

Commit

Permalink
* Github action to build the software greatly improved. Added arm64 &…
Browse files Browse the repository at this point in the history
… armhf cross compilation recipes & upload them to release section. Linux build now done on Ubuntu 20 as it outputs less dependant binary & use hardened profile on defaults. Some other build targets added as well, which are used for testing purposes (not uploaded to releases section).

* CMake config for software improved. Converted some vars to option() with description. And other small tweaks for a better compatibility.
  • Loading branch information
N-Storm committed Apr 29, 2024
1 parent bc2cfe4 commit 0bbde4a
Show file tree
Hide file tree
Showing 11 changed files with 468 additions and 45 deletions.
97 changes: 72 additions & 25 deletions .github/workflows/build-software.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,67 @@ on:
- "v*.*.*"
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
build:
runs-on: ${{ matrix.sys.os }}
container: ${{ matrix.sys.container }}

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false

matrix:
sys:
- { os: ubuntu-latest, shell: bash, c_compiler: gcc, binary_orig: digilivolo, binary_target: digilivolo-linux-x86_64 }
- { os: ubuntu-latest, shell: bash, c_compiler: clang }
- { os: windows-latest, shell: 'msys2 {0}', c_compiler: gcc, binary_orig: digilivolo.exe, binary_target: digilivolo-win-x86_64.exe }
- { os: windows-latest, shell: pwsh, c_compiler: gcc }
- { os: windows-latest, shell: pwsh, c_compiler: clang }
- { os: ubuntu-latest, container: 'ghcr.io/phusion/holy-build-box/hbb-64', shell: bash , c_compiler: gcc , binary_orig: digilivolo }
- { os: ubuntu-latest, container: 'debian:10' , shell: bash , c_compiler: gcc , binary_orig: digilivolo }
- { os: ubuntu-20.04 , shell: bash , c_compiler: gcc , binary_orig: digilivolo , binary_release: digilivolo-linux-x86_64 }
- { os: ubuntu-latest, container: 'debian' , shell: bash , crosscompile: armhf, binary_orig: digilivolo , binary_release: digilivolo-linux-armhf }
- { os: ubuntu-latest, container: 'debian' , shell: bash , crosscompile: arm64, binary_orig: digilivolo , binary_release: digilivolo-linux-arm64 }
- { os: ubuntu-20.04 , shell: bash , c_compiler: clang , binary_orig: digilivolo }
- { os: windows-latest , shell: 'msys2 {0}', c_compiler: gcc , binary_orig: digilivolo.exe, binary_release: digilivolo-win-x86_64.exe }
- { os: windows-latest , shell: pwsh , c_compiler: gcc , binary_orig: digilivolo.exe }
- { os: windows-latest , shell: pwsh , c_compiler: clang , binary_orig: digilivolo.exe }
build_type: [Release]

defaults:
run:
shell: ${{ matrix.sys.shell }}

steps:
- uses: ConorMacBride/install-package@v1

- name: Install required prerequisite packages on the container and configure git
if: matrix.sys.container != ''
run: |
apt update || yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm
apt -y full-upgrade || yum update -y
apt install -y sudo git dialog python3 python3-pip python3-setuptools curl wget || yum install -y sudo git dialog python3 python3-pip python3-setuptools ninja-build make cmake3 libusb-devel libudev-devel curl wget
git --version
git config --global --add safe.directory /__w/dl/dl
echo
cat /etc/os-release
- name: Install packages required for the workflow and build deps
uses: ConorMacBride/install-package@v1
if: matrix.sys.container != 'ghcr.io/phusion/holy-build-box/hbb-64'
with:
apt: libudev-dev

- uses: actions/checkout@v4
apt: libudev-dev sudo gcc cmake build-essential make sudo libusb-dev libc6-dev pkg-config file ninja-build clang

- name: Checkout repo
uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: '[HBB] Create symlink cmake -> cmake3'
if: matrix.sys.container == 'ghcr.io/phusion/holy-build-box/hbb-64'
run: ln -s /usr/bin/cmake3 /usr/bin/cmake

- name: Install Ninja
if: matrix.sys.shell != 'msys2 {0}'
id: ninja
if: matrix.sys.shell == 'pwsh'
uses: turtlesec-no/get-ninja@main

- name: 'Setup MSYS2'
- name: Setup MSYS2 UCRT64
if: matrix.sys.shell == 'msys2 {0}'
uses: msys2/setup-msys2@v2
with:
Expand All @@ -57,31 +82,53 @@ jobs:
cmake:p
ninja:p
- name: Configure CMake
- name: Install cross compiling toolchain and deps
if: ${{ matrix.sys.crosscompile != '' }}
shell: bash
run: |
echo "Installing cross toolchain for ${{ matrix.sys.crosscompile }}"
sudo dpkg --add-architecture ${{ matrix.sys.crosscompile }}
sudo apt update
sudo apt install -y crossbuild-essential-${{ matrix.sys.crosscompile }}
sudo apt install -y libudev-dev:${{ matrix.sys.crosscompile }} libusb-dev:${{ matrix.sys.crosscompile }} libc6-dev:${{ matrix.sys.crosscompile }} pkg-config:${{ matrix.sys.crosscompile }}
- name: Configure CMake project
run: >
cmake -B software/build
-DCMAKE_C_COMPILER=${{ matrix.sys.c_compiler }}
cmake -B software/build ${{ env.CMAKE_TOOLCHAIN_FILE_OPT }} ${{ env.CMAKE_C_COMPILER_OPT }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DUSE_SYSTEM_HIDAPI=false
-G Ninja
-S software
env:
CMAKE_TOOLCHAIN_FILE_OPT: ${{ matrix.sys.crosscompile == '' && ' ' || format('-DCMAKE_TOOLCHAIN_FILE=cmake/{0}-linux-toolchain.cmake', matrix.sys.crosscompile) }}
CMAKE_C_COMPILER_OPT: ${{ matrix.sys.c_compiler == '' && ' ' || format('-DCMAKE_C_COMPILER={0}', matrix.sys.c_compiler) }}

- name: Build
- name: Build software
run: cmake --build software/build

- name: Rename binary
if: ${{ matrix.sys.binary_target != '' }}
- name: Print some info on compiled binary
shell: bash
run: |
echo "=== objdump -x ==="
objdump -x software/build/${{ matrix.sys.binary_orig }} || /bin/true
echo "=== size -A ==="
size -A software/build/${{ matrix.sys.binary_orig }} || /bin/true
echo "=== ldd -v ==="
ldd -v software/build/${{ matrix.sys.binary_orig }} || /bin/true
echo "=== file & ls ==="
file software/build/${{ matrix.sys.binary_orig }} || /bin/true
ls -l software/build/${{ matrix.sys.binary_orig }} || /bin/true
- name: Rename binary to release target
if: ${{ matrix.sys.binary_release != '' }}
shell: bash
run: |
mv software/build/${{ matrix.sys.binary_orig }} software/build/${{ matrix.sys.binary_target }}
ls -l software/build/${{ matrix.sys.binary_target }}
file software/build/${{ matrix.sys.binary_target }}
mv software/build/${{ matrix.sys.binary_orig }} software/build/${{ matrix.sys.binary_release }}
- name: Make and upload release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/') && matrix.sys.binary_target != ''
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/') && matrix.sys.binary_release != ''
with:
fail_on_unmatched_files: false
generate_release_notes: true
make_latest: true
files: software/build/${{ matrix.sys.binary_target }}
files: software/build/${{ matrix.sys.binary_release }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@
*.exe
*.out
*.app

*.bak
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ USB HID Reports. As well as other various improvements.
Download compiled firmware from [releases page](https://github.com/N-Storm/DigiLivolo/releases) or build from
sources (see below for instructions).

Software binaries for Linux/Windows x86_64 can be downloaded from
Software binaries for Windows x64, Linux x86_64 and ARM can be downloaded from
[releases page](https://github.com/N-Storm/DigiLivolo/releases) as well. Instructions for building from
sources are provided below.

Expand Down Expand Up @@ -135,9 +135,11 @@ it from there. Requires PlatformIO plugin installed.
From the `DigiLivolo/software` directory:

```shell
cmake -Wno-dev -B ./build . && cmake --build ./build
cmake -DCMAKE_BUILD_TYPE=Release -Wno-dev -B ./build . && cmake --build ./build
```

Or simply run `bash build.sh` script from this directory.

For building on Windows [MSYS2](https://www.msys2.org/) UCRT64 has been tested to work.

Resulting binary should be compiled as `build/digilivolo[.exe]`.
Expand Down
41 changes: 25 additions & 16 deletions software/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
set(PROJECT_NAME "digilivolo")
project(${PROJECT_NAME} C)

option(USE_SYSTEM_HIDAPI "Don't build included hidapi, use system installed version instead" FALSE)
option(HIDAPI_WITH_LIBUSB "Build hidapi with libusb interface" FALSE)
option(BUILD_SHARED_LIBS "Link target & deps dynamically where possible" FALSE)

if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -std=gnu11 -flto -ffunction-sections -fdata-sections -ffat-lto-objects -Wall -Wl,--warn-common -Wl,--gc-sections")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Og -std=gnu11 -Wall -Wl,--warn-common")
endif()
set(HIDAPI_WITH_LIBUSB FALSE)
set(BUILD_SHARED_LIBS FALSE) # HIDAPI as static library on all platforms

if(POLICY CMP0074)
# allow using hidapi_ROOT if CMake supports it
Expand All @@ -27,26 +30,32 @@ execute_process(

message(STATUS "Project: ${PROJECT_NAME} ${GIT_VERSION}")

if(NOT USE_SYSTEM_HIDAPI)
add_subdirectory(lib/hidapi)
message(STATUS "hidapi will be built from sources")
else()
message(STATUS "Finding library hidapi")
find_package(hidapi 0.13 REQUIRED)
endif()

message(STATUS "Using HIDAPI: ${hidapi_VERSION}")

add_subdirectory(lib/argp-standalone)

configure_file(src/git_version.h.in src/git_version.h @ONLY)
add_executable(${PROJECT_NAME} src/args.c src/digilivolo.c src/usb_func.c)
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/src")
target_link_libraries(${PROJECT_NAME} hidapi::hidapi argp-standalone)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
find_package(argp)

if(NOT ARGP_FOUND)
add_subdirectory(lib/argp-standalone)
target_link_libraries(${PROJECT_NAME} argp-standalone)
endif()

if(USE_SYSTEM_HIDAPI)
message(STATUS "Finding library hidapi")
find_package(HIDAPI 0.13 REQUIRED)
target_link_libraries(${PROJECT_NAME} HIDAPI::hidapi)
else()
add_subdirectory(lib/hidapi)
message(STATUS "hidapi will be built from sources")
target_link_libraries(${PROJECT_NAME} hidapi::hidapi)
message(STATUS "Using HIDAPI: ${hidapi_VERSION}")
endif()

# Strip binary for release builds
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:${PROJECT_NAME}>
COMMAND $<$<CONFIG:Release>:${CMAKE_STRIP}> $<$<CONFIG:Release>:$<TARGET_FILE:${PROJECT_NAME}>>
VERBATIM
)
2 changes: 1 addition & 1 deletion software/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fi

# cmake -DUSE_SYSTEM_HIDAPI=false -B ${SCRIPT_DIR}/build -G 'Unix Makefiles' ${SCRIPT_DIR}
# cmake -DUSE_SYSTEM_HIDAPI=false -B ${SCRIPT_DIR}/build -G 'Ninja' -Wno-dev ${SCRIPT_DIR}
cmake -DUSE_SYSTEM_HIDAPI=false -Wno-dev -B ${SCRIPT_DIR}/build ${SCRIPT_DIR}
cmake -DCMAKE_BUILD_TYPE=Release -DUSE_SYSTEM_HIDAPI=false -Wno-dev -B ${SCRIPT_DIR}/build ${SCRIPT_DIR}

cmake --build ${SCRIPT_DIR}/build

Expand Down
Loading

0 comments on commit 0bbde4a

Please sign in to comment.