Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create initial design proposal #1

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
9 changes: 9 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
BasedOnStyle: Google
---
Language: Cpp
ColumnLimit: 120
IncludeBlocks: Regroup
---
Language: Proto
IndentWidth: 4
15 changes: 15 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
Checks: >
-*,
bugprone-*,
cert-*,
concurrency-*,
cppcoreguidelines-*,
google-*,
hicpp-*,
misc-*,
modernize-*,
performance-*,
portability-*,
readability-*
FormatStyle: file
41 changes: 41 additions & 0 deletions .cmake-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
parse:
additional_commands:
protobuf_generate_cpp:
kwargs:
PROTOS: "*"
IMPORT_DIRS: "*"
LANGUAGE: "*"
PLUGIN: "*"
GENERATE_EXTENSIONS: "*"
configure_package_config_file:
flags:
- NO_SET_AND_CHECK_MACRO
- NO_CHECK_REQUIRED_COMPONENTS_MACRO
kwargs:
INSTALL_DESTINATION: "*"
PATH_VARS: "*"
INSTALL_PREFIX: "*"
find_dependency:
flags:
- CONFIG
- QUIET
- REQUIRED
kwargs:
COMPONENTS: "*"
gtest_discover_tests:
flags:
- NO_PRETTY_TYPES
- NO_PRETTY_VALUES
kwargs:
EXTRA_ARGS: "*"
WORKING_DIRECTORY: "*"
TEST_PREFIX: "*"
TEST_SUFFIX: "*"
PROPERTIES: "*"
TEST_LIST: "*"
DISCOVERY_TIMEOUT: "*"
format:
line_width: 120
markup:
first_comment_is_literal: true
33 changes: 33 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM mcr.microsoft.com/devcontainers/cpp:0-ubuntu-22.04

ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="3.25.2"
ARG INSTALL_PROTOLINT_VERSION_FROM_SOURCE="0.42.2"

COPY ./reinstall-cmake.sh ./install-protolint.sh /tmp/

RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \
fi \
&& rm -f /tmp/reinstall-cmake.sh

RUN if [ "${INSTALL_PROTOLINT_VERSION_FROM_SOURCE}" != "none" ]; then \
chmod +x /tmp/install-protolint.sh && /tmp/install-protolint.sh ${INSTALL_PROTOLINT_VERSION_FROM_SOURCE}; \
fi \
&& rm -f /tmp/install-protolint.sh

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends \
clang-format-15 \
clang-tidy-15 \
doxygen \
gcc-12 \
graphviz \
libgmock-dev \
libgrpc++-dev \
libgtest-dev \
libprotobuf-dev \
protobuf-compiler \
protobuf-compiler-grpc \
python3-pip

RUN pip install --no-cache-dir cmakelang
51 changes: 51 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "C++",
"build": {
"dockerfile": "Dockerfile",
"args": {
// NOTE temp workaround for docker v23, see https://github.com/microsoft/vscode-remote-release/issues/7958
"BUILDKIT_INLINE_CACHE": "0"
}
},
"capAdd": [
"SYS_PTRACE"
],
"securityOpt": [
"seccomp=unconfined"
],
"customizations": {
"vscode": {
"extensions": [
"cheshirekow.cmake-format",
"ms-vscode.cmake-tools",
"ms-vscode.cpptools",
"ms-vscode.live-server",
"plex.vscode-protolint",
"redhat.vscode-yaml",
"zxh404.vscode-proto3"
],
"settings": {
"C_Cpp.clang_format_path": "/usr/bin/clang-format-15",
"C_Cpp.codeAnalysis.clangTidy.enabled": true,
"C_Cpp.codeAnalysis.clangTidy.path": "/usr/bin/clang-tidy-15",
"C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json",
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"cmake.exportCompileCommandsFile": true,
"cmake.generator": "Ninja",
"cmake.installPrefix": "${workspaceFolder}/build/prefix",
"editor.formatOnSave": true,
"editor.tabSize": 2,
"files.associations": {
".clang-format": "yaml",
".clang-tidy": "yaml",
".clangd": "yaml",
".cmake-format": "yaml",
"*.cmake.in": "cmake"
},
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true
}
}
}
}
41 changes: 41 additions & 0 deletions .devcontainer/install-protolint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
#-------------------------------------------------------------------------------
# Copyright (c) 2023, MBition GmbH
#
# This program and the accompanying materials are made
# available under the terms of the Mozilla Public License Version 2.0
# which is available at https://www.mozilla.org/en-US/MPL/2.0/
#
# SPDX-License-Identifier: MPL-2.0
#-------------------------------------------------------------------------------

