Skip to content

Commit

Permalink
add fix to get windows libfuzzers building (#35)
Browse files Browse the repository at this point in the history
* add fix to get windows libfuzzers building TODO: move away from throwing exceptions

* add a ci step that confirms libfuzzers get built and artifacted

* google/addlicense now checks for cmake file license. updated to account for that

* downgrade windows so that vs2022 isn't installed
  • Loading branch information
farzonl authored Apr 23, 2023
1 parent 9c01f8b commit 6218828
Show file tree
Hide file tree
Showing 18 changed files with 226 additions and 24 deletions.
140 changes: 140 additions & 0 deletions .github/workflows/cmake-libfuzzer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
name: CMake Libfuzzer Release

on:
push:
branches:
- master
paths:
- '**.cpp'
- '**.h'
- '**CMakeLists.txt'
- .github/workflows/cmake-libfuzzer.yml
pull_request:
branches:
- '**'
paths:
- '**.cpp'
- '**.h'
- '**CMakeLists.txt'
- .github/workflows/cmake-libfuzzer.yml
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
# Note using windows-2019 b\c of weird compile error when vs2022 is installed
# https://github.com/llvm/llvm-project/issues/56300
os: [ubuntu-latest, macos-latest, windows-2019]
include:
- os: windows-2019
artifact_exec_ext: .exe
artifact_os_name: Windows
artifact_arch: x86_64
steps:
- uses: actions/checkout@v2
- name: Install Dependencies (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt install build-essential cmake \
ca-certificates llvm clang libedit-dev ninja-build
- name: Install Dependencies (Mac)
if: matrix.os == 'macOS-latest'
run: |
brew install llvm ninja
- name: Install Dependencies (Windows)
if: matrix.os == 'windows-2019'
run: |
choco install llvm ninja
- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
run: cmake -E make_directory ${{github.workspace}}/build

- name: Cache C++ dependencies in Packages Directory
uses: actions/cache@v3
with:
path: |
packages
key: ${{ runner.OS }}-c++-packages-cache-libfuzzer-Release-${{ hashFiles('depsCache.json') }}
restore-keys: |
${{ runner.OS }}-c++-packages-cache-libfuzzer-Release-
- name: Configure CMake (Mac)
shell: bash
working-directory: ${{github.workspace}}/build
if: matrix.os == 'macOS-latest'
# Mac needs brew's llvm to override AppleClang
run: |
export PATH="/usr/local/opt/llvm/bin:$PATH"
cmake -G Ninja $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DBUILD_FUZZER=true
- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
shell: bash
working-directory: ${{github.workspace}}/build
if: matrix.os != 'macOS-latest'
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: |
cmake -G Ninja $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DBUILD_FUZZER=true
- name: Build
working-directory: ${{github.workspace}}/build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE
- name: Set variables (Mac\Linux)
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macOS-latest'
run: |
APP=$(cat $GITHUB_WORKSPACE/src/lib/Version/appName.txt)
VER=$(cat $GITHUB_WORKSPACE/src/lib/Version/version.txt)
echo "VERSION=$VER" >> $GITHUB_ENV
echo "APPNAME=$APP" >> $GITHUB_ENV
- name: Set variables (Windows)
if: matrix.os == 'windows-2019'
run: |
$APP = type .\src\lib\Version\appName.txt
$VER = type .\src\lib\Version\version.txt
echo "VERSION=$VER" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
echo "APPNAME=$APP" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Prepare Binaries for upload (Mac\Linux)
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macOS-latest'
shell: bash
run: |
mkdir ${{github.workspace}}/artifacts
cp build/fuzz/${{ env.APPNAME }}Lang_FUZZ ${{github.workspace}}/artifacts
pushd ${{github.workspace}}
zip -r ${{ env.APPNAME }}-$(uname -s)-libfuzzers-$(uname -m).zip artifacts
popd
- name: Prepare Binaries for upload (windows)
if: matrix.os == 'windows-latest'
shell: powershell
run: |
[system.io.directory]::CreateDirectory("${{github.workspace}}/artifacts")
Copy-Item "build/fuzz/${{ env.APPNAME }}Lang_FUZZ${{ matrix.artifact_exec_ext }}" -Destination "${{github.workspace}}/artifacts"
Compress-Archive -Path ${{github.workspace}}/artifacts/* -DestinationPath ${{ env.APPNAME }}-${{matrix.artifact_os_name}}-libfuzzers-${{matrix.artifact_arch}}.zip
- name: 'Upload Pull Request Artifact'
uses: actions/upload-artifact@v3
if: startsWith(github.ref, 'refs/pull/')
with:
name: ${{ env.APPNAME }} Pull Request Artifacts
path: ${{ env.APPNAME }}-*.zip
retention-days: 5
- name: Upload binaries to Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/heads/master')
with:
tag_name: ${{ env.APPNAME }}-${{ env.VERSION }}
files: |
${{ env.APPNAME }}-*.zip
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (c) 2023 F. Lotfi All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

cmake_minimum_required(VERSION 3.22)
project(WarfLang)

Expand All @@ -17,6 +21,14 @@ if(UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()

if(WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# See https://github.com/Kitware/CMake/blob/master/Modules/Platform/Windows-Clang.cmake#L86
#This will set:
# For Release: -fms-runtime-lib=static -Xclang -flto-visibility-public-std -Xclang --dependent-lib=libcmt
# For Debug: -fms-runtime-lib=static_dbg -Xclang -flto-visibility-public-std -Xclang --dependent-lib=libcmtd
set(CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()

if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
# Default debug flags are OK
Expand All @@ -38,6 +50,7 @@ if(CMAKE_CROSS_COMPILING)
set(WIN32 FALSE)
set(LINUX TRUE)
set(UNIX TRUE)

endif()
if(CMAKE_SYSTEM_NAME MATCHES MacOS)
set(WIN32 FALSE)
Expand Down
37 changes: 19 additions & 18 deletions fuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
# Copyright (c) 2023 F. Lotfi All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

project(${CMAKE_PROJECT_NAME}_FUZZ)

set(CMAKE_C_COMPILER:FILEPATH /usr/local/opt/llvm/bin/clang)
set(CMAKE_CXX_COMPILER:FILEPATH /usr/local/opt/llvm/bin/clang++)
include_directories(${CMAKE_SOURCE_DIR}/src/lib)

#/usr/local/opt/llvm/lib/clang/12.0.1/lib/darwin/libclang_rt.fuzzer_osx.a
#/usr/local/opt/llvm/lib/clang/12.0.1/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
add_executable(${PROJECT_NAME} fuzzTest.cpp)

#/usr/local/opt/llvm/lib/clang/13.0.1/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
#clang++ -g -fsanitize=address,fuzzer

#/usr/local/opt/llvm/lib/clang/14.0.6/lib/darwin/libclang_rt.fuzzer_osx.a
#/usr/local/opt/llvm/lib/clang/14.0.6/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address,fuzzer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,fuzzer")

include_directories(${CMAKE_SOURCE_DIR}/src/lib)
if(Win32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DEBUG /Od")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DEBUG /Od")
elseif(UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif()

add_executable(${PROJECT_NAME} fuzzTest.cpp)

#clang++ -g -fsanitize=address,fuzzer
target_compile_options(${PROJECT_NAME}
PRIVATE $<$<C_COMPILER_ID:Clang>:-g -O1 -lc++abi -fsanitize=address,fuzzer>
)

target_link_libraries(${PROJECT_NAME}
PRIVATE $<$<C_COMPILER_ID:Clang>:-fsanitize=address,fuzzer>
WarfCore
)
target_link_libraries(${PROJECT_NAME} PRIVATE
WarfCore
)
8 changes: 6 additions & 2 deletions fuzz/fuzzTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ extern "C" int LLVMFuzzerTestOneInput(const char *cLine, size_t len) {
return -1;
}
std::string sLine(cLine, len);
LexerFuzzTest(sLine);
ParserFuzzTest(sLine);
try {
LexerFuzzTest(sLine);
ParserFuzzTest(sLine);
} catch (...) {
return -1;
}
return 0;
}
2 changes: 1 addition & 1 deletion scripts/license-add.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
find src test fuzz \( -name \*.h -o -name \*.cpp \) -exec ~/go/bin/addlicense -c "F. Lotfi" -l bsd {} \;
find src test fuzz \( -name \*.h -o -name \*.cpp -o -name \*.cmake -o -name CMakeLists.txt \) -exec ~/go/bin/addlicense -c "F. Lotfi" -l bsd {} \;
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Copyright (c) 2023 F. Lotfi All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

add_subdirectory(lib)
add_subdirectory(cli)
4 changes: 4 additions & 0 deletions src/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (c) 2023 F. Lotfi All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

project(Warf)

set(SOURCE_FILES
Expand Down
4 changes: 4 additions & 0 deletions src/lib/Binding/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (c) 2023 F. Lotfi All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

include_directories(${WARF_CORE_SOURCE_DIR})

set(SourceFiles
Expand Down
4 changes: 4 additions & 0 deletions src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (c) 2023 F. Lotfi All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

project(WarfCore)

if(MSVC)
Expand Down
4 changes: 4 additions & 0 deletions src/lib/Error/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (c) 2023 F. Lotfi All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

include_directories(${WARF_CORE_SOURCE_DIR})

set(SourceFiles
Expand Down
4 changes: 4 additions & 0 deletions src/lib/Symbol/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (c) 2023 F. Lotfi All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

include_directories(${WARF_CORE_SOURCE_DIR})

set(SourceFiles
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Symbol/VariableSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.

#include "VariableSymbol.h"
//#include <functional>
// #include <functional>
#include "Scope.h"

VariableSymbol::VariableSymbol(const std::string &name, Type type)
Expand Down
4 changes: 4 additions & 0 deletions src/lib/Syntax/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (c) 2023 F. Lotfi All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

include_directories(${WARF_CORE_SOURCE_DIR})

set(SourceFiles Lexer.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Syntax/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// license that can be found in the LICENSE file.

#include <sstream>
//#include<algorithm> // for copy() and assign()
//#include<iterator> // for back_inserter
// #include<algorithm> // for copy() and assign()
// #include<iterator> // for back_inserter
#include "AssignmentExpressionNode.h"
#include "BinaryExpressionNode.h"
#include "IdentifierExpressionNode.h"
Expand Down
4 changes: 4 additions & 0 deletions src/lib/Version/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (c) 2023 F. Lotfi All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.



include ("CMakeListsVersion.cmake")
Expand Down
4 changes: 4 additions & 0 deletions src/lib/Version/CMakeListsVersion.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (c) 2023 F. Lotfi All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

# this file is intended to be included by other project CMakeLists.txt files
# in order to make the following Warf version variables available
# WARF_MAJOR : Integer major number (e.g. 0, 1, 2)
Expand Down
4 changes: 4 additions & 0 deletions src/lib/Version/generate_product_version.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (c) 2023 F. Lotfi All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

include (CMakeParseArguments)

set (GenerateProductVersionCurrentDir ${CMAKE_CURRENT_LIST_DIR})
Expand Down
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (c) 2023 F. Lotfi All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

project(${CMAKE_PROJECT_NAME}_TEST)

download_file(https://raw.githubusercontent.com/onqtam/doctest/2.4.6/doctest/doctest.h
Expand Down

0 comments on commit 6218828

Please sign in to comment.