Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Address Sanitization to CI build #223

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/linux-cmake-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ jobs:
linux-build:
name: Build and run tests on Linux using CMake
runs-on: ubuntu-latest
strategy:
matrix:
asan: ["ON", "OFF"]

steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -25,7 +29,7 @@ jobs:
run: |
mkdir build
cd build
cmake .. -DSPIRV_REFLECT_BUILD_TESTS=ON
cmake .. -DCMAKE_BUILD_TYPE=Release -DSPIRV_REFLECT_BUILD_TESTS=ON -DSPIRV_REFLECT_ENABLE_ASAN=${{matrix.asan}}
make -j $(nproc)
- name: Run unit tests
run: |
Expand Down
239 changes: 123 additions & 116 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,116 +1,123 @@
cmake_minimum_required(VERSION 3.1)

project(spirv-reflect)

OPTION(SPIRV_REFLECT_EXECUTABLE "Build spirv-reflect executable" ON)
OPTION(SPIRV_REFLECT_EXAMPLES "Build stripper examples" ON)
OPTION(SPIRV_REFLECT_STRIPPER "Build stripper utility" OFF)
OPTION(SPIRV_REFLECT_STATIC_LIB "Build a SPIRV-Reflect static library" OFF)
OPTION(SPIRV_REFLECT_BUILD_TESTS "Build the SPIRV-Reflect test suite" OFF)
OPTION(SPIRV_REFLECT_ENABLE_ASSERTS "Enable asserts for debugging" OFF)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 14)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")

