Skip to content

Commit

Permalink
Merge branch 'release-creation'
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxDevon committed Jan 29, 2024
2 parents 829cff4 + f7067ff commit 6d4160f
Show file tree
Hide file tree
Showing 22 changed files with 359 additions and 115 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ AllowShortLambdasOnASingleLine: Empty

# We do not want clang-format to put all arguments on a new line
AllowAllArgumentsOnNextLine: false

InsertNewlineAtEOF: true
19 changes: 19 additions & 0 deletions .github/data/release_body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Libdbc release

### Developer Notes

**TODO: Update this!**

## Breaking Changes

* <Insert-Change>

## Features

* <Insert-Change>

## Bugs

* <Insert-Change>


40 changes: 26 additions & 14 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Libdbc Pipeline

on: [push]
on: [push, workflow_call]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand Down Expand Up @@ -42,27 +42,28 @@ jobs:
sudo locale-gen de_DE.UTF-8
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
- name: Configure build
working-directory: ${{runner.workspace}}
env:
CC: ${{matrix.cc}}
CXX: ${{matrix.cxx}}
run: |
cmake -Bbuild -H$GITHUB_WORKSPACE \
cmake -Bbuild -H$GITHUB_WORKSPACE \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
-DCMAKE_CXX_EXTENSIONS=ON \
-DDBC_TEST_LOCALE_INDEPENDENCE=ON
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
-DCMAKE_CXX_EXTENSIONS=ON \
-DDBC_TEST_LOCALE_INDEPENDENCE=ON \
-DDBC_GENERATE_SINGLE_HEADER=ON
- name: Build tests + lib
working-directory: ${{runner.workspace}}
run: cmake --build build --parallel `nproc`

- name: Run tests
env:
CTEST_OUTPUT_ON_FAILURE: 1
working-directory: ${{runner.workspace}}
run: ctest --output-on-failure --test-dir build -j `nproc`

windows-build:
Expand Down Expand Up @@ -129,11 +130,11 @@ jobs:
CC: ${{matrix.cc}}
CXX: ${{matrix.cxx}}
run: |
cmake -Bbuild -H$GITHUB_WORKSPACE \
cmake -Bbuild -H$GITHUB_WORKSPACE \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
-DCMAKE_CXX_EXTENSIONS=ON \
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
-DCMAKE_CXX_EXTENSIONS=ON \
-DDBC_TEST_LOCALE_INDEPENDENCE=ON
- name: Build tests + lib
Expand All @@ -150,7 +151,18 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install clang-format version
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 16
sudo apt update && sudo apt install -y clang-format-16
sudo ln -sf $(which clang-format-16) $(which clang-format)
test "$(clang-format --version)" == "$(clang-format-16 --version)"
- name: Test format with clang format
run: ./scripts/fmt.sh
Expand Down
73 changes: 66 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,82 @@ on:
inputs:
major:
required: true
type: string
description: "The major version"
type: number
minor:
required: true
type: string
description: "The minor version"
type: number
patch:
required: true
type: string
description: "The patch version"
type: number

release_type:
type: choice
description: "The type of release you are making. Controls branch naming / creation"
options:
- patch
- minor
- major

jobs:
check_version:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: "Validate version in cmake before continuing"
run: ./scripts/check_version.py --version "v${{ inputs.major }}.${{ inputs.minor }}.${{ inputs.patch }}"

pipeline:
needs: [check_version]
uses: ./.github/workflows/pipeline.yml

create_release:
runs-on: ubuntu-latest
needs: [pipeline]

env:
header_file_path: build/single_header/libdbc/libdbc.hpp

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

- name: "Setup Cargo"
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
- name: Configure build
run: cmake -Bbuild -H$GITHUB_WORKSPACE -DDBC_GENERATE_SINGLE_HEADER=ON

- name: Generate the header file
run: cmake --build build --parallel `nproc` --target single_header

- uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: header-only
path: ${{ env.header_file_path }}

- name: "Create a branch if we are making a major / minor release"
uses: peterjgrainger/[email protected]
if: ${{ inputs.release_type }} == "minor" || ${{ inputs.release_type }} == "major"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
branch: 'release/v${{ inputs.major }}.${{ inputs.minor }}'
sha: '${{ github.sha }}'

- name: "Run tests as a pre check"
uses: .github/workflows/tests.yml
- uses: ncipollo/release-action@v1
with:
artifacts: "${{ env.header_file_path }}"
draft: true
bodyFile: ".github/data/release_body.md"
tag: v${{ inputs.major }}.${{ inputs.minor }}.${{ inputs.patch }}
commit: release/v${{ inputs.major }}.${{ inputs.minor }}



Expand Down
72 changes: 35 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
cmake_minimum_required(VERSION 3.16)

project(dbc
VERSION 0.2.0
DESCRIPTION "C++ DBC Parser"
)
# Keep this on one line for release checking
project(dbc VERSION 0.2.0 DESCRIPTION "C++ DBC Parser")