set -e

PROTOLINT_VERSION=${1:-"none"}

if [ "${PROTOLINT_VERSION}" = "none" ]; then
echo "No protolint version specified, skipping protolint installation"
exit 0
fi

echo "Installing protolint..."
mkdir -p /opt/protolint/bin

architecture=$(dpkg --print-architecture)
case "${architecture}" in
arm64)
ARCH=arm64 ;;
amd64)
ARCH=x86_64 ;;
*)
echo "Unsupported architecture ${architecture}."
exit 1
;;
esac

PROTOLINT_BINARY_NAME="protolint_${PROTOLINT_VERSION}_Linux_${ARCH}.tar.gz"

curl -sSL "https://github.com/yoheimuta/protolint/releases/download/v${PROTOLINT_VERSION}/${PROTOLINT_BINARY_NAME}" | \
tar xvz -C /opt/protolint/bin

ln -s /opt/protolint/bin/protolint /usr/local/bin/protolint
60 changes: 60 additions & 0 deletions .devcontainer/reinstall-cmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
#
set -e

CMAKE_VERSION=${1:-"none"}

if [ "${CMAKE_VERSION}" = "none" ]; then
echo "No CMake version specified, skipping CMake reinstallation"
exit 0
fi

# Cleanup temporary directory and associated files when exiting the script.
cleanup() {
EXIT_CODE=$?
set +e
if [[ -n "${TMP_DIR}" ]]; then
echo "Executing cleanup of tmp files"
rm -Rf "${TMP_DIR}"
fi
exit $EXIT_CODE
}
trap cleanup EXIT


echo "Installing CMake..."
apt-get -y purge --auto-remove cmake
mkdir -p /opt/cmake

architecture=$(dpkg --print-architecture)
case "${architecture}" in
arm64)
ARCH=aarch64 ;;
amd64)
ARCH=x86_64 ;;
*)
echo "Unsupported architecture ${architecture}."
exit 1
;;
esac

CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh"
CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt"
TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX)

echo "${TMP_DIR}"
cd "${TMP_DIR}"

curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O
curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O

sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}"
sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license

for EXE in ccmake cmake cpack ctest; do
ln -sf /opt/cmake/bin/$EXE /usr/local/bin/$EXE
done
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode/
build/
compile_commands.json
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "open-simulation-interface"]
path = open-simulation-interface
url = https://github.com/mercedes-benz/open-simulation-interface.git
13 changes: 13 additions & 0 deletions .protolint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
lint:
rules:
remove:
- REPEATED_FIELD_NAMES_PLURALIZED
rules_option:
enum_field_names_zero_value_end_with:
suffix: UNKNOWN
indent:
style: 4
max_line_length:
max_chars: 120
tab_chars: 4
112 changes: 112 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#-------------------------------------------------------------------------------
# Copyright (c) 2023, MBition GmbH
#
# This program and the accompanying materials are made
# available under the terms of the Mozilla Public License Version 2.0
# which is available at https://www.mozilla.org/en-US/MPL/2.0/
#
# SPDX-License-Identifier: MPL-2.0
#-------------------------------------------------------------------------------

cmake_minimum_required(VERSION 3.24.0)

project(
OsiGrpcPackaging
VERSION 0.1.0
LANGUAGES CXX)

# Build options
option(OsiGrpcPackaging_BUILD_DOCS "Build docs" ${PROJECT_IS_TOP_LEVEL})
option(OsiGrpcPackaging_BUILD_TESTING "Build tests" ${PROJECT_IS_TOP_LEVEL})
option(OsiGrpcPackaging_ENABLE_WARNINGS "Enable compiler warnings" ${PROJECT_IS_TOP_LEVEL})
option(OsiGrpcPackaging_ENABLE_WERROR "Fail and stop if a compiler warning is triggered" ${PROJECT_IS_TOP_LEVEL})
option(OsiGrpcPackaging_gRPC_UNSECURE "" OFF)
option(OsiGrpcPackaging_INSTALL "Install the project" ${PROJECT_IS_TOP_LEVEL})

