Skip to content

Commit

Permalink
sarif: gate SARIF behind a VCPKG feature
Browse files Browse the repository at this point in the history
  • Loading branch information
frabert committed Aug 26, 2024
1 parent 53b1a07 commit a7ceecc
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 39 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
# Tells vcpkg where binary packages are stored.
VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/vcpkg/bincache
# Use specific vcpkg version
VCPKG_COMMIT_ID: '5568f110b509a9fd90711978a7cb76bae75bb092'
VCPKG_COMMIT_ID: '8e7e48eb0f61427bd5c18ba80bac7f33aa184ba5'

jobs:
build:
Expand Down Expand Up @@ -50,6 +50,6 @@ jobs:
- name: Run cmake
uses: lukka/run-cmake@v10
with:
configurePreset: 'ninja-multi-vcpkg'
buildPreset: 'ninja-vcpkg-deb'
testPreset: 'ninja-vcpkg-deb'
configurePreset: 'ninja-multi-vcpkg-full'
buildPreset: 'ninja-vcpkg-deb-full'
testPreset: 'ninja-vcpkg-deb-full'
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ add_subdirectory(core)
add_subdirectory(coro)
add_subdirectory(graph)

option(GAP_ENABLE_SARIF "Enable SARIF support" OFF)
option(GAP_ENABLE_SARIF "Enable SARIF support"
$<IN_LIST:sarif,VCPKG_MANIFEST_FEATURES>
)

if (${GAP_ENABLE_SARIF})
add_subdirectory(sarif)
Expand Down
28 changes: 18 additions & 10 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
"VCPKG_MANIFEST_FEATURES": "with-doctest"
}
},
{
"name": "all-vcpkg-features",
"hidden": true,
"description": "Use doctest package and enable SARIF",
"cacheVariables": {
"VCPKG_MANIFEST_FEATURES": "with-doctest;sarif"
}
},
{
"name": "ninja-multi-vcpkg",
"displayName": "Ninja Multi-Config Configure Settings",
Expand All @@ -27,9 +35,9 @@
}
},
{
"name": "ninja-multi-vcpkg-doctest",
"name": "ninja-multi-vcpkg-full",
"displayName": "Ninja Multi-Config Configure Settings with doctest",
"inherits": [ "ninja-multi-vcpkg", "with-doctest" ]
"inherits": [ "ninja-multi-vcpkg", "all-vcpkg-features" ]
}
],

Expand All @@ -47,15 +55,15 @@
"configuration": "Release"
},
{
"name": "ninja-vcpkg-deb-doctest",
"configurePreset": "ninja-multi-vcpkg-doctest",
"displayName": "Build ninja-multi-vcpkg-debug-doctest",
"name": "ninja-vcpkg-deb-full",
"configurePreset": "ninja-multi-vcpkg-full",
"displayName": "Build ninja-multi-vcpkg-debug-full",
"configuration": "Debug"
},
{
"name": "ninja-vcpkg-rel-doctest",
"configurePreset": "ninja-multi-vcpkg-doctest",
"displayName": "Build ninja-multi-vcpkg-release-doctest",
"name": "ninja-vcpkg-rel-full",
"configurePreset": "ninja-multi-vcpkg-full",
"displayName": "Build ninja-multi-vcpkg-release-full",
"configuration": "Release"
}
],
Expand All @@ -70,8 +78,8 @@
"configuration": "Debug"
},
{
"name": "ninja-vcpkg-deb-doctest",
"configurePreset": "ninja-multi-vcpkg-doctest",
"name": "ninja-vcpkg-deb-full",
"configurePreset": "ninja-multi-vcpkg-full",
"output": {
"verbosity": "verbose"
},
Expand Down
21 changes: 12 additions & 9 deletions sarif/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Copyright (c) 2024-present, Trail of Bits, Inc. All rights reserved.

find_package(nlohmann_json CONFIG REQUIRED)
if (GAP_ENABLE_SARIF)
find_package(nlohmann_json CONFIG REQUIRED)

add_headers(sarif GAP_SARIF_HEADERS
sarif.hpp
)
add_headers(sarif GAP_SARIF_HEADERS
sarif.hpp
)

add_sources(sarif GAP_SARIF_SOURCES
sarif.cpp
)
add_sources(sarif GAP_SARIF_SOURCES
sarif.cpp
)

add_gap_static_library(gap-sarif "${GAP_SARIF_HEADERS}" "${GAP_SARIF_SOURCES}")
target_link_libraries(gap-sarif PUBLIC nlohmann_json::nlohmann_json)
add_gap_static_library(gap-sarif "${GAP_SARIF_HEADERS}" "${GAP_SARIF_SOURCES}")
target_link_libraries(gap-sarif PUBLIC nlohmann_json::nlohmann_json)
target_compile_definitions(gap-sarif PUBLIC GAP_ENABLE_SARIF=1)
endif()
16 changes: 10 additions & 6 deletions sarif/include/gap/sarif/sarif.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
// Enum value names are converted from camelCase to PascalCase and prefixed with `k`.
//

#include <cstdint>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>
#ifdef GAP_ENABLE_SARIF

#include <nlohmann/json.hpp>
#include <cstdint>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>

#include <nlohmann/json.hpp>

namespace gap::sarif
{
Expand Down Expand Up @@ -2697,3 +2699,5 @@ namespace gap::sarif
void to_json(json &, const root &);
void from_json(const json &, root &);
} // namespace gap::sarif

#endif // GAP_ENABLE_SARIF
16 changes: 9 additions & 7 deletions test/sarif/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Copyright 2024, Trail of Bits, Inc. All rights reserved.

add_gap_test(test-gap-sarif
definitions.cpp
)
if (GAP_ENABLE_SARIF)
add_gap_test(test-gap-sarif
sarif.cpp
)

target_link_libraries(test-gap-sarif
PUBLIC
gap-sarif
)
target_link_libraries(test-gap-sarif
PUBLIC
gap-sarif
)
endif()
9 changes: 7 additions & 2 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
"name": "main",
"version-string": "latest",
"dependencies": [
"spdlog",
"nlohmann-json"
"spdlog"
],
"features": {
"with-doctest": {
"description": "Use doctest package",
"dependencies": [
"doctest"
]
},
"sarif": {
"description": "Enable SARIF support",
"dependencies": [
"nlohmann-json"
]
}
}
}

0 comments on commit a7ceecc

Please sign in to comment.