# -- PROJECT OPTIONS -- #
option(DBC_ENABLE_TESTS "Enable Unittests" ON)
option(DBC_TEST_LOCALE_INDEPENDENCE "Used to deterime if the libary is locale agnostic when it comes to converting floats. You need `de_DE.UTF-8` locale installed for this testing." OFF)
option(DBC_GENERATE_DOCS "Use doxygen if installed to generated documentation files" OFF)
option(DBC_GENERATE_SINGLE_HEADER "This will run the generator for the single header file version. Default is OFF since we make a static build. Requires cargo installed." OFF)
# ---------------------- #

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand All @@ -27,20 +26,18 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)

find_package(FastFloat QUIET)
if (NOT ${FastFloat_FOUND})
include(FetchContent)
FetchContent_Declare(
FastFloat
GIT_REPOSITORY https://github.com/fastfloat/fast_float.git
GIT_TAG 1ea4f27b2aeee2859a1354a3c24cff52a116cad1
)
# FetchContent_MakeAvailable(FastFloat)
FetchContent_Populate(FastFloat)
add_subdirectory(${fastfloat_SOURCE_DIR} ${fastfloat_BINARY_DIR} EXCLUDE_FROM_ALL)
include(FetchContent)
FetchContent_Declare(
FastFloat
GIT_REPOSITORY https://github.com/fastfloat/fast_float.git
GIT_TAG 1ea4f27b2aeee2859a1354a3c24cff52a116cad1
)
FetchContent_MakeAvailable(FastFloat)
endif()

# add where to find the source files
list(APPEND SOURCE_FILES
${PROJECT_SOURCE_DIR}/src/utils.cpp
${PROJECT_SOURCE_DIR}/src/utils.cpp
${PROJECT_SOURCE_DIR}/src/message.cpp
${PROJECT_SOURCE_DIR}/src/signal.cpp
${PROJECT_SOURCE_DIR}/src/dbc.cpp
Expand All @@ -55,50 +52,51 @@ list(APPEND HEADER_FILES
)

if(DBC_ENABLE_TESTS)
include(CTest)
add_subdirectory(test)
include(CTest)
add_subdirectory(test)
endif()

if(DBC_GENERATE_DOCS)
add_subdirectory(doc)
add_subdirectory(doc)
endif()

list(APPEND GCC_CLANG_COMPILE_FLAGS
-Wall -Wextra -Wpedantic
-Wconversion -Wint-in-bool-context
-Wmissing-declarations -Wmissing-field-initializers
-Werror
-Wall -Wextra -Wpedantic
-Wconversion -Wint-in-bool-context
-Wmissing-declarations -Wmissing-field-initializers
-Werror
)


if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(/W4 /WX)
add_compile_options(/W4 /WX)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Clang shadow warnings aren't as sensitive as gcc
add_compile_options(${GCC_CLANG_COMPILE_FLAGS} -Wshadow)
# Clang shadow warnings aren't as sensitive as gcc
add_compile_options(${GCC_CLANG_COMPILE_FLAGS} -Wshadow)
else()
add_compile_options(${GCC_CLANG_COMPILE_FLAGS})
add_compile_options(${GCC_CLANG_COMPILE_FLAGS})
endif()

add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} FastFloat::fast_float)
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)

target_sources(${PROJECT_NAME} INTERFACE FILE_SET HEADERS
TYPE HEADERS
BASE_DIRS ${PROJECT_SOURCE_DIR}/include/libdbc
FILES ${HEADER_FILES}
TYPE HEADERS
BASE_DIRS ${PROJECT_SOURCE_DIR}/include/libdbc
FILES ${HEADER_FILES}
)

add_custom_target(release
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_SOURCE_DIR}/scripts/create_single_header.sh
DEPENDS ${PROJECT_NAME}
)
if(DBC_GENERATE_SINGLE_HEADER)
add_custom_target(single_header ALL
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_SOURCE_DIR}/scripts/create_single_header.sh
)
endif()

## Installation
# install lib
Expand All @@ -111,5 +109,5 @@ install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/libdbc DESTINATION ${CMAKE_INSTA
# Generate pkg-config file
configure_file(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ cmake -LH .. | grep -B1 "DBC_"
cmake -LAH ..
```

### Creating a Single Header File

It requires you have `cargo` installed from rust. See these instructions if you don't have that https://www.rust-lang.org/tools/install.
It uses the https://github.com/Felerius/cpp-amalgamate crate to do the single header file creation.

The output will be generated in the `build/single_header/libdbc/` folder. You can run a cmake command to build this as well as other targets.

To just build the single header you can simply run the target:
```shell
cmake -Bbuild -H. -DDBC_GENERATE_SINGLE_HEADER=ON

cmake --build build --parallel `nproc` --target single_header
```


## Testing

I am trying to always make sure that this is very well tested code. I am using Catch2 to do this
Expand Down
1 change: 0 additions & 1 deletion include/libdbc/dbc.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#ifndef __DBC_HPP__
#define __DBC_HPP__

Expand Down
2 changes: 1 addition & 1 deletion include/libdbc/exceptions/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ class validity_error : public exception {

} // libdbc

#endif // __ERROR_HPP__
#endif // __ERROR_HPP__
1 change: 0 additions & 1 deletion script-requirements.txt

This file was deleted.

Loading

0 comments on commit 6d4160f

Please sign in to comment.