if (SPIRV_REFLECT_EXECUTABLE)
# ==========================================================================
# Compile spirv_reflect.c as C
# ==========================================================================
add_executable(spirv-reflect ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.h
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.c
${CMAKE_CURRENT_SOURCE_DIR}/examples/arg_parser.h
${CMAKE_CURRENT_SOURCE_DIR}/examples/arg_parser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/examples/common.h
${CMAKE_CURRENT_SOURCE_DIR}/examples/common.cpp
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.h
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.cpp)
target_compile_options(spirv-reflect PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<CXX_COMPILER_ID:GNU>:-Wall -Werror>
$<$<CXX_COMPILER_ID:Clang>:-Wall -Werror>
$<$<CXX_COMPILER_ID:AppleClang>:-Wall -Werror>)
if (SPIRV_REFLECT_ENABLE_ASSERTS)
target_compile_definitions(spirv-reflect PRIVATE SPIRV_REFLECT_ENABLE_ASSERTS)
endif()
set_target_properties(spirv-reflect PROPERTIES CXX_STANDARD 11)
target_include_directories(spirv-reflect PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if(WIN32)
target_compile_definitions(spirv-reflect PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()

install(TARGETS spirv-reflect RUNTIME DESTINATION bin)

# ==========================================================================
# Compile spirv_reflect.c as C++
# ==========================================================================
add_executable(spirv-reflect-pp ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.h
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.cpp
${CMAKE_CURRENT_SOURCE_DIR}/examples/arg_parser.h
${CMAKE_CURRENT_SOURCE_DIR}/examples/arg_parser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/examples/common.h
${CMAKE_CURRENT_SOURCE_DIR}/examples/common.cpp
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.h
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.cpp)
target_compile_options(spirv-reflect-pp PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<CXX_COMPILER_ID:GNU>:-Wall -Werror>
$<$<CXX_COMPILER_ID:Clang>:-Wall -Werror>
$<$<CXX_COMPILER_ID:AppleClang>:-Wall -Werror>)
if (SPIRV_REFLECT_ENABLE_ASSERTS)
target_compile_definitions(spirv-reflect-pp PRIVATE SPIRV_REFLECT_ENABLE_ASSERTS)
endif()
set_target_properties(spirv-reflect-pp PROPERTIES CXX_STANDARD 11)
target_include_directories(spirv-reflect-pp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if(WIN32)
target_compile_definitions(spirv-reflect-pp PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()

install(TARGETS spirv-reflect-pp RUNTIME DESTINATION bin)
endif()

if (SPIRV_REFLECT_EXAMPLES)
add_subdirectory(examples)
endif()

if (SPIRV_REFLECT_STRIPPER)
add_subdirectory(util/stripper)
endif()

if (SPIRV_REFLECT_BUILD_TESTS)
message("Tests are enabled!")
SET(BUILD_GMOCK OFF CACHE BOOL "Builds the googlemock subproject" FORCE)
SET(BUILD_GTEST ON CACHE BOOL "Builds the googletest subproject" FORCE)
SET(INSTALL_GTEST OFF CACHE BOOL "Enable installation of googletest. (Projects embedding googletest generally turn this OFF.)" FORCE)
SET(gtest_force_shared_crt ON CACHE BOOL "Enable DLL for C runtime libraries on Windows" FORCE)

add_subdirectory(third_party/googletest)
add_executable(test-spirv-reflect ${CMAKE_CURRENT_SOURCE_DIR}/tests/test-spirv-reflect.cpp
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.h
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.c
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.h
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.cpp)
set_target_properties(test-spirv-reflect PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
CXX_STANDARD 11)
target_compile_definitions(test-spirv-reflect PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS>)
target_link_libraries(test-spirv-reflect gtest_main)
target_include_directories(test-spirv-reflect PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_command(TARGET test-spirv-reflect POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/tests ${CMAKE_CURRENT_BINARY_DIR}/tests)
endif()

if(SPIRV_REFLECT_STATIC_LIB)
add_library(spirv-reflect-static STATIC ${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.h
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.c)

target_include_directories(spirv-reflect-static
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
install(TARGETS spirv-reflect-static LIBRARY DESTINATION lib)
endif()

cmake_minimum_required(VERSION 3.1)

project(spirv-reflect)

OPTION(SPIRV_REFLECT_EXECUTABLE "Build spirv-reflect executable" ON)
OPTION(SPIRV_REFLECT_EXAMPLES "Build stripper examples" ON)
OPTION(SPIRV_REFLECT_STRIPPER "Build stripper utility" OFF)
OPTION(SPIRV_REFLECT_STATIC_LIB "Build a SPIRV-Reflect static library" OFF)
OPTION(SPIRV_REFLECT_BUILD_TESTS "Build the SPIRV-Reflect test suite" OFF)
OPTION(SPIRV_REFLECT_ENABLE_ASSERTS "Enable asserts for debugging" OFF)
OPTION(SPIRV_REFLECT_ENABLE_ASAN "Use address sanitization" OFF)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 14)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")

if (SPIRV_REFLECT_ENABLE_ASAN)
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
add_link_options(-fsanitize=address)
endif()

if (SPIRV_REFLECT_EXECUTABLE)
# ==========================================================================
# Compile spirv_reflect.c as C
# ==========================================================================
add_executable(spirv-reflect ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.h
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.c
${CMAKE_CURRENT_SOURCE_DIR}/examples/arg_parser.h
${CMAKE_CURRENT_SOURCE_DIR}/examples/arg_parser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/examples/common.h
${CMAKE_CURRENT_SOURCE_DIR}/examples/common.cpp
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.h
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.cpp)
target_compile_options(spirv-reflect PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<CXX_COMPILER_ID:GNU>:-Wall -Werror>
$<$<CXX_COMPILER_ID:Clang>:-Wall -Werror>
$<$<CXX_COMPILER_ID:AppleClang>:-Wall -Werror>)
if (SPIRV_REFLECT_ENABLE_ASSERTS)
target_compile_definitions(spirv-reflect PRIVATE SPIRV_REFLECT_ENABLE_ASSERTS)
endif()

set_target_properties(spirv-reflect PROPERTIES CXX_STANDARD 11)
target_include_directories(spirv-reflect PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if(WIN32)
target_compile_definitions(spirv-reflect PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()

install(TARGETS spirv-reflect RUNTIME DESTINATION bin)

# ==========================================================================
# Compile spirv_reflect.c as C++
# ==========================================================================
add_executable(spirv-reflect-pp ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.h
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.cpp
${CMAKE_CURRENT_SOURCE_DIR}/examples/arg_parser.h
${CMAKE_CURRENT_SOURCE_DIR}/examples/arg_parser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/examples/common.h
${CMAKE_CURRENT_SOURCE_DIR}/examples/common.cpp
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.h
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.cpp)
target_compile_options(spirv-reflect-pp PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<CXX_COMPILER_ID:GNU>:-Wall -Werror>
$<$<CXX_COMPILER_ID:Clang>:-Wall -Werror>
$<$<CXX_COMPILER_ID:AppleClang>:-Wall -Werror>)
if (SPIRV_REFLECT_ENABLE_ASSERTS)
target_compile_definitions(spirv-reflect-pp PRIVATE SPIRV_REFLECT_ENABLE_ASSERTS)
endif()
set_target_properties(spirv-reflect-pp PROPERTIES CXX_STANDARD 11)
target_include_directories(spirv-reflect-pp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if(WIN32)
target_compile_definitions(spirv-reflect-pp PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()

install(TARGETS spirv-reflect-pp RUNTIME DESTINATION bin)
endif()

if (SPIRV_REFLECT_EXAMPLES)
add_subdirectory(examples)
endif()

if (SPIRV_REFLECT_STRIPPER)
add_subdirectory(util/stripper)
endif()

if (SPIRV_REFLECT_BUILD_TESTS)
message("Tests are enabled!")
SET(BUILD_GMOCK OFF CACHE BOOL "Builds the googlemock subproject" FORCE)
SET(BUILD_GTEST ON CACHE BOOL "Builds the googletest subproject" FORCE)
SET(INSTALL_GTEST OFF CACHE BOOL "Enable installation of googletest. (Projects embedding googletest generally turn this OFF.)" FORCE)
SET(gtest_force_shared_crt ON CACHE BOOL "Enable DLL for C runtime libraries on Windows" FORCE)

add_subdirectory(third_party/googletest)
add_executable(test-spirv-reflect ${CMAKE_CURRENT_SOURCE_DIR}/tests/test-spirv-reflect.cpp
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.h
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.c
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.h
${CMAKE_CURRENT_SOURCE_DIR}/common/output_stream.cpp)
set_target_properties(test-spirv-reflect PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
CXX_STANDARD 11)
target_compile_definitions(test-spirv-reflect PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS>)
target_link_libraries(test-spirv-reflect gtest_main)
target_include_directories(test-spirv-reflect PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_command(TARGET test-spirv-reflect POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/tests ${CMAKE_CURRENT_BINARY_DIR}/tests)
endif()

if(SPIRV_REFLECT_STATIC_LIB)
add_library(spirv-reflect-static STATIC ${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.h
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.c)

target_include_directories(spirv-reflect-static
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
install(TARGETS spirv-reflect-static LIBRARY DESTINATION lib)
endif()