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
165 changes: 82 additions & 83 deletions .github/workflows/c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- .github/workflows/c.yaml
jobs:
coverage:
name: Test
name: Code Coverage
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
Expand All @@ -38,8 +38,19 @@ jobs:
bash <(curl -s https://codecov.io/bash) -s c/build || echo "Codecov did not collect coverage reports";


gcc6-release:
name: GCC6 - Release
ubuntu-lts:
Copy link
Contributor Author

@RReichert RReichert Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've applied the DRY principle here and removed the gcc6-release and clang6-* jobs and replaced them with "strategy matrix". This matrix will create 7 jobs (would have been 8 but I've excluded 1 since its already being build by the Code Coverage jobs above). I've also applied the same idea with Mingw and VS 2019.

I also made sure that the updated build now follow the Configure/Build/Test/Install workflow.

Also as part of this change, I've also fixed up the fact that gcc6-release job wasn't actually building for GCC 6, it was actually using the system version which was GCC 7.

strategy:
matrix:
build_type: [ "Debug", "Release" ]
compiler: [
{ c: "gcc-6", cxx: "g++-6", package: "gcc-6 g++-6" },
{ c: "clang-6.0", cxx: "clang++-6.0", package: "clang-6.0" }
]
build_shared_libraries: [ true, false ]
exclude: [
{ build_type: "Debug", compiler: { c: "gcc-6", cxx: "g++-6" }, build_shared_libraries: false }
]
name: "Ubuntu 18.04 (Build: ${{ matrix.build_type }}, Compilers: ${{ matrix.compiler.c }}/${{ matrix.compiler.cxx }}, Shared Library: ${{ matrix.build_shared_libraries }})"
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
Expand All @@ -50,81 +61,68 @@ jobs:
- name: Setup
run: |
sudo apt-get -qq update
sudo apt-get -qq install libeigen3-dev libserialport-dev
sudo apt-get -qq install libeigen3-dev libserialport-dev ${{ matrix.compiler.package }}

- name: Run tests
run: make test-c
env:
CMAKEFLAGS: -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=true

- name: Build examples
run: make -C c/build examples
- name: Configure
run: |
cmake -S c -B build \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_C_COMPILER=${{ matrix.compiler.c }} \
-DCMAKE_CXX_COMPILER=${{ matrix.compiler.cxx }} \
-DBUILD_SHARED_LIBS=${{ matrix.build_shared_libraries }} \
-DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/install" \
-DINSTALL_GTEST=false \
-DBUILD_EXAMPLES=true

- name: Build
run: cmake --build build

clang6-debug:
name: Clang6 - Debug
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
fetch-depth: 0
- name: Example
run: cmake --build build --target examples

- name: Setup
run: |
sudo apt-get -qq update
sudo apt-get -qq install clang-6.0 libeigen3-dev libserialport-dev
- name: Test
run: cmake --build build --target do-all-tests

- name: Run tests
run: make test-c
env:
CMAKEFLAGS: -DCMAKE_BUILD_TYPE=Debug -DBUILD_EXAMPLES=true
CC: clang-6.0
CXX: clang++-6.0
- name: Install
run: cmake --build build --target install

- name: Build examples
run: make -C c/build examples
- name: Test Package
run: |
cmake -S c/test_package -B c/test_package/build -DCMAKE_PREFIX_PATH="${{ github.workspace }}/install"
cmake --build c/test_package/build


clang6-release:
name: Clang6 - Release
runs-on: ubuntu-18.04
macos:
name: macOS Catalina
runs-on: macos-10.15
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
fetch-depth: 0

- name: Setup
- name: Configure
run: |
sudo apt-get -qq update
sudo apt-get -qq install clang-6.0 libeigen3-dev libserialport-dev

- name: Run tests
run: make test-c
env:
CMAKEFLAGS: -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=true
CC: clang-6.0
CXX: clang++-6.0
cmake -S c -B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/install" \
-DINSTALL_GTEST=false