# Find dependencies
find_package(Protobuf REQUIRED VERSION 3)
find_package(PkgConfig REQUIRED)
if(OsiGrpcPackaging_gRPC_UNSECURE)
pkg_check_modules(grpc++ REQUIRED IMPORTED_TARGET grpc++_unsecure)
else()
pkg_check_modules(grpc++ REQUIRED IMPORTED_TARGET grpc++)
endif()
find_program(gRPC_CPP_PLUGIN grpc_cpp_plugin REQUIRED)

add_subdirectory(open-simulation-interface)

# Generate Protobuf sources
set(PROTOS osi_grpc_application_control.proto osi_grpc_symmetric_delta.proto)

protobuf_generate_cpp(
PROTO_SRCS PROTO_HEADERS
PROTOS ${PROTOS} osi_application_control.proto
IMPORT_DIRS ${PROJECT_SOURCE_DIR}/open-simulation-interface ${PROJECT_BINARY_DIR}/open-simulation-interface)

# Generate gRPC sources
protobuf_generate_cpp(
gRPC_SRCS gRPC_HEADERS
PROTOS ${PROTOS}
IMPORT_DIRS ${PROJECT_SOURCE_DIR}/open-simulation-interface ${PROJECT_BINARY_DIR}/open-simulation-interface
LANGUAGE grpc
PLUGIN protoc-gen-grpc=${gRPC_CPP_PLUGIN}
GENERATE_EXTENSIONS ".grpc.pb.cc" ".grpc.pb.h")

add_library(OsiGrpcPackaging)
add_library(OsiGrpcPackaging::OsiGrpcPackaging ALIAS OsiGrpcPackaging)

target_sources(
OsiGrpcPackaging
PUBLIC FILE_SET
HEADERS
BASE_DIRS
${PROJECT_BINARY_DIR}
FILES
${PROTO_HEADERS}
${gRPC_HEADERS}
PRIVATE ${PROTO_SRCS} ${gRPC_SRCS})

# target_include_directories(OsiGrpcPackaging PUBLIC $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>)

target_link_libraries(OsiGrpcPackaging PUBLIC protobuf::libprotobuf PkgConfig::grpc++
open_simulation_interface::open_simulation_interface_obj)

if(OsiGrpcPackaging_INSTALL)
set(OsiGrpcPackaging_CONFIG_INSTALL_DIR
share/OsiGrpcPackaging/cmake
CACHE PATH "Install path for package configs")
include(CMakePackageConfigHelpers)
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/OsiGrpcPackagingConfig.cmake.in ${PROJECT_BINARY_DIR}/OsiGrpcPackagingConfig.cmake
INSTALL_DESTINATION ${OsiGrpcPackaging_CONFIG_INSTALL_DIR}
NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO)

write_basic_package_version_file(
${PROJECT_BINARY_DIR}/OsiGrpcPackagingConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)

install(FILES ${PROJECT_BINARY_DIR}/OsiGrpcPackagingConfig.cmake
${PROJECT_BINARY_DIR}/OsiGrpcPackagingConfigVersion.cmake
DESTINATION ${OsiGrpcPackaging_CONFIG_INSTALL_DIR})

install(
TARGETS OsiGrpcPackaging open_simulation_interface_obj
EXPORT OsiGrpcPackagingTargets
FILE_SET HEADERS)

install(
EXPORT OsiGrpcPackagingTargets
DESTINATION ${OsiGrpcPackaging_CONFIG_INSTALL_DIR}
NAMESPACE OsiGrpcPackaging::)

export(
EXPORT OsiGrpcPackagingTargets
NAMESPACE OsiGrpcPackaging::
FILE ${PROJECT_BINARY_DIR}/OsiGrpcPackagingTargets.cmake)
endif()

if(OsiGrpcPackaging_BUILD_TESTING)
enable_testing()
add_subdirectory(test)
endif()
Loading