diff --git a/.github/workflows/build_compile.yml b/.github/workflows/build_compile.yml new file mode 100644 index 0000000..af3b791 --- /dev/null +++ b/.github/workflows/build_compile.yml @@ -0,0 +1,162 @@ +name: Build and test with docker + +on: + push: + tags: + - '*' + +jobs: + version: + outputs: + version: ${{ steps.get_version.outputs.version }} + buildname: ${{ steps.get_version.outputs.buildname }} + runs-on: "ubuntu-latest" + steps: + - + name: Checkout repository + uses: actions/checkout@v1 + - + name: Get the version + id: get_version + run: | + if [ -z "$version" ] + then + version=$(date '+%Y%m%d') + echo ::set-output name=version::"${version}" + else + echo ::set-output name=version::"${version}" + fi + builddate=$(date '+%Y-%m-%d') + buildhash=$(git rev-parse --short "$GITHUB_SHA") + buildname="${builddate}-${buildhash}" + echo ::set-output name=version::${VERSION} + echo ::set-output name=buildhash::${buildhash} + echo ::set-output name=builddate::${builddate} + echo ::set-output name=buildname::${buildname} + env: + version: ${{ github.event.inputs.version }} + compile: + runs-on: ${{ matrix.host }} + needs: [ version ] + strategy: + fail-fast: false + max-parallel: 3 + matrix: + host: [ + "ubuntu-latest", + #"macos-10.15", + ] + config: + - { + name: "armhf Release", + arch: "armhf" + } + - { + name: "amd64 Release", + arch: "amd64" + } + + name: 'Build and Upload release: ${{ matrix.config.name }}' + steps: + - uses: actions/checkout@v2 + - + name: Build the Docker image + run: docker build -t aasdk_builder --file buildenv/Dockerfile . + - + name: 'Build ${{ matrix.config.arch }} Debian package' + run: docker run -v "${PWD}/release":/release aasdk_builder:latest ${{ matrix.config.arch }} + - + name: Get Name of Artifact + id: get-artifact-name + run: | + ls -hla + ARTIFACT_PATHNAME=$(ls ./release/*.deb | head -n 1) + ARTIFACT_NAME=$(basename $ARTIFACT_PATHNAME) + echo ::set-output name=artifact_filename::${ARTIFACT_NAME} + echo ::set-output name=artifact_path::${ARTIFACT_PATHNAME} + - + name: Upload build artifacts + id: upload_deploy + uses: actions/upload-artifact@v2 + with: + name: ${{ matrix.config.arch }} + path: | + ${{ steps.get-artifact-name.outputs.artifact_path }} +# Create Release + release: + runs-on: ubuntu-latest + needs: [ version, compile ] + if: startsWith(github.ref, 'refs/tags/') + name: 'Create release' + outputs: + release_upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps + steps: + - uses: actions/checkout@v2 + - + name: Build Changelog + id: github_release + uses: mikepenz/release-changelog-builder-action@v2.4.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - + name: Create GitHub release + id: create_release + uses: softprops/action-gh-release@v0.1.13 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{needs.version.outputs.version }} + release_name: ${{needs.version.outputs.buildname }} + body: ${{steps.github_release.outputs.changelog}} + draft: true + prerelease: true +# Upload release artifacts + upload: + needs: [ version, compile, release ] + runs-on: ${{ matrix.host }} + strategy: + fail-fast: false + max-parallel: 3 + matrix: + host: [ + "ubuntu-latest", + #"macos-10.15", + ] + config: + - { + name: "armhf Release", + arch: "armhf" + } + - { + name: "amd64 Release", + arch: "amd64" + } + + name: 'Upload release: ${{ matrix.config.name }}' + steps: + - + name: Download build artifacts + uses: actions/download-artifact@v2 + with: + name: ${{ steps.get_version.outputs.version }} + + - + name: Get Artifact Filenames + id: get-artifact-name + run: | + ARTIFACT_PATHNAME=$(ls ${{ matrix.config.arch }}/*.deb | head -n 1) + ARTIFACT_NAME=$(basename $ARTIFACT_PATHNAME) + echo ::set-output name=artifact_filename::${ARTIFACT_NAME} + echo ::set-output name=artifact_path::${ARTIFACT_PATHNAME} + - + name: Upload zip to release + id: upload_zip + uses: actions/upload-release-asset@v1.0.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_VERSION: ${{ needs.version.outputs.buildname }} + with: + upload_url: ${{needs.release.outputs.release_upload_url}} + asset_path: ${{ steps.get-artifact-name.outputs.artifact_path }} + asset_name: ${{ steps.get-artifact-name.outputs.artifact_filename }} + asset_content_type: application/vnd.debian.binary-package diff --git a/.gitignore b/.gitignore index bac2c3b..9e0cbbf 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ aasdk_proto/*.pb.h Makefile cmake_install.cmake install_manifest.txt +build/** \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..487bff5 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,57 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Clean", + "command": "sudo rm -R build", + "type": "shell", + "args": [], + "problemMatcher": [ + "$tsc" + ], + "presentation": { + "reveal": "always" + }, + "group": "build" + }, + { + "label": "Build", + "command": "mkdir build;cd build;cmake -DCMAKE_BUILD_TYPE=Release ../", + "type": "shell", + "args": [], + "problemMatcher": [ + "$tsc" + ], + "presentation": { + "reveal": "always" + }, + "group": "build" + }, + { + "label": "Create DEB Package", + "command": "cd build;cpack --config CPackConfig.cmake", + "type": "shell", + "args": [], + "problemMatcher": [ + "$tsc" + ], + "presentation": { + "reveal": "always" + }, + "group": "build" + }, + { + "label": "Create DEB SRC Package", + "command": "cd build;cpack --config CPackSourceConfig.cmake", + "type": "shell", + "args": [], + "problemMatcher": [ + "$tsc" + ], + "presentation": { + "reveal": "always" + }, + "group": "build" + } + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index f895c0d..3420358 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,30 @@ cmake_minimum_required(VERSION 3.5.1) -set (AASDK_VERSION_MAJOR 2) -set (AASDK_VERSION_MINOR 1) -set (AASDK_VERSION_PATCH 0) +if( TARGET_ARCH STREQUAL "amd64" ) + message("Building for amd64") +elseif( TARGET_ARCH STREQUAL "armhf" ) + message("Building for armhf") + set(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabihf-gcc-8) + set(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabihf-g++-8) + set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "armhf") +else() + message("Unknown target architecture. Exiting") + return() +endif() + +set (aasdk_VERSION_MAJOR 3) +set (aasdk_VERSION_MINOR 1) +set (aasdk_VERSION_PATCH 0) + +project(aasdk +VERSION ${aasdk_VERSION_MAJOR}.${aasdk_VERSION_MINOR}.${aasdk_VERSION_PATCH} +LANGUAGES CXX) find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") endif() -project(aasdk CXX) - set(base_directory ${CMAKE_CURRENT_SOURCE_DIR}) set(sources_directory ${base_directory}/src) @@ -35,6 +49,10 @@ set(Boost_USE_STATIC_RUNTIME OFF) add_definitions(-DBOOST_ALL_DYN_LINK) +include(${base_directory}/cmake_modules/gitversion.cmake) +set (aasdk_VERSION_PATCH ${_commit_timestamp}) +set (CMAKE_PROJECT_VERSION_PATCH ${aasdk_VERSION_PATCH}) + if(WIN32) set(WINSOCK2_LIBRARIES "ws2_32") endif(WIN32) @@ -81,12 +99,13 @@ target_link_libraries(aasdk ${OPENSSL_LIBRARIES} ${WINSOCK2_LIBRARIES}) -set(AASDK_VERSION_STRING ${AASDK_VERSION_MAJOR}.${AASDK_VERSION_MINOR}.${AASDK_VERSION_PATCH}) -set_target_properties(aasdk PROPERTIES VERSION ${AASDK_VERSION_STRING} - SOVERSION ${AASDK_VERSION_MAJOR}) +set(aasdk_VERSION_STRING ${aasdk_VERSION_MAJOR}.${aasdk_VERSION_MINOR}.${aasdk_VERSION_PATCH}) +message(INFO " Project Version: ${aasdk_VERSION_STRING}") +set_target_properties(aasdk PROPERTIES VERSION ${aasdk_VERSION_STRING} + SOVERSION ${aasdk_VERSION_MAJOR}) -install(TARGETS aasdk DESTINATION lib) -install(DIRECTORY include/aasdk DESTINATION include) +install(TARGETS aasdk DESTINATION lib COMPONENT libraries) +install(DIRECTORY include/aasdk DESTINATION include COMPONENT headers) if(AASDK_TEST) add_executable(aasdk_ut @@ -105,3 +124,27 @@ if(AASDK_TEST) setup_target_for_coverage(NAME aasdk_coverage EXECUTABLE aasdk_ut DEPENDENCIES aasdk_ut) endif(AASDK_CODE_COVERAGE) endif(AASDK_TEST) +SET(CPACK_GENERATOR "DEB") +SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "AASDK") #required +SET(CPACK_PACKAGE_VENDOR "AASDK") +set(CPACK_PACKAGE_VERSION ${aasdk_VERSION_STRING}) +set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) +set(CPACK_DEBIAN_PACKAGE_DEPENDS "libusb-1.0-0,libboost-all-dev,libssl-dev,libprotobuf-dev") +set(CPACK_COMPONENTS_ALL libraries headers Unspecified) +set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries") +set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers") +set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION + "Static libraries used to build programs with AASDK") +set(CPACK_COMPONENT_HEADERS_DESCRIPTION + "C/C++ header files for use with AASDK") +set(CPACK_COMPONENT_LIBRARIES_GROUP "Development") +set(CPACK_COMPONENT_HEADERS_GROUP "Development") +set(CPACK_COMPONENT_GROUP_DEVELOPMENT_EXPANDED ON) +set(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION + "All of the tools you'll ever need to develop software") +set(CPACK_COMPONENT_HEADERS_DEPENDS libraries) +set(CPACK_ALL_INSTALL_TYPES Full Developer) +set(CPACK_INSTALL_TYPE_FULL_DISPLAY_NAME "Everything") +set(CPACK_COMPONENT_LIBRARIES_INSTALL_TYPES Developer Full) +set(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full) +INCLUDE(CPack) diff --git a/aasdk_proto/CMakeLists.txt b/aasdk_proto/CMakeLists.txt index f050119..4c0d40f 100644 --- a/aasdk_proto/CMakeLists.txt +++ b/aasdk_proto/CMakeLists.txt @@ -7,9 +7,9 @@ protobuf_generate_cpp(proto_sources proto_headers ${proto_files}) add_library(aasdk_proto SHARED ${proto_headers} ${proto_sources}) target_link_libraries(aasdk_proto ${PROTOBUF_LIBRARIES}) -set(AASDK_VERSION_STRING ${AASDK_VERSION_MAJOR}.${AASDK_VERSION_MINOR}.${AASDK_VERSION_PATCH}) -set_target_properties(aasdk_proto PROPERTIES VERSION ${AASDK_VERSION_STRING} - SOVERSION ${AASDK_VERSION_MAJOR}) +set(aasdk_VERSION_STRING ${aasdk_VERSION_MAJOR}.${aasdk_VERSION_MINOR}.${aasdk_VERSION_PATCH}) +set_target_properties(aasdk_proto PROPERTIES VERSION ${aasdk_VERSION_STRING} + SOVERSION ${aasdk_VERSION_MAJOR}) install(TARGETS aasdk_proto DESTINATION lib) install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DESTINATION include diff --git a/buildenv/Dockerfile b/buildenv/Dockerfile new file mode 100644 index 0000000..f4b958c --- /dev/null +++ b/buildenv/Dockerfile @@ -0,0 +1,28 @@ +FROM debian:buster AS aasdk + +RUN dpkg --add-architecture armhf +RUN apt-get update +RUN apt-get -y install cmake build-essential git +RUN apt-get -y install gcc-arm-linux-gnueabihf cpp-arm-linux-gnueabihf g++-arm-linux-gnueabihf protobuf-compiler +RUN apt-get -y install gcc-8-base:armhf libc6:armhf libgcc1:armhf libicu63:armhf libidn2-0:armhf libstdc++6:armhf libunistring2:armhf + +# These are all the libboost requirements. It would be shorter if libboost-log-dev wasn't a disaster that's being dealt with manually. +RUN apt-get install -y libprotobuf-dev libusb-1.0.0-dev libssl-dev libboost-dev libboost-system-dev libboost-atomic1.67.0 libboost-chrono1.67.0 libboost-date-time1.67.0 libboost-filesystem1.67.0 libboost-regex1.67.0 libboost-thread1.67.0 libboost-filesystem1.67-dev libboost-thread1.67-dev libboost-date-time1.67-dev +RUN apt-get install -y libprotobuf-dev:armhf libusb-1.0.0-dev:armhf libssl-dev:armhf libboost-dev:armhf libboost-system-dev:armhf libboost-atomic1.67.0:armhf libboost-chrono1.67.0:armhf libboost-date-time1.67.0:armhf libboost-filesystem1.67.0:armhf libboost-regex1.67.0:armhf libboost-system1.67.0:armhf libboost-thread1.67.0:armhf libboost-filesystem1.67-dev:armhf libboost-thread1.67-dev:armhf libboost-date-time1.67-dev:armhf + +COPY / /src + +WORKDIR /src + +# Import resources +COPY ./buildenv/patch-libboost-log-deb.sh /src/resources/patch-libboost-log-deb.sh +COPY ./buildenv/entrypoint.sh /entrypoint.sh + +# Patch libboost-log-dev and install +RUN chmod +x ./resources/patch-libboost-log-deb.sh +RUN ./resources/patch-libboost-log-deb.sh + +# Make Executable +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] \ No newline at end of file diff --git a/buildenv/entrypoint.sh b/buildenv/entrypoint.sh new file mode 100644 index 0000000..6394b42 --- /dev/null +++ b/buildenv/entrypoint.sh @@ -0,0 +1,28 @@ +#!/bin/bash +ARCH=$1 +MAJORVER=0 + +if [ -z "$ARCH" ] +then + echo "Please supply a target architecture to build" + echo "Choose from 'amd64', 'armhf'" + exit +else + if [ "$ARCH" != "amd64" ] && [ "$ARCH" != "armhf" ] + then + echo "Invalid architecture requested" + exit + fi +fi + +echo "Now building within docker for $ARCH" + +# Clear out the /build directory +mkdir build; +cd build; +cmake -DCMAKE_BUILD_TYPE=Release -DTARGET_ARCH=$ARCH ../ +make -j4 +cpack --config CPackConfig.cmake + +# Move it to release +mv *.deb /release/ \ No newline at end of file diff --git a/buildenv/patch-libboost-log-deb.sh b/buildenv/patch-libboost-log-deb.sh new file mode 100644 index 0000000..7454a91 --- /dev/null +++ b/buildenv/patch-libboost-log-deb.sh @@ -0,0 +1,46 @@ +# All this because of a packaging bug in libboost-log-dev +# 'Multi-Arch: same' is not present in the control file of Debian packages, all the way up to Sid +# Rather than recompiling the parent libbost suite, download the 6 packages, extract, edit, and repackage. + +# https://bugs.debian.org/cgi-bin/pkgreport.cgi?package=libboost-log-dev + +apt-get -y install --download-only libboost-log-dev:amd64 libboost-log1.67.0:amd64 libboost-log1.67-dev:amd64 +apt-get -y install --download-only libboost-log-dev:armhf libboost-log1.67.0:armhf libboost-log1.67-dev:armhf + +mkdir -p /tmp/armhf/libboost-log-dev/ +dpkg-deb -x /var/cache/apt/archives/libboost-log-dev_1.67.0.1_armhf.deb /tmp/armhf/libboost-log-dev/ +dpkg-deb -e /var/cache/apt/archives/libboost-log-dev_1.67.0.1_armhf.deb /tmp/armhf/libboost-log-dev/DEBIAN/ +sed -i '/^Priority: optional/a Multi-Arch: same' /tmp/armhf/libboost-log-dev/DEBIAN/control +dpkg-deb -b /tmp/armhf/libboost-log-dev/ /tmp/libboost-log-dev_1.67.0.1_armhf.deb + +mkdir -p /tmp/amd64/libboost-log-dev/ +dpkg-deb -x /var/cache/apt/archives/libboost-log-dev_1.67.0.1_amd64.deb /tmp/amd64/libboost-log-dev/ +dpkg-deb -e /var/cache/apt/archives/libboost-log-dev_1.67.0.1_amd64.deb /tmp/amd64/libboost-log-dev/DEBIAN/ +sed -i '/^Priority: optional/a Multi-Arch: same' /tmp/amd64/libboost-log-dev/DEBIAN/control +dpkg-deb -b /tmp/amd64/libboost-log-dev/ /tmp/libboost-log-dev_1.67.0.1_amd64.deb + +mkdir -p /tmp/armhf/libboost-log1.67-dev/ +dpkg-deb -x /var/cache/apt/archives/libboost-log1.67-dev_1.67.0-13+deb10u1_armhf.deb /tmp/armhf/libboost-log1.67-dev/ +dpkg-deb -e /var/cache/apt/archives/libboost-log1.67-dev_1.67.0-13+deb10u1_armhf.deb /tmp/armhf/libboost-log1.67-dev/DEBIAN/ +sed -i '/^Priority: optional/a Multi-Arch: same' /tmp/armhf/libboost-log1.67-dev/DEBIAN/control +dpkg-deb -b /tmp/armhf/libboost-log1.67-dev/ /tmp/libboost-log1.67-dev_1.67.0-13+deb10u1_armhf.deb + +mkdir -p /tmp/amd64/libboost-log1.67-dev/ +dpkg-deb -x /var/cache/apt/archives/libboost-log1.67-dev_1.67.0-13+deb10u1_amd64.deb /tmp/amd64/libboost-log1.67-dev/ +dpkg-deb -e /var/cache/apt/archives/libboost-log1.67-dev_1.67.0-13+deb10u1_amd64.deb /tmp/amd64/libboost-log1.67-dev/DEBIAN/ +sed -i '/^Priority: optional/a Multi-Arch: same' /tmp/amd64/libboost-log1.67-dev/DEBIAN/control +dpkg-deb -b /tmp/amd64/libboost-log1.67-dev/ /tmp/libboost-log1.67-dev_1.67.0-13+deb10u1_amd64.deb + +mkdir -p /tmp/armhf/libboost-log1.67.0/ +dpkg-deb -x /var/cache/apt/archives/libboost-log1.67.0_1.67.0-13+deb10u1_armhf.deb /tmp/armhf/libboost-log1.67.0/ +dpkg-deb -e /var/cache/apt/archives/libboost-log1.67.0_1.67.0-13+deb10u1_armhf.deb /tmp/armhf/libboost-log1.67.0/DEBIAN/ +sed -i '/^Priority: optional/a Multi-Arch: same' /tmp/armhf/libboost-log1.67.0/DEBIAN/control +dpkg-deb -b /tmp/armhf/libboost-log1.67.0/ /tmp/libboost-log1.67.0_1.67.0-13+deb10u1_armhf.deb + +mkdir -p /tmp/amd64/libboost-log1.67.0/ +dpkg-deb -x /var/cache/apt/archives/libboost-log1.67.0_1.67.0-13+deb10u1_amd64.deb /tmp/amd64/libboost-log1.67.0/ +dpkg-deb -e /var/cache/apt/archives/libboost-log1.67.0_1.67.0-13+deb10u1_amd64.deb /tmp/amd64/libboost-log1.67.0/DEBIAN/ +sed -i '/^Priority: optional/a Multi-Arch: same' /tmp/amd64/libboost-log1.67.0/DEBIAN/control +dpkg-deb -b /tmp/amd64/libboost-log1.67.0/ /tmp/libboost-log1.67.0_1.67.0-13+deb10u1_amd64.deb + +dpkg -i /tmp/libboost*.deb \ No newline at end of file diff --git a/cmake_modules/gitversion.cmake b/cmake_modules/gitversion.cmake new file mode 100644 index 0000000..b3267b5 --- /dev/null +++ b/cmake_modules/gitversion.cmake @@ -0,0 +1,51 @@ +# cmake/gitversion.cmake +cmake_minimum_required(VERSION 3.0.0) + +message(STATUS "Resolving GIT Version") + +set(_build_version "unknown") +set(_commit_timestamp "unknown") + +find_package(Git) +if(GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + WORKING_DIRECTORY "${local_dir}" + OUTPUT_VARIABLE _build_version + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY "${local_dir}" + OUTPUT_VARIABLE _build_branch + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + execute_process( + COMMAND ${GIT_EXECUTABLE} log -1 --format=%at + WORKING_DIRECTORY "${local_dir}" + OUTPUT_VARIABLE _commit_timestamp + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + message( STATUS "GIT hash: ${_build_version}; branch: ${_build_branch}; Commit epoch: ${_commit_timestamp};") + execute_process( + COMMAND ${GIT_EXECUTABLE} diff --no-ext-diff --quiet + WORKING_DIRECTORY "${local_dir}" + RESULT_VARIABLE ret + ) + if(ret EQUAL "1") + set(_build_changes "*") + else() + set(_build_changes "") + endif() + +else() + message(STATUS "GIT not found") +endif() + +# branch name +# git rev-parse --abbrev-ref HEAD +# changed +# git diff --no-ext-diff --quiet