Skip to content

Commit

Permalink
Merge Develop (#34)
Browse files Browse the repository at this point in the history
* Fix renaming of project with janitor
* Correct detected build settings around UBSAN
  • Loading branch information
lefticus authored Apr 29, 2023
1 parent 9451f27 commit 9bb9b40
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 41 deletions.
11 changes: 4 additions & 7 deletions .github/actions/setup_cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ inputs:
generator:
required: true
type: string
developer_mode:
packaging_maintainer_mode:
required: true
type: string

Expand All @@ -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 }}
1 change: 1 addition & 0 deletions .github/constants.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJECT_NAME=myproject
2 changes: 1 addition & 1 deletion .github/workflows/auto-clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: '.'
Expand Down
29 changes: 17 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ on:
env:
CLANG_TIDY_VERSION: "15.0.2"
VERBOSE: 1
PROJECT_NAME: myproject


jobs:
Expand Down Expand Up @@ -42,7 +41,7 @@ jobs:
build_type:
- Release
- Debug
package_maintainer_mode:
packaging_maintainer_mode:
- ON
- OFF
build_shared:
Expand All @@ -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
Expand All @@ -78,42 +77,42 @@ jobs:
generator: "Unix Makefiles"
build_type: Debug
gcov_executable: gcov
package_maintainer_mode: On
packaging_maintainer_mode: On
enable_ipo: Off

# Windows msvc builds
- os: windows-2022
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

Expand All @@ -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:
Expand All @@ -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 <NAME>"
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ on:
schedule:
- cron: '38 0 * * 5'

env:
PROJECT_NAME: myproject

jobs:
analyze:
Expand Down Expand Up @@ -50,7 +48,7 @@ jobs:


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

- name: Setup Cache
uses: ./.github/actions/setup_cache
Expand All @@ -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
Expand Down
24 changes: 17 additions & 7 deletions .github/workflows/template-janitor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- OFF

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

- name: Setup Cache
uses: ./.github/actions/setup_cache
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }}

Expand All @@ -156,7 +164,7 @@ jobs:
- OFF

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

- name: Setup Cache
uses: ./.github/actions/setup_cache
Expand Down Expand Up @@ -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 }}
34 changes: 23 additions & 11 deletions ProjectOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9bb9b40

Please sign in to comment.