- name: Build examples
run: make -C c/build examples
- name: Build
run: cmake --build build

- name: Test
run: cmake --build build --target do-all-tests

macos:
name: macos
runs-on: macos-10.15
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
fetch-depth: 0
- name: Install
run: cmake --build build --target install

- name: Run tests
run: make test-c
env:
CC: clang
CXX: clang++
- name: Test Package
run: |
cmake -S c/test_package -B c/test_package/build -DCMAKE_PREFIX_PATH="${{ github.workspace }}/install"
cmake --build c/test_package/build


big-endian:
Expand All @@ -150,42 +148,43 @@ jobs:
CMAKEFLAGS: -DCMAKE_EXE_LINKER_FLAGS_RELEASE="-static" -Dgtest_disable_pthreads=ON


windows-minGW:
name: Windows MinGW
windows-2019:
strategy:
matrix:
generator: [ "MinGW Makefiles", "Visual Studio 16 2019" ]
build_shared_libraries: [ true, false ]
name: "Windows 2019 (Generator: ${{ matrix.generator }}, Shared Library: ${{ matrix.build_shared_libraries }})"
runs-on: windows-2019
steps:

- uses: actions/checkout@v2
with:
submodules: recursive
fetch-depth: 0

- name: Configure
run: cmake -G "MinGW Makefiles" -S c -B build
run: |
cmake -G "${{ matrix.generator }}" -S c -B build `
-DCMAKE_BUILD_TYPE=Release `
-DBUILD_SHARED_LIBS=${{ matrix.build_shared_libraries }} `
-DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/install" `
-Dgtest_force_shared_crt=true `
-DINSTALL_GTEST=false

- name: Build
run: cmake --build build --target all

- name: Test
run: cmake --build build --target do-all-tests
run: cmake --build build

- name: Build Test
run: cmake --build build --target build-all-tests

windows-vs-2019:
name: Windows VS 2019
runs-on: windows-2019
steps:

- uses: actions/checkout@v2
with:
submodules: recursive
fetch-depth: 0

- name: Configure
run: cmake -G "Visual Studio 16 2019" -S c -B build -D gtest_force_shared_crt=true
- name: Run Test
run: cmake --build build --target do-all-tests
if: ${{ !matrix.build_shared_libraries }}

- name: Build
run: cmake --build build --target ALL_BUILD
- name: Install
run: cmake --build build --target install

- name: Test
run: cmake --build build --target do-all-tests
- name: Test Package
run: |
cmake -G "${{ matrix.generator }}" -S c/test_package -B c/test_package/build -DCMAKE_PREFIX_PATH="${{ github.workspace }}/install"
cmake --build c/test_package/build

2 changes: 1 addition & 1 deletion c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.12)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to up this number because here you can see that this feature only worked for C++ until until 3.12 when C was also introduce.

project(libsbp C CXX)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake" "${CMAKE_CURRENT_LIST_DIR}/cmake/common")
Expand Down
10 changes: 10 additions & 0 deletions c/include/libsbp/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ typedef struct sbp_msg_callbacks_node sbp_msg_callbacks_node_t;
#define SBP_DEPRECATED __attribute__((deprecated))
#define SBP_ATTR_FORMAT(fmt,args) __attribute__((format(printf,fmt,args)))
#define SBP_ATTR_VFORMAT(fmt) __attribute__((format(printf,fmt,0)))
#define SBP_EXPORT __attribute__((visibility("default")))

#elif defined(_MSC_VER)

Expand All @@ -120,6 +121,14 @@ typedef struct sbp_msg_callbacks_node sbp_msg_callbacks_node_t;
#define SBP_ATTR_FORMAT(fmt,args)
#define SBP_ATTR_VFORMAT(fmt)

#if !defined(_WINDLL)
#define SBP_EXPORT
#elif defined(sbp_EXPORTS)
#define SBP_EXPORT __declspec(dllexport)
#else
#define SBP_EXPORT __declspec(dllimport)
#endif

#elif defined(__ghs__)

#define SBP_PACK_START /* Intentionally empty */
Expand All @@ -129,6 +138,7 @@ typedef struct sbp_msg_callbacks_node sbp_msg_callbacks_node_t;
#define SBP_DEPRECATED /* Intentionally empty */
#define SBP_ATTR_FORMAT(fmt,args)
#define SBP_ATTR_VFORMAT(fmt)
#define SBP_EXPORT /* Intentionally empty */

#else

Expand Down
7 changes: 4 additions & 3 deletions c/include/libsbp/cpp/message_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
#ifndef SBP_CPP_MESSAGE_HANDLER_H_
#define SBP_CPP_MESSAGE_HANDLER_H_

#include <cassert>
#include <array>
#include <cassert>
#include <cstddef>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added this in since down below we used size_t which isn't guaranteed to be imported by any of the above header files (based on the documentations)


#include <libsbp/cpp/state.h>
#include <libsbp/cpp/message_traits.h>
#include <libsbp/cpp/state.h>

namespace sbp {

Expand Down Expand Up @@ -145,7 +146,7 @@ class CallbackInterface<MsgType> {
* @tparam MsgTypes List of SBP message types to register callbacks for
*/
template<typename... MsgTypes>
class MessageHandler : public details::CallbackInterface<MsgTypes...> {
class MessageHandler : public details::CallbackInterface<MsgTypes...> {
static constexpr size_t kMsgCount = sizeof...(MsgTypes);

State &state_;
Expand Down
2 changes: 1 addition & 1 deletion c/include/libsbp/edc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
extern "C" {
#endif

u16 crc16_ccitt(const u8 *buf, u32 len, u16 crc);
SBP_EXPORT u16 crc16_ccitt(const u8 *buf, u32 len, u16 crc);

#ifdef __cplusplus
}
Expand Down
12 changes: 6 additions & 6 deletions c/include/libsbp/legacy/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ typedef void (*sbp_frame_callback_t)(u16 sender_id, u16 msg_type,
* `SBP_CALLBACK_ERROR` if the callback was already
* registered for that message type.
*/
s8 sbp_payload_callback_register(sbp_state_t* s, u16 msg_type, sbp_msg_callback_t cb, void* context,
SBP_EXPORT s8 sbp_payload_callback_register(sbp_state_t* s, u16 msg_type, sbp_msg_callback_t cb, void* context,
sbp_msg_callbacks_node_t *node);

/** Register a frame callback for a msg_type.
Expand All @@ -56,7 +56,7 @@ s8 sbp_payload_callback_register(sbp_state_t* s, u16 msg_type, sbp_msg_callback_
* `SBP_CALLBACK_ERROR` if the if callback was already
* registered for that message type.
*/
s8 sbp_frame_callback_register(sbp_state_t* s, u16 msg_type,
SBP_EXPORT s8 sbp_frame_callback_register(sbp_state_t* s, u16 msg_type,
sbp_frame_callback_t cb, void* context,
sbp_msg_callbacks_node_t *node);

Expand All @@ -69,7 +69,7 @@ s8 sbp_frame_callback_register(sbp_state_t* s, u16 msg_type,
* \return `SBP_OK` (0) if successful, `SBP_NULL_ERROR` if a usage error,
* `SBP_CALLBACK_ERROR` if the node already exists
*/
s8 sbp_all_payload_callback_register(sbp_state_t *s, sbp_frame_callback_t cb,
SBP_EXPORT s8 sbp_all_payload_callback_register(sbp_state_t *s, sbp_frame_callback_t cb,
void *context, sbp_msg_callbacks_node_t *node);

/** Directly process an SBP frame.
Expand All @@ -92,7 +92,7 @@ s8 sbp_all_payload_callback_register(sbp_state_t *s, sbp_frame_callback_t cb,
* SBP_OK_CALLBACK_UNDEFINED` (2) if message decoded with no
* associated callback.
*/
s8 sbp_frame_process(sbp_state_t *s, u16 sender_id, u16 msg_type,
SBP_EXPORT s8 sbp_frame_process(sbp_state_t *s, u16 sender_id, u16 msg_type,
u8 payload_len, u8 payload[], u16 frame_len, u8 frame[], u8 cb_mask);

/** Directly process an SBP message.
Expand All @@ -108,7 +108,7 @@ s8 sbp_frame_process(sbp_state_t *s, u16 sender_id, u16 msg_type,
* `SBP_OK_CALLBACK_UNDEFINED` (2) if message decoded with no associated
* callback.
*/
s8 sbp_payload_process(sbp_state_t *s, u16 sender_id, u16 msg_type, u8 msg_len,
SBP_EXPORT s8 sbp_payload_process(sbp_state_t *s, u16 sender_id, u16 msg_type, u8 msg_len,
u8 payload[]);

/** Send SBP messages.
Expand Down Expand Up @@ -140,7 +140,7 @@ s8 sbp_payload_process(sbp_state_t *s, u16 sender_id, u16 msg_type, u8 msg_len,
* \return `SBP_OK` (0) if successful, `SBP_WRITE_ERROR` if the message could
* not be sent or was only partially sent.
*/
s8 sbp_payload_send(sbp_state_t *s, u16 msg_type, u16 sender_id, u8 len, u8 *payload,
SBP_EXPORT s8 sbp_payload_send(sbp_state_t *s, u16 msg_type, u16 sender_id, u8 len, u8 *payload,
sbp_write_fn_t write);

#ifdef __cplusplus
Expand Down
5 changes: 3 additions & 2 deletions c/include/libsbp/legacy/cpp/frame_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#ifndef SBP_LEGACY_CPP_FRAME_HANDLER_H
#define SBP_LEGACY_CPP_FRAME_HANDLER_H

#include <cassert>
#include <array>
#include <cassert>
#include <cstddef>

#include <libsbp/cpp/state.h>
#include <libsbp/legacy/cpp/message_traits.h>
Expand Down Expand Up @@ -193,4 +194,4 @@ class AllFrameHandler {

} /* namespace sbp */

#endif /* SBP_LEGACY_CPP_MESSAGE_HANDLER_H */
#endif /* SBP_LEGACY_CPP_FRAME_HANDLER_H */
2 changes: 1 addition & 1 deletion c/include/libsbp/legacy/cpp/payload_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class PayloadCallbackInterface<MsgType> {
* @tparam MsgTypes List of SBP message types to register callbacks for
*/
template<typename... MsgTypes>
class PayloadHandler : public details::PayloadCallbackInterface<MsgTypes...> {
class PayloadHandler : public details::PayloadCallbackInterface<MsgTypes...> {
static constexpr std::size_t kMsgCount = sizeof...(MsgTypes);

State &state_;
Expand Down
10 changes: 5 additions & 5 deletions c/include/libsbp/sbp.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ struct sbp_state {

/** \} */

s8 sbp_remove_callback(sbp_state_t *s, sbp_msg_callbacks_node_t *node);
void sbp_clear_callbacks(sbp_state_t* s);
void sbp_state_init(sbp_state_t *s);
void sbp_state_set_io_context(sbp_state_t *s, void* context);
s8 sbp_process(sbp_state_t *s, sbp_read_fn_t read);
SBP_EXPORT s8 sbp_remove_callback(sbp_state_t *s, sbp_msg_callbacks_node_t *node);
SBP_EXPORT void sbp_clear_callbacks(sbp_state_t* s);
SBP_EXPORT void sbp_state_init(sbp_state_t *s);
SBP_EXPORT void sbp_state_set_io_context(sbp_state_t *s, void* context);
SBP_EXPORT s8 sbp_process(sbp_state_t *s, sbp_read_fn_t read);

#ifdef __cplusplus
}
Expand Down
Loading