From 9bb9b40689296726c917ada0a1bd159e2ce0451f Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 29 Apr 2023 15:41:00 -0600 Subject: [PATCH] Merge Develop (#34) * Fix renaming of project with janitor * Correct detected build settings around UBSAN --- .github/actions/setup_cache/action.yml | 11 +++----- .github/constants.env | 1 + .github/workflows/auto-clang-format.yml | 2 +- .github/workflows/ci.yml | 29 ++++++++++++--------- .github/workflows/codeql-analysis.yml | 9 ++++--- .github/workflows/template-janitor.yml | 24 ++++++++++++----- ProjectOptions.cmake | 34 +++++++++++++++++-------- 7 files changed, 69 insertions(+), 41 deletions(-) create mode 100644 .github/constants.env diff --git a/.github/actions/setup_cache/action.yml b/.github/actions/setup_cache/action.yml index 197e5571..7bf260e2 100644 --- a/.github/actions/setup_cache/action.yml +++ b/.github/actions/setup_cache/action.yml @@ -11,7 +11,7 @@ inputs: generator: required: true type: string - developer_mode: + packaging_maintainer_mode: required: true type: string @@ -20,16 +20,13 @@ runs: using: "composite" steps: - name: Cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: # You might want to add .ccache to your cache configuration? path: | ~/.cache/pip - ${{ env.HOME }}/.cache/vcpkg/archives - ${{ env.XDG_CACHE_HOME }}/vcpkg/archives - ${{ env.LOCALAPPDATA }}\vcpkg\archives - ${{ env.APPDATA }}\vcpkg\archives - key: ${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.build_type }}-${{ inputs.generator }}-${{ inputs.developer_mode }}-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('./vcpkg.json')}} + ~/.ccache + key: ${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.build_type }}-${{ inputs.generator }}-${{ inputs.packaging_maintainer_mode }}-${{ hashFiles('**/CMakeLists.txt') }} restore-keys: | ${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.build_type }} diff --git a/.github/constants.env b/.github/constants.env new file mode 100644 index 00000000..5c8528a0 --- /dev/null +++ b/.github/constants.env @@ -0,0 +1 @@ +PROJECT_NAME=myproject diff --git a/.github/workflows/auto-clang-format.yml b/.github/workflows/auto-clang-format.yml index c39fb5e7..b4e0a1b9 100644 --- a/.github/workflows/auto-clang-format.yml +++ b/.github/workflows/auto-clang-format.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: DoozyX/clang-format-lint-action@v0.13 with: source: '.' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 72e2af3a..db6c6110 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,6 @@ on: env: CLANG_TIDY_VERSION: "15.0.2" VERBOSE: 1 - PROJECT_NAME: myproject jobs: @@ -42,7 +41,7 @@ jobs: build_type: - Release - Debug - package_maintainer_mode: + packaging_maintainer_mode: - ON - OFF build_shared: @@ -69,7 +68,7 @@ jobs: # Set up preferred package generators, for given build configurations - build_type: Release - package_maintainer_mode: OFF + packaging_maintainer_mode: OFF package_generator: TBZ2 # This exists solely to make sure a non-multiconfig build works @@ -78,7 +77,7 @@ jobs: generator: "Unix Makefiles" build_type: Debug gcov_executable: gcov - package_maintainer_mode: On + packaging_maintainer_mode: On enable_ipo: Off # Windows msvc builds @@ -86,34 +85,34 @@ jobs: compiler: msvc generator: "Visual Studio 17 2022" build_type: Debug - package_maintainer_mode: On + packaging_maintainer_mode: On enable_ipo: On - os: windows-2022 compiler: msvc generator: "Visual Studio 17 2022" build_type: Release - package_maintainer_mode: On + packaging_maintainer_mode: On enable_ipo: On - os: windows-2022 compiler: msvc generator: "Visual Studio 17 2022" build_type: Debug - package_maintainer_mode: Off + packaging_maintainer_mode: Off - os: windows-2022 compiler: msvc generator: "Visual Studio 17 2022" build_type: Release - package_maintainer_mode: Off + packaging_maintainer_mode: Off package_generator: ZIP - os: windows-2022 compiler: msvc generator: "Visual Studio 17 2022" build_type: Release - package_maintainer_mode: On + packaging_maintainer_mode: On enable_ipo: On build_shared: On @@ -126,16 +125,22 @@ jobs: script: | core.setFailed('There is a mismatch between configured llvm compiler and clang-tidy version chosen') - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Cache uses: ./.github/actions/setup_cache with: compiler: ${{ matrix.compiler }} build_type: ${{ matrix.build_type }} - package_maintainer_mode: ${{ matrix.package_maintainer_mode }} + packaging_maintainer_mode: ${{ matrix.packaging_maintainer_mode }} generator: ${{ matrix.generator }} + - name: Project Name + uses: cardinalby/export-env-action@v2 + with: + envFile: '.github/constants.env' + + - name: Setup Cpp uses: aminya/setup-cpp@v1 with: @@ -156,7 +161,7 @@ jobs: - name: Configure CMake run: | - cmake -S . -B ./build -G "${{matrix.generator}}" -D${{ env.PROJECT_NAME }}_ENABLE_IPO=${{matrix.enable_ipo }} -DCMAKE_BUILD_TYPE:STRING=${{matrix.build_type}} -D${{ env.PROJECT_NAME }}_PACKAGING_MAINTAINER_MODE:BOOL=${{matrix.package_maintainer_mode}} -D${{ env.PROJECT_NAME }}_ENABLE_COVERAGE:BOOL=${{ matrix.build_type == 'Debug' }} -DGIT_SHA:STRING=${{ github.sha }} + cmake -S . -B ./build -G "${{matrix.generator}}" -D${{ env.PROJECT_NAME }}_ENABLE_IPO=${{matrix.enable_ipo }} -DCMAKE_BUILD_TYPE:STRING=${{matrix.build_type}} -D${{ env.PROJECT_NAME }}_PACKAGING_MAINTAINER_MODE:BOOL=${{matrix.packaging_maintainer_mode}} -D${{ env.PROJECT_NAME }}_ENABLE_COVERAGE:BOOL=${{ matrix.build_type == 'Debug' }} -DGIT_SHA:STRING=${{ github.sha }} - name: Build # Execute the build. You can specify a specific target with "--target " diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index d527156f..e21dc29e 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -20,8 +20,6 @@ on: schedule: - cron: '38 0 * * 5' -env: - PROJECT_NAME: myproject jobs: analyze: @@ -50,7 +48,7 @@ jobs: steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Cache uses: ./.github/actions/setup_cache @@ -60,6 +58,11 @@ jobs: packaging_maintainer_mode: ${{ matrix.packaging_maintainer_mode }} generator: ${{ matrix.generator }} + - name: Project Name + uses: cardinalby/export-env-action@v2 + with: + envFile: '.github/constants.env' + - name: Setup Cpp uses: aminya/setup-cpp@v1 diff --git a/.github/workflows/template-janitor.yml b/.github/workflows/template-janitor.yml index d188cc3b..071ead0b 100644 --- a/.github/workflows/template-janitor.yml +++ b/.github/workflows/template-janitor.yml @@ -33,7 +33,7 @@ jobs: - OFF steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Cache uses: ./.github/actions/setup_cache @@ -74,7 +74,7 @@ jobs: - name: Insert new org and project run: | # rename the CMake project to match the github project - find src include test fuzz_test cmake -type f -exec sed -i "s/myproject/${{ env.NEW_SAFE_PROJECT }}/gi" CMakeLists.txt Dependencies.cmake ProjectOptions.cmake .github/workflows/ci.yml .github/workflows/codeql-analysis.yml configured_files/config.hpp.in {} + + find src include test fuzz_test cmake -type f -exec sed -i "s/myproject/${{ env.NEW_SAFE_PROJECT }}/gi" .github/constants.env CMakeLists.txt Dependencies.cmake ProjectOptions.cmake .github/workflows/ci.yml .github/workflows/codeql-analysis.yml configured_files/config.hpp.in {} + # Update URL placeholders for project sed -i "s|%%myurl%%|${{ fromJson(steps.get_repo_meta.outputs.data).html_url }}|gi" CMakeLists.txt @@ -122,20 +122,28 @@ jobs: gcovr: false opencppcoverage: false + - name: Project Name + uses: cardinalby/export-env-action@v2 + with: + envFile: '.github/constants.env' + + - name: Test simple configuration to make sure nothing broke run: | - cmake -S . -B ./build -G "${{ matrix.generator }}" -DCMAKE_BUILD_TYPE:STRING=${{ matrix.build_type }} -DENABLE_DEVELOPER_MODE:BOOL=${{ matrix.developer_mode }} -DOPT_ENABLE_COVERAGE:BOOL=OFF + cmake -S . -B ./build -G "${{ matrix.generator }}" -DCMAKE_BUILD_TYPE:STRING=${{ matrix.build_type }} -D${{ env.NEW_SAFE_PROJECT }}_PACKAGING_MAINTAINER_MODE:BOOL=ON # Build it because we may have broken something in the cpp/hpp files cmake --build build - - uses: EndBug/add-and-commit@v4 + - uses: EndBug/add-and-commit@v9 # only commit and push if we are not a template project anymore! if: fromJson(steps.get_repo_meta.outputs.data).is_template != true with: + add: -A author_name: Template Janitor author_email: template.janitor@example.com message: 'Cleanup template and initialize repository' + pathspec_error_handling: exitImmediately env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -156,7 +164,7 @@ jobs: - OFF steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Cache uses: ./.github/actions/setup_cache @@ -223,14 +231,16 @@ jobs: - name: Test simple configuration to make sure nothing broke (default compiler,cmake,developer_mode OFF) run: | - cmake -S . -B ./build -G "${{ matrix.generator }}" -DCMAKE_BUILD_TYPE:STRING=${{ matrix.build_type }} -DENABLE_DEVELOPER_MODE:BOOL=${{ matrix.developer_mode }} -DOPT_ENABLE_COVERAGE:BOOL=OFF + cmake -S . -B ./build -G "${{ matrix.generator }}" -DCMAKE_BUILD_TYPE:STRING=${{ matrix.build_type }} -D${{ env.PROJECT_NAME }}_PACKAGING_MAINTAINER_MODE:BOOL=ON - - uses: EndBug/add-and-commit@v4 + - uses: EndBug/add-and-commit@v9 # only commit and push if we are a template and project name has changed if: fromJson(steps.get_repo_meta.outputs.data).is_template == true && env.TEST_RUN == 'false' with: + add: -A author_name: Template Janitor author_email: template.janitor@example.com message: 'Change Template Name' + pathspec_error_handling: exitImmediately env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/ProjectOptions.cmake b/ProjectOptions.cmake index b469cae7..2709aa1a 100644 --- a/ProjectOptions.cmake +++ b/ProjectOptions.cmake @@ -3,16 +3,8 @@ include(cmake/LibFuzzer.cmake) include(CMakeDependentOption) include(CheckCXXCompilerFlag) -macro(myproject_setup_options) - option(myproject_ENABLE_HARDENING "Enable hardening" ON) - option(myproject_ENABLE_COVERAGE "Enable coverage reporting" OFF) - cmake_dependent_option( - myproject_ENABLE_GLOBAL_HARDENING - "Attempt to push hardening options to built dependencies" - ON - myproject_ENABLE_HARDENING - OFF) +macro(myproject_supports_sanitizers) if((CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*" OR CMAKE_CXX_COMPILER_ID MATCHES ".*GNU.*") AND NOT WIN32) set(SUPPORTS_UBSAN ON) else() @@ -24,6 +16,19 @@ macro(myproject_setup_options) else() set(SUPPORTS_ASAN ON) endif() +endmacro() + +macro(myproject_setup_options) + option(myproject_ENABLE_HARDENING "Enable hardening" ON) + option(myproject_ENABLE_COVERAGE "Enable coverage reporting" OFF) + cmake_dependent_option( + myproject_ENABLE_GLOBAL_HARDENING + "Attempt to push hardening options to built dependencies" + ON + myproject_ENABLE_HARDENING + OFF) + + myproject_supports_sanitizers() if(NOT PROJECT_IS_TOP_LEVEL OR myproject_PACKAGING_MAINTAINER_MODE) option(myproject_ENABLE_IPO "Enable IPO/LTO" OFF) @@ -90,9 +95,12 @@ macro(myproject_global_options) myproject_enable_ipo() endif() + myproject_supports_sanitizers() + if(myproject_ENABLE_HARDENING AND myproject_ENABLE_GLOBAL_HARDENING) include(cmake/Hardening.cmake) - if(myproject_ENABLE_SANITIZER_UNDEFINED + if(NOT SUPPORTS_UBSAN + OR myproject_ENABLE_SANITIZER_UNDEFINED OR myproject_ENABLE_SANITIZER_ADDRESS OR myproject_ENABLE_SANITIZER_THREAD OR myproject_ENABLE_SANITIZER_LEAK) @@ -177,7 +185,11 @@ macro(myproject_local_options) if(myproject_ENABLE_HARDENING AND NOT myproject_ENABLE_GLOBAL_HARDENING) include(cmake/Hardening.cmake) - if(myproject_ENABLE_SANITIZER_UNDEFINED) + if(NOT SUPPORTS_UBSAN + OR myproject_ENABLE_SANITIZER_UNDEFINED + OR myproject_ENABLE_SANITIZER_ADDRESS + OR myproject_ENABLE_SANITIZER_THREAD + OR myproject_ENABLE_SANITIZER_LEAK) set(ENABLE_UBSAN_MINIMAL_RUNTIME FALSE) else() set(ENABLE_UBSAN_MINIMAL_RUNTIME TRUE)