Skip to content

Commit

Permalink
cc: Gate SARIF support behind feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
frabert committed Aug 26, 2024
1 parent 13f6c3f commit 1cd3fc5
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 21 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
image-version: [22.04]
build-type: [Release, Debug]
sanitizers: [ON, OFF]
features: ["nosarif", "sarif"]

runs-on: ubuntu-${{ matrix.image-version }}
timeout-minutes: 60
Expand All @@ -49,10 +50,10 @@ jobs:
fetch-depth: 1

- name: Configure build - sanitizers ${{ matrix.sanitizers }}
run: cmake --preset ci
run: cmake --preset ci-${{ matrix.features }}

- name: Build ${{ matrix.build-type }} with sanitizers set ${{ matrix.sanitizers }}
run: cmake --build --preset ci --config ${{ matrix.build-type }} -j $(nproc)
run: cmake --build --preset ci-${{ matrix.features }} --config ${{ matrix.build-type }} -j $(nproc)

- name: Test ${{ matrix.build-type }} with sanitizers set ${{ matrix.sanitizers }}
run: ctest --preset ci --build-config ${{ matrix.build-type }}
run: ctest --preset ci-${{ matrix.features }} --build-config ${{ matrix.build-type }}
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,18 @@ target_link_libraries(vast_settings
"$<BUILD_LOCAL_INTERFACE:gap::gap>"
)

option(VAST_ENABLE_SARIF "Enable SARIF export"
$<IN_LIST:sarif,VCPKG_MANIFEST_FEATURES>
)

if (VAST_ENABLE_SARIF)
target_link_libraries(vast_settings
INTERFACE
"$<BUILD_LOCAL_INTERFACE:gap::gap-sarif>"
)
target_compile_definitions(vast_settings INTERFACE VAST_ENABLE_SARIF)
endif()

#
# VAST libraries
#
Expand Down
30 changes: 26 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@
"CMAKE_VERBOSE_MAKEFILE": "True"
}
},
{
"name": "ci-nosarif",
"displayName": "Configure VAST for CI withour SARIF support",
"inherits": "ci"
},
{
"name": "ci-sarif",
"displayName": "Configure VAST for CI withour SARIF support",
"inherits": "ci",
"cacheVariables": {
"VCPKG_MANIFEST_FEATURES": "sarif"
}
},
{
"name": "compiler-explorer",
"displayName": "Configure VAST for Compiler Explorer",
Expand Down Expand Up @@ -85,8 +98,12 @@
"configuration": "RelWithDebInfo"
},
{
"name": "ci",
"configurePreset": "ci"
"name": "ci-nosarif",
"configurePreset": "ci-nosarif"
},
{
"name": "ci-sarif",
"configurePreset": "ci-sarif"
},
{
"name": "ci-release",
Expand Down Expand Up @@ -157,8 +174,13 @@
"configuration": "RelWithDebInfo"
},
{
"name": "ci",
"configurePreset": "ci",
"name": "ci-nosarif",
"configurePreset": "ci-nosarif",
"inherits": "test-base"
},
{
"name": "ci-sarif",
"configurePreset": "ci-sarif",
"inherits": "test-base"
}
],
Expand Down
1 change: 0 additions & 1 deletion lib/vast/Frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ add_vast_library(Frontend
Targets.cpp

LINK_LIBS PUBLIC
gap::gap-sarif
MLIRBytecodeWriter
VASTCodeGen
)
21 changes: 15 additions & 6 deletions lib/vast/Frontend/Consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ VAST_UNRELAX_WARNINGS

#include "vast/Config/config.h"

#include <gap/sarif/sarif.hpp>
#ifdef VAST_ENABLE_SARIF
#include <gap/sarif/sarif.hpp>
#endif // VAST_ENABLE_SARIF

namespace vast::cc {

Expand Down Expand Up @@ -164,6 +166,7 @@ namespace vast::cc {
);
}

#ifdef VAST_ENABLE_SARIF
static gap::sarif::physical_location get_physical_loc(mlir::FileLineColLoc loc) {
std::filesystem::path file_path{ loc.getFilename().str() };
auto abs_path = std::filesystem::absolute(file_path);
Expand All @@ -175,6 +178,7 @@ namespace vast::cc {
} },
};
}
#endif // VAST_ENABLE_SARIF

void vast_stream_consumer::process_mlir_module(target_dialect target, mlir::ModuleOp mod) {
// Handle source manager properly given that lifetime analysis
Expand All @@ -199,6 +203,7 @@ namespace vast::cc {
llvm::DebugFlag = true;
}

#ifdef VAST_ENABLE_SARIF
gap::sarif::run sarif_run{
.tool{
.driver{
Expand All @@ -214,6 +219,7 @@ namespace vast::cc {
.executionSuccessful = true,
}, },
};
#endif // VAST_ENABLE_SARIF

// Setup and execute vast pipeline
auto file_entry = src_mgr.getFileEntryRefForID(main_file_id);
Expand All @@ -225,9 +231,9 @@ namespace vast::cc {
setup_pipeline(pipeline_source::ast, target, mctx, vargs, snapshot_prefix);
VAST_CHECK(pipeline, "failed to setup pipeline");

mlir::ScopedDiagnosticHandler sarif_diag_handler{
&mctx,
[&](mlir::Diagnostic &diag) {
#ifdef VAST_ENABLE_SARIF
if (auto sarif_path = vargs.get_option(opt::output_sarif)) {
mctx.getDiagEngine().registerHandler([&](mlir::Diagnostic &diag) {
gap::sarif::result result{
.ruleId{ "mlir-diag" },
.message{ .text = diag.str() },
Expand Down Expand Up @@ -265,11 +271,13 @@ namespace vast::cc {
break;
}
sarif_run.results.push_back(result);
}
};
});
}
#endif // VAST_ENABLE_SARIF

auto result = pipeline->run(mod);

#ifdef VAST_ENABLE_SARIF
sarif_run.invocations[0].executionSuccessful = mlir::succeeded(result);

gap::sarif::root sarif_report{
Expand All @@ -282,6 +290,7 @@ namespace vast::cc {
nlohmann::json j = sarif_report;
os << j;
}
#endif // VAST_ENABLE_SARIF

VAST_CHECK(
mlir::succeeded(result), "MLIR pass manager failed when running vast passes"
Expand Down
4 changes: 2 additions & 2 deletions ports/gap/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO lifting-bits/gap
REF 107767b580fd8440a5bef5654c64174e6b5ecd95
SHA512 8b6b9a8e5fa5d740d3de40adf34ed678334a72b2bc83c698f6a22db75a131523b15c2d05b1946a898eb755e8f2c1359d706e17da1235d1bc5a0d0465f6da7347
REF a7ceecc118410f11b0c904b88a5ccfd6221f434b
SHA512 20b72abb4a5c6bb97a218ea0c9492c1e70ba158c4a351656fec29141ed15dd17cdbececa0b31ebb7d4d44af6db69be4c4d40ef9ebd19dd8ac3a085e2e5ca15a4
HEAD_REF main
)

Expand Down
18 changes: 13 additions & 5 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"dependencies": [
{
"name": "gap",
"features": [
"sarif"
"features": {
"sarif": {
"description": "Enables SARIF output support",
"dependencies": [
{
"name": "gap",
"features": [
"sarif"
]
}
]
}
},
"dependencies": [
"gap"
]
}

0 comments on commit 1cd3fc5

Please sign in to comment.