Skip to content

Commit

Permalink
Add support for CMake Presets (#348)
Browse files Browse the repository at this point in the history
* dev container + vscode extensions

* exploring cmake presets for CI

* ignore user presets

* add configure to build preset

windows ran in debug, which means the multi config needs more help

* coverage preset

* creating a fuzzing preset

* fuzzing fix cwd + more configs to preset

* move cmake set vars to right section

https://learn.microsoft.com/en-us/cpp/build/cmake-presets-vs?view=msvc-170

"You can set C and C++ compilers by using cacheVariables.CMAKE_C_COMPILER and cacheVariables.CMAKE_CXX_COMPILER in a Configure Preset. It's equivalent to passing -D CMAKE_C_COMPILER=<value> and -D CMAKE_CXX_COMPILER=<value> to CMake from the command line."

* fix workdir for new fuzz run targets

* split up presets into more files

* fix include order (liking this less)

* add asan to presets

* fix copy paste

* add asan build preset

* move ubsan to presets

* replace mustache with a cmake script

* touch ups

* restore file to void merge conflicts

* fix order for args

* remove action wrapper

more quotes for inputs

* revert bad render of boost_json

* fix casing

* format changes

* test to see if output is working

* last try

* git revert moving mustache to cmake

* cmake not enough for presets

* drop ci prefix

* new test for `library_ROOT` search path

* install with presets

* cmake --install does not take a preset

* install with preset is not yet supported

https://gitlab.kitware.com/cmake/cmake/-/issues/23208

* add missing build step

* more global fuzzing flags to toolchain file

* fixup toolchain in presets

* fix pathing and limit configs to tested platforms

* clean up + use presets for clang-tidy

* dry up sanitizer flags

* try install with a preset

* remove duplicated test

* notes about hunter test

* skip checking the compiler since this causes errors with the same CMake uses in combinations with the fuzz sanitizer flag

https://github.com/prince-chrismc/jwt-cpp/actions/runs/7481024827/job/20361722539?pr=33

```
    /usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x22
    CMakeFiles/cmTC_ff7c6.dir/testCCompiler.c.o: in function `main':
    testCCompiler.c:(.text.main[main]+0x0): multiple definition of `main'; /usr/lib/llvm-14/lib/clang/14.0.0/lib/linux/libclang_rt.fuzzer-x86_64.a(FuzzerMain.cpp.o):(.text.main+0x0): first defined here
    /usr/bin/ld: /usr/lib/llvm-14/lib/clang/14.0.0/lib/linux/libclang_rt.fuzzer-x86_64.a(FuzzerMain.cpp.o): in function `main':
    (.text.main+0x12): undefined reference to `LLVMFuzzerTestOneInput'
```

* remove system name to disable cross compiling

* tests do not pass clang-tidy

* drop toolchain, use target specific flags

* leave flags in cmake

* missing deps + clean apt files

* remove some code duplication

* fix typo

* devcontainers fix, test and add wolfssl

refactored installer to have a script that could be reused

* add missing build context

* pass version to script

* dont use bash syntax

* fix typo

* upload tar.gz for new releases

* revert name to manually trigger it

* Update and rename nuget.yml to release.yml

* disable nuget for testing

* add a zip as well

* back to basics

* remove remove testing code

* update workflow name

* enable testing needs to be in the root

* add a test preset and use it in some workflows

* fix linting tests

* bump github actions

* bump python setup

* drop dev containers

* dont install openssl on windows

* revert merge conflicts

* fix whitespace

* fix private claims example to have a valid token

#351

* put back versioned format

I dont remember why, it looks like it was debugging
  • Loading branch information
prince-chrismc authored Jun 15, 2024
1 parent 0d03bc5 commit a6927cb
Show file tree
Hide file tree
Showing 15 changed files with 351 additions and 80 deletions.
31 changes: 26 additions & 5 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ jobs:

- name: setup
run: |
mkdir build
cd build
cmake .. -DJWT_BUILD_EXAMPLES=OFF
sudo make install
cmake --preset release
sudo cmake --build --preset release --target install
- name: test
working-directory: tests/cmake
Expand Down Expand Up @@ -95,6 +93,29 @@ jobs:
cmake . -DTEST:STRING="defaults-enabled"
cmake --build .
preset-support-but-not-enough:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install/cmake
with:
version: "3.24.4"
url: "https://cmake.org/files/v3.24/cmake-3.24.4.tar.gz"
- uses: ./.github/actions/install/gtest

- name: setup
run: |
mkdir build
cd build
cmake .. -DJWT_BUILD_EXAMPLES=ON -DJWT_BUILD_TESTS=ON
sudo make install
- name: test
run: |
cd tests/cmake
cmake . -DTEST:STRING="defaults-enabled"
cmake --build .
custom-install-linux:
runs-on: ubuntu-latest
steps:
Expand All @@ -117,7 +138,7 @@ jobs:
root-hint-install-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: lukka/get-cmake@latest

- name: setup
Expand Down
13 changes: 4 additions & 9 deletions .github/workflows/cross-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,17 @@ jobs:

steps:
- uses: actions/checkout@v4
- run: cmake -E make_directory ${{ github.workspace }}/build

- name: configure
shell: bash # access regardless of the host operating system
working-directory: ${{ github.workspace }}/build
run: cmake $GITHUB_WORKSPACE -DJWT_BUILD_EXAMPLES=ON
run: cmake --preset examples

- name: build
working-directory: ${{ github.workspace }}/build
shell: bash
run: cmake --build .
run: cmake --build --preset examples

- name: test
run: |
cmake --build build/ --target rsa-create-run
cmake --build build/ --target rsa-verify-run
cmake --build --preset examples --target rsa-create-run
cmake --build --preset examples --target rsa-verify-run
- if: github.event_name == 'push' && always()
uses: ./.github/actions/badge
Expand Down
71 changes: 26 additions & 45 deletions .github/workflows/jwt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ jobs:
- uses: ./.github/actions/install/open-source-parsers-jsoncpp

- name: configure
run: |
mkdir build
cd build
cmake .. -DJWT_BUILD_EXAMPLES=OFF -DJWT_BUILD_TESTS=ON -DJWT_ENABLE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug
run: cmake --preset coverage
- name: run
working-directory: build
run: make jwt-cpp-test coverage
run: cmake --build --preset coverage

- uses: coverallsapp/github-action@v2
with:
Expand All @@ -38,21 +33,19 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: lukka/get-cmake@latest
- uses: ./.github/actions/install/gtest

- name: configure
run: |
mkdir build
cd build
cmake .. -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DJWT_ENABLE_FUZZING=ON
run: cmake --preset ci-fuzzing
- name: build
run: cmake --build --preset ci-fuzzing

- name: run
run: |
cmake --build build/ --target jwt-cpp-fuzz-BaseEncodeFuzz-run
cmake --build build/ --target jwt-cpp-fuzz-BaseDecodeFuzz-run
cmake --build build/ --target jwt-cpp-fuzz-TokenDecodeFuzz-run
cmake --build --preset ci-fuzzing --target jwt-cpp-fuzz-BaseEncodeFuzz-run
cmake --build --preset ci-fuzzing --target jwt-cpp-fuzz-BaseDecodeFuzz-run
cmake --build --preset ci-fuzzing --target jwt-cpp-fuzz-TokenDecodeFuzz-run
asan: # Based on https://gist.github.com/jlblancoc/44be9d4d466f0a973b1f3808a8e56782
asan:
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -69,46 +62,34 @@ jobs:
version: ${{ matrix.openssl.tag }}

- name: configure
run: |
mkdir build
cd build
cmake .. -DJWT_BUILD_TESTS=ON -DCMAKE_CXX_FLAGS="-fsanitize=address -fsanitize=leak -g" \
-DCMAKE_C_FLAGS="-fsanitize=address -fsanitize=leak -g" \
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address -fsanitize=leak" \
-DCMAKE_MODULE_LINKER_FLAGS="-fsanitize=address -fsanitize=leak"
run: cmake --preset ci-asan
- name: build
run: cmake --build --preset ci-asan

- name: run
working-directory: build
run: |
make
export ASAN_OPTIONS=check_initialization_order=true:detect_stack_use_after_return=true:fast_unwind_on_malloc=0
./example/rsa-create
./example/rsa-verify
./example/jwks-verify
./tests/jwt-cpp-test
cmake --build --preset ci-asan --target private-claims-run
cmake --build --preset ci-asan --target rsa-create-run
cmake --build --preset ci-asan --target rsa-verify-run
cmake --build --preset ci-asan --target jwks-verify-run
cmake --build --preset ci-asan --target jwt-cpp-test-run
ubsan:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: lukka/get-cmake@latest
- uses: ./.github/actions/install/gtest

- name: configure
run: |
mkdir build
cd build
cmake .. -DJWT_BUILD_TESTS=ON -DCMAKE_CXX_STANDARD=20 \
-DCMAKE_CXX_FLAGS="-fsanitize=undefined -fsanitize=return -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize-recover=all -g" \
-DCMAKE_C_FLAGS="-fsanitize=undefined -fsanitize=return -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize-recover=all -g" \
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=undefined -fsanitize=return -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize-recover=all" \
-DCMAKE_MODULE_LINKER_FLAGS="-fsanitize=undefined -fsanitize=return -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize-recover=all"
run: cmake --preset ci-ubsan
- name: build
run: cmake --build --preset ci-ubsan -DCMAKE_CXX_STANDARD=20

- name: run
working-directory: build
run: |
make
export UBSAN_OPTIONS=print_stacktrace=1
./example/rsa-create
./example/rsa-verify
./tests/jwt-cpp-test
cmake --build --preset ci-ubsan --target private-claims-run
cmake --build --preset ci-ubsan --target rsa-create-run
cmake --build --preset ci-ubsan --target rsa-verify-run
cmake --build --preset ci-ubsan --target jwks-verify-run
cmake --build --preset ci-ubsan --target jwt-cpp-test-run
10 changes: 3 additions & 7 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
matrix:
files: ["**/CMakeLists.txt", "cmake/code-coverage.cmake"]
steps:
- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- run: pip install cmakelang
Expand All @@ -54,13 +54,9 @@ jobs:
- uses: lukka/get-cmake@latest
- uses: actions/checkout@v4
- name: configure
run: |
mkdir build
cd build
cmake .. -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-fix"
run: cmake --preset examples -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-fix"
- name: run
working-directory: build
run: make
run: cmake --build --preset examples
- uses: ./.github/actions/process-linting-results
with:
linter_name: clang-tidy
Expand Down
24 changes: 13 additions & 11 deletions .github/workflows/ssl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
version: ${{ matrix.openssl.tag }}

- name: configure
run: cmake . -DJWT_BUILD_TESTS=ON -DOPENSSL_ROOT_DIR=/tmp
- run: make
run: cmake --preset unit-tests -DOPENSSL_ROOT_DIR=/tmp
- run: cmake --build --preset unit-tests
- name: test
run: ./tests/jwt-cpp-test
run: ctest --preset unit-tests

- if: github.event_name == 'push' && always()
uses: ./.github/actions/badge
Expand All @@ -50,8 +50,10 @@ jobs:
version: "openssl-3.0.5"

- name: configure
run: cmake . -DJWT_BUILD_TESTS=ON -DOPENSSL_ROOT_DIR=/tmp -DCMAKE_CXX_FLAGS="-DOPENSSL_NO_DEPRECATED=1" -DCMAKE_C_FLAGS="-DOPENSSL_NO_DEPRECATED=1"
- run: make
run: cmake --preset unit-tests -DOPENSSL_ROOT_DIR=/tmp -DCMAKE_CXX_FLAGS="-DOPENSSL_NO_DEPRECATED=1" -DCMAKE_C_FLAGS="-DOPENSSL_NO_DEPRECATED=1"
- run: cmake --build --preset unit-tests
- name: test
run: ctest --preset unit-tests

libressl:
runs-on: ubuntu-latest
Expand All @@ -69,10 +71,10 @@ jobs:
version: ${{ matrix.libressl }}

- name: configure
run: cmake . -DJWT_BUILD_TESTS=ON -DJWT_SSL_LIBRARY:STRING=LibreSSL
- run: make
run: cmake --preset unit-tests -DJWT_SSL_LIBRARY:STRING=LibreSSL
- run: cmake --build --preset unit-tests
- name: test
run: ./tests/jwt-cpp-test
run: ctest --preset unit-tests

- if: github.event_name == 'push' && always()
uses: ./.github/actions/badge
Expand All @@ -98,10 +100,10 @@ jobs:
version: ${{ matrix.wolfssl.ref }}

- name: configure
run: cmake . -DJWT_BUILD_TESTS=ON -DJWT_SSL_LIBRARY:STRING=wolfSSL
- run: make
run: cmake --preset unit-tests -DJWT_SSL_LIBRARY:STRING=wolfSSL
- run: cmake --build --preset unit-tests
- name: test
run: ./tests/jwt-cpp-test
run: ctest --preset unit-tests

- if: github.event_name == 'push' && always()
uses: ./.github/actions/badge
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,15 @@ $RECYCLE.BIN/
test
*.o
*.o.d
.vscode

# IDE-specific files
.vscode/
.vscode/!extensions.json # Allow to provide recommended extensions

# ClangD cache files
.cache

build/*
package-lock.json

CMakeUserPresets.json
10 changes: 10 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"recommendations": [
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"ms-vscode.cmake-tools",
"twxs.cmake",
"matepek.vscode-catch2-test-adapter",
"GitHub.vscode-github-actions"
]
}
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ if(JWT_BUILD_EXAMPLES)
endif()

if(JWT_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

Expand Down
33 changes: 33 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
"patch": 0
},
"include": [
"example/CMakePresets.json",
"tests/CMakePresets.json"
],
"configurePresets": [
{
"name": "dev",
"displayName": "Development",
"inherits": "debug",
"environment": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
},
"cacheVariables": {
"JWT_BUILD_EXAMPLES": "ON",
"JWT_BUILD_TESTS": "ON"
}
}
],
"buildPresets": [
{
"name": "dev",
"configurePreset": "dev",
"configuration": "Debug"
}
]
}
48 changes: 48 additions & 0 deletions cmake/CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "Default Config",
"hidden": true,
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"JWT_BUILD_EXAMPLES": "OFF",
"JWT_BUILD_TESTS": "OFF"
}
},
{
"name": "debug",
"displayName": "Debug",
"inherits": "default",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"displayName": "Release",
"inherits": "default",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"buildPresets": [
{
"name": "debug",
"configurePreset": "debug",
"configuration": "Debug"
},
{
"name": "release",
"configurePreset": "release",
"configuration": "Release"
}
]
}
1 change: 1 addition & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ add_custom_target(print-claims-run COMMAND print-claims)

add_executable(private-claims private-claims.cpp)
target_link_libraries(private-claims jwt-cpp::jwt-cpp)
add_custom_target(private-claims-run COMMAND private-claims)

add_executable(rsa-create rsa-create.cpp)
target_link_libraries(rsa-create jwt-cpp::jwt-cpp)
Expand Down
Loading

0 comments on commit a6927cb

Please sign in to comment.