diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68eadde..04763dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,146 +6,9 @@ on: pull_request: branches: [main] -# Cancel redundant runs on the same ref (e.g. rapid pushes to a PR branch) -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - permissions: contents: read jobs: - build-linux: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: true - matrix: - include: - - { os: ubuntu-24.04, compiler: g++-13, packages: g++-13, build_type: Debug } - - { os: ubuntu-24.04, compiler: g++-14, packages: g++-14, build_type: Release } - - { os: ubuntu-24.04, compiler: clang++-18, packages: clang-18, build_type: Release } - - { os: ubuntu-24.04, compiler: clang++-19, packages: clang-19, build_type: Debug } - - { os: ubuntu-22.04, compiler: g++-12, packages: g++-12, build_type: Debug } - - { os: ubuntu-24.04-arm, compiler: g++-14, packages: g++-14, build_type: Debug } - - steps: - - uses: actions/checkout@v4 - - - name: Install compiler - run: | - sudo apt-get update -q - sudo apt-get install -y ${{ matrix.packages }} - - # Cache CPM-downloaded sources (Catch2 etc.) keyed on CMakeLists.txt content. - # CPM_SOURCE_CACHE is forwarded to cmake below so both steps agree on the path. - - name: Cache CPM sources - uses: actions/cache@v4 - with: - path: ${{ runner.temp }}/cpm-cache - key: cpm-${{ runner.os }}-${{ hashFiles('CMakeLists.txt') }} - restore-keys: cpm-${{ runner.os }}- - - # ccache-action manages save/restore internally; no separate actions/cache needed. - - name: Set up ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.build_type }} - - - name: Configure, build, and test - env: - CPM_SOURCE_CACHE: ${{ runner.temp }}/cpm-cache - run: | - cmake -B build \ - -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ - -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_STANDARD=23 - cmake --build build --parallel - ctest --test-dir build --output-on-failure - - build-windows: - needs: build-linux - runs-on: ${{ matrix.os }} - strategy: - fail-fast: true - matrix: - include: - # - { os: windows-2025, arch: x64, build_type: Debug } - - { os: windows-2025, arch: x64, build_type: Release } - - { os: windows-2025, arch: x86, build_type: Release } - - { os: windows-2022, arch: x64, build_type: Release } - - steps: - - uses: actions/checkout@v4 - - - name: Cache CPM sources - uses: actions/cache@v4 - with: - path: ${{ runner.temp }}/cpm-cache - key: cpm-${{ runner.os }}-${{ matrix.arch }}-${{ hashFiles('CMakeLists.txt') }} - restore-keys: cpm-${{ runner.os }}-${{ matrix.arch }}- - - - name: Set up sccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: windows-${{ matrix.arch }}-${{ matrix.build_type }} - variant: sccache - - - name: Set up MSVC - uses: TheMrMilchmann/setup-msvc-dev@v3 - with: - arch: ${{ matrix.arch }} - - - name: Configure, build, and test - env: - CPM_SOURCE_CACHE: ${{ runner.temp }}/cpm-cache - run: | - cmake -B build -G Ninja ` - -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} ` - -DCMAKE_CXX_COMPILER_LAUNCHER=sccache ` - -DCMAKE_CXX_STANDARD=23 - cmake --build build --parallel - ctest --test-dir build --output-on-failure - - build-macos: - needs: build-windows - runs-on: ${{ matrix.os }} - strategy: - fail-fast: true - max-parallel: 1 - matrix: - include: - # arm64 (Apple Silicon M1) — two macOS generations - - { os: macos-14, build_type: Debug } - - { os: macos-14, build_type: Release } - - { os: macos-15, build_type: Debug } - - { os: macos-15, build_type: Release } - - { os: macos-15-intel, build_type: Release } - - { os: macos-26, build_type: Release } - - { os: macos-26, build_type: Debug } - - steps: - - uses: actions/checkout@v4 - - - name: Cache CPM sources - uses: actions/cache@v4 - with: - path: ${{ runner.temp }}/cpm-cache - key: cpm-${{ runner.os }}-${{ matrix.os }}-${{ hashFiles('CMakeLists.txt') }} - restore-keys: cpm-${{ runner.os }}-${{ matrix.os }}- - - - name: Set up ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ matrix.os }}-${{ matrix.build_type }} - - - name: Configure, build, and test - env: - CPM_SOURCE_CACHE: ${{ runner.temp }}/cpm-cache - run: | - cmake -B build \ - -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_STANDARD=23 - cmake --build build --parallel 1 - ctest --test-dir build --output-on-failure + build: + uses: timblechmann/nova_github_actions/.github/workflows/cmake-ci.yml@main diff --git a/CMakeLists.txt b/CMakeLists.txt index bfdb946..d2de5d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.25) -project(nova_nonnull VERSION 0.1.0 LANGUAGES CXX) +project(nova_nonnull LANGUAGES CXX) if (NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 20) @@ -11,14 +11,16 @@ if (NOT CMAKE_MSVC_DEBUG_INFORMATION_FORMAT) set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "Embedded") endif() -add_custom_target(nova_nonnull_project_files SOURCES - .clang-tidy - .pre-commit-config.yaml - _clang-format - README.md - LICENSE - .github/workflows/ci.yml -) +if (PROJECT_IS_TOP_LEVEL) + add_custom_target(nova_nonnull_project_files SOURCES + .clang-tidy + .pre-commit-config.yaml + _clang-format + README.md + LICENSE + .github/workflows/ci.yml + ) +endif() # Project layout add_library(nova_nonnull INTERFACE) @@ -33,17 +35,18 @@ target_include_directories(nova_nonnull INTERFACE ) # Testing -option(NOVA_BUILD_TESTS "Build unit tests" ON) +option(NOVA_BUILD_TESTS "Build unit tests" ${PROJECT_IS_TOP_LEVEL}) if(NOVA_BUILD_TESTS) if (NOT COMMAND CPMAddPackage) - # CPM.cmake downloader - set(CPM_DOWNLOAD_VERSION 0.40.2) + set(CPM_DOWNLOAD_VERSION 0.42.3) if(NOT EXISTS "${CMAKE_BINARY_DIR}/cmake/CPM.cmake") - message(STATUS "Downloading CPM.cmake ${CPM_DOWNLOAD_VERSION}...") - file(DOWNLOAD - "https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake" - "${CMAKE_BINARY_DIR}/cmake/CPM.cmake" - ) + message(STATUS "Downloading CPM.cmake ${CPM_DOWNLOAD_VERSION}...") + file(DOWNLOAD + "https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake" + "${CMAKE_BINARY_DIR}/cmake/CPM.cmake" + TLS_VERIFY ON + EXPECTED_HASH SHA256=a609e875fd532b067174250f6abbc3dac22fe2d64869783fb1e80bda1625c844 + ) endif() include("${CMAKE_BINARY_DIR}/cmake/CPM.cmake") endif() @@ -54,7 +57,7 @@ if(NOVA_BUILD_TESTS) CPMAddPackage( NAME Catch2 GITHUB_REPOSITORY catchorg/Catch2 - VERSION 3.13.0 + VERSION 3.15.0 ) endblock() endif() @@ -68,6 +71,7 @@ if(NOVA_BUILD_TESTS) enable_testing() add_test(NAME nova_nonnull_tests COMMAND nova_nonnull_tests) + add_executable(nova_nonnull_asan_take_tests tests/asan_take.cpp ) @@ -83,6 +87,8 @@ if(NOVA_BUILD_TESTS) ) if (CMAKE_BUILD_TYPE STREQUAL "Debug") + target_compile_definitions(nova_nonnull_asan_take_tests PRIVATE NDEBUG) + add_test(NAME nova_nonnull_asan_take_tests COMMAND ${CMAKE_COMMAND} -E env $ ) diff --git a/include/nova/non_null.hpp b/include/nova/non_null.hpp index bd0ff4e..e23c916 100644 --- a/include/nova/non_null.hpp +++ b/include/nova/non_null.hpp @@ -12,7 +12,7 @@ #include #if defined( __has_feature ) -# if __has_feature( address_sanitizer ) +# if __has_feature( address_sanitizer ) && __has_include( ) # define NOVA_HAVE_ASAN 1 # endif #endif @@ -43,7 +43,7 @@ # endif #endif -#if defined( __GNUC__ ) || defined( __clang__ ) +#if ( defined( __GNUC__ ) || defined( __clang__ ) ) && !( defined( __clang_major__ ) && defined( __OPTIMIZE__ ) ) # define NOVA_RETURNS_NONNULL __attribute__( ( returns_nonnull ) ) #else # define NOVA_RETURNS_NONNULL