Skip to content

Commit cf0a8bc

Browse files
Libcanard v2.0 (#182)
* Drop canard_dsdl, use Nunavut instead * Upgrade CI to LLVM 13 * Actualize license headers * Support redundant transmission queues and use more consistent public field naming * Ditch the deprecated canardRxAccept(), rename canardRxAccept2() * Refactor the API to eliminate the need to cast away const qualifiers; fixes #175 * Tighten up memory checking in the test suite -- add canaries * Fix race condition in the roundtrip test * Do not use Catch2 macros from non-main thread because it is not thread-safe * Support CANARD_CONFIG_HEADER * CI: add style_check job * Use AVL tree in the transmission queue * Remove all linked lists * Reduce indirection, pointer casts, and memory footprint by exposing the AVL tree in the public API * Disable C++-specific warnings as they make no sense for a C library * Add table-based CRC option (#186) * CI: disable SonarCloud on forks * Add docker utilities (#187) * Add acceptance filter configuration helpers (#171) Co-authored-by: Kalyan Sriram <coder.kalyan@gmail.com>
1 parent 2d44945 commit cf0a8bc

30 files changed

+3759
-2473
lines changed

.github/workflows/main.yml

+95-115
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,10 @@
11
name: Main Workflow
2-
3-
on:
4-
push:
5-
branches: [ master ]
6-
pull_request:
7-
branches: [ master, actions ]
8-
2+
on: [push, pull_request]
93
env:
10-
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
11-
BUILD_TYPE: Release
12-
4+
LLVM_VERSION: 13
135
jobs:
146
debug:
15-
env:
16-
BUILD_TYPE: Debug
17-
18-
runs-on: ubuntu-latest
19-
20-
strategy:
21-
matrix:
22-
toolchain: ['clang', 'gcc']
23-
include:
24-
- toolchain: gcc
25-
c-compiler: gcc
26-
cxx-compiler: g++
27-
- toolchain: clang
28-
c-compiler: clang-11
29-
cxx-compiler: clang++-11
30-
31-
steps:
32-
- uses: actions/checkout@v2
33-
34-
- name: Install Dependencies
35-
run: sudo apt install gcc-multilib g++-multilib clang-tidy-11 clang-format-11
36-
37-
- name: Configure CMake
38-
run: cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_C_COMPILER=${{ matrix.c-compiler }} -DCMAKE_CXX_COMPILER=${{ matrix.cxx-compiler }} tests
39-
40-
- name: Build
41-
working-directory: ${{github.workspace}}/build
42-
run: make VERBOSE=1
43-
44-
- name: Test
45-
working-directory: ${{github.workspace}}/build
46-
run: make test
47-
48-
release:
49-
env:
50-
BUILD_TYPE: Release
51-
527
runs-on: ubuntu-latest
53-
548
strategy:
559
matrix:
5610
toolchain: ['clang', 'gcc']
@@ -59,95 +13,104 @@ jobs:
5913
c-compiler: gcc
6014
cxx-compiler: g++
6115
- toolchain: clang
62-
c-compiler: clang-11
63-
cxx-compiler: clang++-11
64-
16+
c-compiler: clang
17+
cxx-compiler: clang++
6518
steps:
6619
- uses: actions/checkout@v2
67-
68-
- name: Install Dependencies
69-
run: sudo apt install gcc-multilib g++-multilib
70-
71-
- name: Configure CMake
72-
run: cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_C_COMPILER=${{ matrix.c-compiler }} -DCMAKE_CXX_COMPILER=${{ matrix.cxx-compiler }} -DNO_STATIC_ANALYSIS=1 tests
73-
74-
- name: Build
75-
working-directory: ${{github.workspace}}/build
76-
run: make VERBOSE=1
77-
78-
- name: Test
79-
working-directory: ${{github.workspace}}/build
80-
run: make test
81-
82-
minsizerel:
83-
env:
84-
BUILD_TYPE: MinSizeRel
85-
20+
- run: |
21+
wget https://apt.llvm.org/llvm.sh
22+
chmod +x llvm.sh
23+
sudo ./llvm.sh $LLVM_VERSION
24+
sudo apt-get -y install gcc-multilib g++-multilib clang-tidy-$LLVM_VERSION
25+
sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-$LLVM_VERSION 50
26+
clang-tidy --version
27+
- run: >
28+
cmake
29+
-B ${{ github.workspace }}/build
30+
-DCMAKE_BUILD_TYPE=Debug
31+
-DCMAKE_C_COMPILER=${{ matrix.c-compiler }}
32+
-DCMAKE_CXX_COMPILER=${{ matrix.cxx-compiler }}
33+
tests
34+
- working-directory: ${{github.workspace}}/build
35+
run: |
36+
make VERBOSE=1
37+
make test
38+
- uses: actions/upload-artifact@v2
39+
if: always()
40+
with:
41+
name: ${{github.job}}
42+
path: ${{github.workspace}}/**/*
43+
retention-days: 2
44+
45+
optimizations:
8646
runs-on: ubuntu-latest
87-
8847
strategy:
8948
matrix:
9049
toolchain: ['clang', 'gcc']
50+
build_type: [Release, MinSizeRel]
9151
include:
9252
- toolchain: gcc
9353
c-compiler: gcc
9454
cxx-compiler: g++
9555
- toolchain: clang
96-
c-compiler: clang-11
97-
cxx-compiler: clang++-11
98-
56+
c-compiler: clang
57+
cxx-compiler: clang++
9958
steps:
10059
- uses: actions/checkout@v2
101-
102-
- name: Install Dependencies
103-
run: sudo apt install gcc-multilib g++-multilib
104-
105-
- name: Configure CMake
106-
run: cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_C_COMPILER=${{ matrix.c-compiler }} -DCMAKE_CXX_COMPILER=${{ matrix.cxx-compiler }} -DNO_STATIC_ANALYSIS=1 tests
107-
108-
- name: Build
109-
working-directory: ${{github.workspace}}/build
110-
run: make VERBOSE=1
111-
112-
- name: Test
113-
working-directory: ${{github.workspace}}/build
114-
run: make test
60+
- run: sudo apt install gcc-multilib g++-multilib
61+
- run: >
62+
cmake
63+
-B ${{ github.workspace }}/build
64+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
65+
-DCMAKE_C_COMPILER=${{ matrix.c-compiler }}
66+
-DCMAKE_CXX_COMPILER=${{ matrix.cxx-compiler }}
67+
-DNO_STATIC_ANALYSIS=1
68+
tests
69+
- working-directory: ${{github.workspace}}/build
70+
run: |
71+
make VERBOSE=1
72+
make test
73+
- uses: actions/upload-artifact@v2
74+
if: always()
75+
with:
76+
name: ${{github.job}}
77+
path: ${{github.workspace}}/**/*
78+
retention-days: 2
11579

11680
avr:
81+
runs-on: ubuntu-latest
11782
env:
11883
mcu: at90can64
11984
flags: -Wall -Wextra -Werror -pedantic -Wconversion -Wtype-limits
120-
85+
steps:
86+
- uses: actions/checkout@v2
87+
- run: |
88+
sudo apt install gcc-avr avr-libc
89+
avr-gcc --version
90+
- run: avr-gcc libcanard/*.c -c -std=c99 -mmcu=${{ env.mcu }} ${{ env.flags }}
91+
- run: avr-gcc libcanard/*.c -c -std=c11 -mmcu=${{ env.mcu }} ${{ env.flags }}
92+
- run: avr-gcc libcanard/*.c -c -std=gnu99 -mmcu=${{ env.mcu }} ${{ env.flags }}
93+
- run: avr-gcc libcanard/*.c -c -std=gnu11 -mmcu=${{ env.mcu }} ${{ env.flags }}
94+
95+
style_check:
12196
runs-on: ubuntu-latest
122-
12397
steps:
12498
- uses: actions/checkout@v2
125-
126-
- name: Install Dependencies
127-
run: sudo apt install gcc-avr avr-libc
128-
129-
- name: Build C99
130-
run: avr-gcc libcanard/*.c -c -std=c99 -mmcu=${{ env.mcu }} ${{ env.flags }}
131-
132-
- name: Build C11
133-
run: avr-gcc libcanard/*.c -c -std=c11 -mmcu=${{ env.mcu }} ${{ env.flags }}
134-
135-
- name: Build GNU99
136-
run: avr-gcc libcanard/*.c -c -std=gnu99 -mmcu=${{ env.mcu }} ${{ env.flags }}
137-
138-
- name: Build GNU11
139-
run: avr-gcc libcanard/*.c -c -std=gnu11 -mmcu=${{ env.mcu }} ${{ env.flags }}
99+
- uses: DoozyX/clang-format-lint-action@v0.13
100+
with:
101+
source: './libcanard ./tests'
102+
exclude: './tests/catch'
103+
extensions: 'c,h,cpp,hpp'
104+
clangFormatVersion: ${{ env.LLVM_VERSION }}
140105

141106
sonarcloud:
107+
runs-on: ubuntu-latest
142108
env:
143109
SONAR_SCANNER_VERSION: 4.6.1.2450
144110
SONAR_SERVER_URL: "https://sonarcloud.io"
145111
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory
146112
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
147113
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
148-
149-
runs-on: ubuntu-latest
150-
151114
steps:
152115
- uses: actions/checkout@v2
153116
with:
@@ -156,7 +119,7 @@ jobs:
156119
- name: Install Dependencies
157120
run: sudo apt install gcc-multilib g++-multilib
158121

159-
- name: Set up JDK 11
122+
- name: Set up JDK
160123
uses: actions/setup-java@v1
161124
with:
162125
java-version: 11
@@ -173,7 +136,7 @@ jobs:
173136
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip
174137
run: |
175138
mkdir -p $HOME/.sonar
176-
curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }}
139+
curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }}
177140
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
178141
echo "$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin" >> $GITHUB_PATH
179142
@@ -190,10 +153,27 @@ jobs:
190153
cmake tests -DCMAKE_BUILD_TYPE=Debug -DNO_STATIC_ANALYSIS=1 -DCMAKE_C_FLAGS='-DNDEBUG=1'
191154
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} make all
192155
make test
193-
gcov-10 --preserve-paths --long-file-names $(find CMakeFiles/test_private_cov.dir -name '*.gcno')
194-
gcov-10 --preserve-paths --long-file-names $(find CMakeFiles/test_private_le_cov.dir -name '*.gcno')
195-
gcov-10 --preserve-paths --long-file-names $(find CMakeFiles/test_public_cov.dir -name '*.gcno')
156+
gcov --preserve-paths --long-file-names $(find CMakeFiles/test_private_cov.dir -name '*.gcno')
157+
gcov --preserve-paths --long-file-names $(find CMakeFiles/test_public_cov.dir -name '*.gcno')
196158
197159
- name: Run sonar-scanner
198-
run: |
199-
sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" --define sonar.login=${{ secrets.SONAR_TOKEN }}
160+
# Don't run sonar-scanner on builds originating from forks due to secrets not being available
161+
run: >
162+
[ -z "$SONAR_TOKEN" ] || sonar-scanner
163+
--define sonar.organization=uavcan
164+
--define sonar.projectName=libcanard
165+
--define sonar.projectKey=libcanard
166+
--define sonar.sources=libcanard
167+
--define sonar.exclusions=libcanard/cavl.h
168+
--define sonar.cfamily.gcov.reportsPath=.
169+
--define sonar.cfamily.cache.enabled=false
170+
--define sonar.cfamily.threads=2
171+
--define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"
172+
--define sonar.host.url="${{ env.SONAR_SERVER_URL }}"
173+
174+
- uses: actions/upload-artifact@v2
175+
if: always()
176+
with:
177+
name: ${{github.job}}
178+
path: ${{github.workspace}}/**/*
179+
retention-days: 2

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,5 @@ build-avr/
4848
!**/.idea/dictionaries
4949
!**/.idea/dictionaries/*
5050

51-
# Generated files
52-
dsdlc_generated/
53-
5451
# Pycache
5552
__pycache__/

.idea/dictionaries/pavel.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CONTRIBUTING.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ The code shall follow applicable high-reliability coding guidelines as explained
88
The implementation shall be fully compliant with the UAVCAN/CAN specification.
99

1010
The implementation and the API should be kept simple.
11-
The core library `canard.c` (that is, excluding the optional DSDL presentation layer extension) shall never become
12-
larger than 1000 logical lines of code.
13-
This restriction ensures that the library is kept simple and easy to validate and verify.
1411
There will be no high-level abstractions -- if that is desired, other implementations of UAVCAN should be used.
1512

1613
The library is intended for deeply embedded systems where the resources may be scarce.
@@ -53,12 +50,13 @@ to prevent non-compliant code from being accepted into upstream.
5350

5451
## Tools
5552

56-
The following tools are required to conduct library development locally:
53+
The following tools are required to conduct library development locally
54+
(check the CI workflow files for the required versions):
5755

58-
- GCC v10 or newer.
59-
- Clang and Clang-Tools v11 or newer.
60-
- CMake v3.12 or newer.
61-
- An AMD64 machine.
56+
- GCC
57+
- Clang and Clang-Tools
58+
- CMake
59+
- An AMD64 machine
6260

6361
### Clang-Tidy
6462

@@ -102,6 +100,10 @@ We would welcome contributions implementing CI/CD testing against popular embedd
102100
the ARM Cortex M series and AVR in an emulator.
103101
As a high-integrity library, the Libcanard test suite should provide full test coverage for all commonly used platforms.
104102

103+
**WARNING:**
104+
[Catch2 is NOT thread-safe!](https://github.com/catchorg/Catch2/blob/1e379de9d7522b294e201700dcbb36d4f8037301/docs/limitations.md#thread-safe-assertions)
105+
Never use `REQUIRE` etc. anywhere but the main thread.
106+
105107
## Releasing
106108

107109
Simply create a new release on GitHub: <https://github.com/UAVCAN/libcanard/releases/new>

0 commit comments

Comments
 (0)