Skip to content

Commit 140995f

Browse files
Repair the build (#442)
This is a response to https://forum.opencyphal.org/t/building-libcyphal/2427 - Added brief build instructions to the README. The point of this change is mostly to indicate that one does not need to "build" libcyphal to use it because it is header-only. Building is only needed for development or verification. - Fixed broken coverage measurement and updated CI workflow dependencies. Oh boy. - Fixed the missing cavl error by pulling cavl from its own repository. Libcanard does no longer ship cavl and libudpard will eventually be updated to not do that either. - The libcanard reference was updated to `master` instead of `v4`, temporarily until v4 is out. The code that leverages libcanard has been doctored to accommodate API changes in v4 (still officially unstable but I am not planning on changing it so it's kinda stable after all). - Treat `NO_STATIC_ANALYSIS` properly.
1 parent 8716d16 commit 140995f

File tree

10 files changed

+119
-54
lines changed

10 files changed

+119
-54
lines changed

.github/workflows/sonar.yml

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ jobs:
1717
runs-on: ubuntu-latest
1818
container: ghcr.io/opencyphal/toolshed:ts24.4.3
1919
steps:
20-
- uses: actions/checkout@v4
20+
- uses: actions/checkout@v5
2121
with:
2222
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
2323
- name: get nunavut
2424
run: |
2525
pip install --break-system-packages git+https://github.com/OpenCyphal/[email protected]
26-
- name: Install sonar-scanner and build-wrapper
27-
uses: SonarSource/sonarcloud-github-c-cpp@v2
26+
- name: Install build-wrapper
27+
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v6
2828
- name: Run tests
2929
env:
3030
GTEST_COLOR: yes
@@ -43,7 +43,7 @@ jobs:
4343
cmake --build . --target test/unittest/coverage.xml
4444
cmake --build . --target docs/examples/coverage.xml
4545
- name: upload-artifacts
46-
uses: actions/upload-artifact@v4
46+
uses: actions/upload-artifact@v5
4747
with:
4848
name: Coverage-14-gcc
4949
path: |
@@ -53,27 +53,28 @@ jobs:
5353
build/*/**/gcovr_html/*.*
5454
if-no-files-found: error
5555
- name: Run sonar-scanner
56+
uses: SonarSource/sonarqube-scan-action@v6
5657
env:
5758
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5859
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
59-
run: >
60-
sonar-scanner
61-
-X
62-
--define sonar.organization=opencyphal-garage
63-
--define sonar.projectKey=OpenCyphal-Garage_libcyphal
64-
--define sonar.projectName=libcyphal
65-
--define sonar.projectVersion=1.0
66-
--define sonar.sources=include,test/unittest/sonar.cpp
67-
--define sonar.tests=test/unittest,docs/examples
68-
--define sonar.test.inclusions=test_*.cpp,example_*.cpp
69-
--define sonar.sourceEncoding=UTF-8
70-
--define sonar.host.url=https://sonarcloud.io
71-
--define sonar.cfamily.ignoreHeaderComments=false
72-
--define sonar.coverage.exclusions="test/unittest/**/*,docs/examples/**/*,**/sonar.cpp"
73-
--define sonar.cpd.exclusions="test/unittest/**/*,docs/examples/**/*,**/sonar.cpp"
74-
--define sonar.cfamily.compile-commands="build/compile_commands.json"
75-
--define sonar.cfamily.reportingCppStandardOverride=c++14
76-
--define sonar.coverageReportPaths="build/test/unittest/coverage.xml,build/docs/examples/coverage.xml"
77-
--define sonar.issue.ignore.multicriteria=r1
78-
--define sonar.issue.ignore.multicriteria.r1.ruleKey=cpp:S3230
79-
--define sonar.issue.ignore.multicriteria.r1.resourceKey=**
60+
with:
61+
args: >
62+
-X
63+
--define sonar.organization=opencyphal-garage
64+
--define sonar.projectKey=OpenCyphal-Garage_libcyphal
65+
--define sonar.projectName=libcyphal
66+
--define sonar.projectVersion=1.0
67+
--define sonar.sources=include,test/unittest/sonar.cpp
68+
--define sonar.tests=test/unittest,docs/examples
69+
--define sonar.test.inclusions=test_*.cpp,example_*.cpp
70+
--define sonar.sourceEncoding=UTF-8
71+
--define sonar.host.url=https://sonarcloud.io
72+
--define sonar.cfamily.ignoreHeaderComments=false
73+
--define sonar.coverage.exclusions="test/unittest/**/*,docs/examples/**/*,**/sonar.cpp"
74+
--define sonar.cpd.exclusions="test/unittest/**/*,docs/examples/**/*,**/sonar.cpp"
75+
--define sonar.cfamily.compile-commands=build/compile_commands.json
76+
--define sonar.cfamily.reportingCppStandardOverride=c++14
77+
--define sonar.cfamily.cobertura.reportPaths=build/test/unittest/coverage.xml,build/docs/examples/coverage.xml
78+
--define sonar.issue.ignore.multicriteria=r1
79+
--define sonar.issue.ignore.multicriteria.r1.ruleKey=cpp:S3230
80+
--define sonar.issue.ignore.multicriteria.r1.resourceKey=**

.github/workflows/tests.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
runs-on: ubuntu-latest
1919
container: ghcr.io/opencyphal/toolshed:ts24.4.3
2020
steps:
21-
- uses: actions/checkout@v4
21+
- uses: actions/checkout@v5
2222
- name: Cache ext modules
2323
id: libcyphal-ext
2424
uses: actions/cache@v4
@@ -59,7 +59,7 @@ jobs:
5959
std: 14
6060
toolchain: gcc
6161
steps:
62-
- uses: actions/checkout@v4
62+
- uses: actions/checkout@v5
6363
- name: Cache ext modules
6464
id: libcyphal-ext
6565
uses: actions/cache@v4
@@ -86,7 +86,7 @@ jobs:
8686
if: ${{ runner.debug == '1' }}
8787
run: ls -lAhR build/
8888
- name: upload-artifacts
89-
uses: actions/upload-artifact@v4
89+
uses: actions/upload-artifact@v5
9090
with:
9191
name: ${{ matrix.build_flavor }}-${{ matrix.std }}-${{ matrix.toolchain }}
9292
path: |
@@ -104,7 +104,7 @@ jobs:
104104
container: ghcr.io/opencyphal/toolshed:ts24.4.3
105105
needs: [warmup]
106106
steps:
107-
- uses: actions/checkout@v4
107+
- uses: actions/checkout@v5
108108
- name: Cache ext modules
109109
id: libcyphal-ext
110110
uses: actions/cache@v4
@@ -129,12 +129,12 @@ jobs:
129129
uses: actions/configure-pages@v5
130130
- name: Upload docs
131131
if: ${{ github.event_name != 'pull_request' }}
132-
uses: actions/upload-pages-artifact@v3
132+
uses: actions/upload-pages-artifact@v4
133133
with:
134134
path: "build/docs/html/"
135135
- name: upload-pr-docs
136136
if: ${{ github.event_name == 'pull_request' }}
137-
uses: actions/upload-artifact@v4
137+
uses: actions/upload-artifact@v5
138138
with:
139139
name: pr-docs
140140
path: "build/docs/html/"

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ include(cmake/CMakeCommon.cmake REQUIRED)
1010
project(libcyphal
1111
VERSION ${LIBCYPHAL_VERSION}
1212
LANGUAGES CXX C
13-
HOMEPAGE_URL https://github.com/OpenCyphal-Garage/libcyphal
13+
HOMEPAGE_URL https://github.com/OpenCyphal/libcyphal
1414
)
1515

1616
# Use -DNO_STATIC_ANALYSIS=1 to suppress static analysis.
1717
# If not suppressed, the tools used here shall be available, otherwise the build will fail.
18+
option(NO_STATIC_ANALYSIS "Disable static analysis (e.g. clang-tidy). If OFF, the tools must be available." OFF)
1819
if (NOT NO_STATIC_ANALYSIS)
1920
# clang-tidy (separate config files per directory)
2021
find_program(clang_tidy NAMES clang-tidy)

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,18 @@
1212
Portable reference implementation of the [Cyphal protocol stack](https://opencyphal.org) in C++ for embedded systems, Linux, and POSIX-compliant RTOSs.
1313

1414
Cyphal is a lightweight protocol designed for reliable communication in aerospace and robotic applications over robust vehicular networks.
15+
16+
## Building
17+
18+
**You don't need to build LibCyphal to use it** since this is a header-only library. You will need to build the transport libraries though (libcanard, libudpard, etc), which is covered in their respective documentation.
19+
20+
If you want to build libcyphal for development purposes, you may use containerized toolchains as covered in CONTRIBUTING.md. Otherwise, you may want to disable static analysis:
21+
22+
```shell
23+
mkdir build
24+
cd build
25+
cmake .. -DNO_STATIC_ANALYSIS=1
26+
make -j16
27+
```
28+
29+
If you're facing obscure DSDL compilation issues, ensure you have Nunavut installed and unset `CYPHAL_PATH`.

cmake/compiler_flag_sets/default.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ list(APPEND C_FLAG_SET
3232
"-Wswitch-enum"
3333
"-Wtype-limits"
3434
"-Wno-error=array-bounds"
35+
"-Wno-error=attributes"
3536
)
3637

3738
set(CXX_FLAG_SET ${C_FLAG_SET})

cmake/modules/Findcavl.cmake

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#
2+
# Copyright (C) OpenCyphal Development Team <opencyphal.org>
3+
# Copyright Amazon.com Inc. or its affiliates.
4+
# SPDX-License-Identifier: MIT
5+
#
6+
7+
include(FetchContent)
8+
set(cavl_GIT_REPOSITORY "https://github.com/pavel-kirienko/cavl")
9+
set(cavl_GIT_TAG "c-2.1.0")
10+
11+
FetchContent_Declare(
12+
cavl
13+
GIT_REPOSITORY ${cavl_GIT_REPOSITORY}
14+
GIT_TAG ${cavl_GIT_TAG}
15+
)
16+
17+
# +--------------------------------------------------------------------------------------------------------------------+
18+
# Because we use FetchContent_Populate to specify a source directory other than the default we have
19+
# to manually manage the <lowercaseName>_POPULATED, <lowercaseName>_SOURCE_DIR, and <lowercaseName>_BINARY_DIR
20+
# variables normally set by this method.
21+
# See https://cmake.org/cmake/help/latest/module/FetchContent.html?highlight=fetchcontent#command:fetchcontent_populate
22+
# for more information.
23+
# This is not ideal, to copy-and-paste this code, but it is the only way to redirect fetch content to an in-source
24+
# directory. An upstream patch to cmake is needed to fix this.
25+
get_property(cavl_POPULATED GLOBAL PROPERTY cavl_POPULATED)
26+
if(NOT cavl_POPULATED)
27+
cmake_path(APPEND CETLVAST_EXTERNAL_ROOT "cavl" OUTPUT_VARIABLE LOCAL_cavl_SOURCE_DIR)
28+
if (NOT ${FETCHCONTENT_FULLY_DISCONNECTED})
29+
FetchContent_Populate(
30+
cavl
31+
SOURCE_DIR ${LOCAL_cavl_SOURCE_DIR}
32+
GIT_REPOSITORY ${cavl_GIT_REPOSITORY}
33+
GIT_TAG ${cavl_GIT_TAG}
34+
)
35+
else()
36+
set(cavl_SOURCE_DIR ${LOCAL_cavl_SOURCE_DIR})
37+
endif()
38+
set_property(GLOBAL PROPERTY cavl_POPULATED true)
39+
endif()
40+
41+
add_project_library(
42+
NAME cavl2_c
43+
HEADER_PATH "${cavl_SOURCE_DIR}/c"
44+
)

cmake/modules/Findcyphal.cmake

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
if (NOT TARGET cyphal)
44

55
include(ProjectLibrary)
6+
find_package(cavl REQUIRED)
67
find_package(libcanard REQUIRED)
78
find_package(libudpard REQUIRED)
89
find_package(cetl REQUIRED)
@@ -23,23 +24,19 @@ add_project_library(
2324
)
2425

2526
find_package(clangformat)
26-
27-
if (clangformat_FOUND)
28-
29-
# define a dry-run version that we always run.
30-
enable_clang_format_check_for_directory(
31-
DIRECTORY ${LIBCYPHAL_INCLUDE}
32-
GLOB_PATTERN "**/*.hpp"
33-
ADD_TO_ALL
34-
)
35-
36-
# provide an in-place format version as a helper that must be manually run.
37-
enable_clang_format_check_for_directory(
38-
DIRECTORY ${LIBCYPHAL_INCLUDE}
39-
GLOB_PATTERN "**/*.hpp"
40-
FORMAT_IN_PLACE
41-
)
42-
27+
if (clangformat_FOUND AND NOT NO_STATIC_ANALYSIS)
28+
# define a dry-run version that we always run.
29+
enable_clang_format_check_for_directory(
30+
DIRECTORY ${LIBCYPHAL_INCLUDE}
31+
GLOB_PATTERN "**/*.hpp"
32+
ADD_TO_ALL
33+
)
34+
# provide an in-place format version as a helper that must be manually run.
35+
enable_clang_format_check_for_directory(
36+
DIRECTORY ${LIBCYPHAL_INCLUDE}
37+
GLOB_PATTERN "**/*.hpp"
38+
FORMAT_IN_PLACE
39+
)
4340
endif()
4441

4542
# +---------------------------------------------------------------------------+

cmake/modules/Findlibcanard.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
include(FetchContent)
1010

1111
set(libcanard_GIT_REPOSITORY "https://github.com/OpenCyphal/libcanard.git")
12-
set(libcanard_GIT_TAG "v4")
12+
set(libcanard_GIT_TAG "master") # TODO: update to a release tag
1313

1414
FetchContent_Declare(
1515
libcanard
@@ -73,5 +73,6 @@ add_project_library(
7373
STATIC
7474
FPIC
7575
)
76+
target_link_libraries(canard PRIVATE cavl2_c)
7677

77-
endif()
78+
endif()

cmake/modules/Findlibudpard.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include(FindPackageHandleStandardArgs)
99
include(ProjectLibrary)
1010

1111
set(libudpard_GIT_REPOSITORY "https://github.com/OpenCyphal-garage/libudpard.git")
12-
set(libudpard_GIT_TAG "v2")
12+
set(libudpard_GIT_TAG "main") # TODO: update to a release tag
1313

1414
FetchContent_Declare(
1515
libudpard

include/libcyphal/transport/can/can_transport_impl.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ class TransportImpl final : private TransportDelegate, public ICanTransport
337337
static_cast<CanardMicrosecond>(deadline_us.count()),
338338
&metadata,
339339
{payload.size(), payload.data()}, // NOSONAR cpp:S5356
340-
static_cast<CanardMicrosecond>(now_us.count()));
340+
static_cast<CanardMicrosecond>(now_us.count()),
341+
&tx_frames_expired_);
341342

342343
cetl::optional<AnyFailure> failure =
343344
tryHandleTransientCanardResult<TransientErrorReport::CanardTxPush>(media, result);
@@ -691,7 +692,9 @@ class TransportImpl final : private TransportDelegate, public ICanTransport
691692
auto* const frame_handler_ptr =
692693
static_cast<decltype(frame_handler)*>(user_reference); // NOSONAR cpp:S5356, cpp:S5357
693694
return (*frame_handler_ptr)(deadline, *frame);
694-
});
695+
},
696+
&tx_frames_expired_,
697+
&tx_frames_failed_);
695698
}
696699

697700
if ((result == 0) && (media.canard_tx_queue().size == 0))
@@ -781,6 +784,8 @@ class TransportImpl final : private TransportDelegate, public ICanTransport
781784
TransientErrorHandler transient_error_handler_;
782785
Callback::Any configure_filters_callback_;
783786
SessionTree<RxSessionTreeNode::Response> svc_response_rx_session_nodes_;
787+
std::uint64_t tx_frames_expired_ = 0;
788+
std::uint64_t tx_frames_failed_ = 0;
784789

785790
}; // TransportImpl
786791

0 commit comments

Comments
 (0)