Skip to content

Commit

Permalink
GitHub Actions testing on Ubuntu, Mac, & Windows
Browse files Browse the repository at this point in the history
Updates to fix issues in the CMake install instructions.

Updates the README.md to indicate that CMake is now preferred

Adds a GitHub Actions badge, Discord badge, and logo to the README.md.

CMake:

- Renamed ENABLE_DOCS to ENABLE_MAN_PAGES.

- Fixed build issue when milter isn't enabled on Linux. Changed the
default to build milter on non-macOS, non-Windows operating systems.

- Fix LD_LIBRARY_PATH for tests including on macOS where LD_LIBRARY_PATH
  and DYLD_LIBRARY_PATH must be manually propagated to subprocesses.

- Use UNKNOWN IMPORTED library instead of INTERFACE IMPORTED library for
  pdcurses, but still use INTERFACE IMPORTED for ncurses.
  UNKNOWN IMPORTED appears to be required so that we can use
  $<TARGET_FILE_DIR:Curses::curses> to collected the pdcurses library at
  install time on Windows.

- When building with vcpkg on Windows, CMake will automatically install
  your app local dependencies (aka the DLL runtime dependencies).
  Meanwhile, file(GET_RUNTIME_DEPENDENCIES ...) doesn't appear to work
  correctly with vcpkg packages. The solution is to use a custom target
  that has CMake perform a local install to the unit_tests directory
  when using vcpkg.
  This is in fact far easier than using GET_RUNTIME_DEPENDENCIES in the
  unit_tests for assembling the test environment but we can't use this
  method for the non-vcpkg install because it won't collect
  checkDynamic.dll for us because we don't install our tests.
  We also can't link with the static check.lib because the static
  check.lib has pthreads symbols linked in and will conflict with our
  pthread.dll.

  TL;DR: We'll continue to use file(GET_RUNTIME_DEPENDENCIES ...) for
  assembling the test enviornment on non-vcpkg builds, and use the local
  install method for vcpkg builds.

testcase.py: Wrapped a Pathlib.unlink() call in exception handling as
the missing_ok optional parameter requires a Python version too new for
common use.

Remove localtime_r from win32 compat lib.
localtime_r may be present in libcheck when building with vcpkg and
while making it a static function would also solve the issue, using
localtime_s instead like we do everywhere else should work just fine.

check_clamd: Limited the max # of connections for the stress test on Mac
to 850, to address issues found testing on macos-latest on GitHub Actions.
  • Loading branch information
micahsnyder committed Feb 25, 2021
1 parent 034cc77 commit c81968d
Show file tree
Hide file tree
Showing 13 changed files with 805 additions and 458 deletions.
173 changes: 173 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
name: CMake Build

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches:
- rel/*
- dev/*
- main
pull_request:
branches:
- rel/*
- dev/*
- main

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
VCPKG_GIT_REF: 8a9a97315aefb3f8bc5d81bf66ca0025938b9c91

jobs:
build-windows:
runs-on: windows-latest

steps:
- uses: actions/checkout@v1

- name: Install Build Tools
uses: crazy-max/ghaction-chocolatey@v1
with:
args: install wixtoolset

- uses: lukka/get-cmake@latest

# Restore from cache the previously built ports. If cache-miss, download, build vcpkg ports.
- name: Restore vcpkg ports from cache or install vcpkg
# Download and build vcpkg, without installing any port. If content is cached already, it is a no-op.
uses: lukka/run-vcpkg@v5
id: runvcpkg
with:
vcpkgArguments: "curl[openssl] json-c libxml2 pcre2 check pthreads zlib pdcurses bzip2"
vcpkgGitCommitId: "${{ env.VCPKG_GIT_REF }}"
vcpkgTriplet: "x64-windows"

- name: Print the VCPKG_ROOT & VCPKG_TRIPLET (for debugging)
shell: bash
run: echo "'${{ steps.runvcpkg.outputs.RUNVCPKG_VCPKG_ROOT_OUT }}' '${{ steps.runvcpkg.outputs.RUNVCPKG_VCPKG_TRIPLET_OUT }}' "

- name: dir the VCPKG_ROOT
run: dir ${{ steps.runvcpkg.outputs.RUNVCPKG_VCPKG_ROOT_OUT }}

- name: Create Build Directory
shell: bash
# 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 ${{runner.workspace}}/build

- name: Run CMake+Ninja with triplet (cmd)
uses: lukka/run-cmake@main
id: runcmake_cmd
with:
cmakeGenerator: "Ninja" # Visual Studio 15 2017
cmakeListsOrSettingsJson: "CMakeListsTxtBasic"
cmakeListsTxtPath: "${{runner.workspace}}/clamav-devel/CMakeLists.txt"
useVcpkgToolchainFile: true
cmakeAppendedArgs: '-A x64 -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DENABLE_EXAMPLES=ON -DENABLE_STATIC_LIB=ON -- -v'
cmakeBuildType: "${{ env.BUILD_TYPE }}"
vcpkgTriplet: ${{ steps.runvcpkg.outputs.RUNVCPKG_VCPKG_TRIPLET_OUT }}
buildDirectory: "${{runner.workspace}}/build"

- name: Test
working-directory: ${{runner.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{ env.BUILD_TYPE }} -V

- name: Create Installer
working-directory: ${{runner.workspace}}/build
run: cpack -C ${{ env.BUILD_TYPE }}

build-macos:
runs-on: macos-latest

steps:
- uses: actions/checkout@v1

- name: Install Build Tools
run: brew install bison flex

- name: Install Dependencies
run: brew install bzip2 check curl-openssl json-c libxml2 ncurses [email protected] pcre2 zlib

- uses: lukka/get-cmake@latest

- name: Create Build Directory
shell: bash
# 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 ${{runner.workspace}}/build

- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
working-directory: ${{runner.workspace}}/build
# 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 ${{runner.workspace}}/clamav-devel -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}
-DOPENSSL_ROOT_DIR=/usr/local/opt/[email protected]/
-DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/[email protected]/lib/libcrypto.1.1.dylib
-DOPENSSL_SSL_LIBRARY=/usr/local/opt/[email protected]/lib/libssl.1.1.dylib
-DENABLE_STATIC_LIB=ON
-DENABLE_EXAMPLES=ON

- name: Build
shell: bash
working-directory: ${{runner.workspace}}/build
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config ${{ env.BUILD_TYPE }}

- name: Test
shell: bash
working-directory: ${{runner.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{ env.BUILD_TYPE }} -V

build-ubuntu:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Install Build Tools
run: sudo apt-get install -y bison flex valgrind

- name: Install Dependencies
run: sudo apt-get install -y check libbz2-dev libcurl4-openssl-dev libjson-c-dev libmilter-dev libncurses5-dev libpcre3-dev libssl-dev libxml2-dev zlib1g-dev

- uses: lukka/get-cmake@latest

- name: Create Build Directory
shell: bash
# 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 ${{runner.workspace}}/build

- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
working-directory: ${{runner.workspace}}/build
# 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 ${{runner.workspace}}/clamav-devel -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}
-DENABLE_STATIC_LIB=ON
-DENABLE_EXAMPLES=ON

- name: Build
shell: bash
working-directory: ${{runner.workspace}}/build
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config ${{ env.BUILD_TYPE }}

- name: Test
shell: bash
working-directory: ${{runner.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{ env.BUILD_TYPE }} -V
81 changes: 46 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ math(EXPR LIBFRESHCLAM_SOVERSION "${LIBFRESHCLAM_CURRENT} - ${LIBFRESHCLAM_AGE}"
set(LIBFRESHCLAM_VERSION "${LIBFRESHCLAM_SOVERSION}.${LIBFRESHCLAM_AGE}.${LIBFRESHCLAM_REVISION}")
HexVersion(LIBFRESHCLAM_VERSION_NUM ${LIBFRESHCLAM_CURRENT} ${LIBFRESHCLAM_REVISION} ${LIBFRESHCLAM_AGE})

#
# Define C_LINUX because CMake only defines UNIX
#
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(C_LINUX 1)
endif()

# Git optionally used to add commit info into build to differentiate in bug reports.
find_package(Git)
if(Git_FOUND)
Expand Down Expand Up @@ -79,19 +86,27 @@ endif()
#

# CMake Option default values:
set(ENABLE_APP_DEFAULT ON)
set(ENABLE_MILTER_DEFAULT OFF)
set(ENABLE_CLAMONACC_DEFAULT ON)
set(ENABLE_EXAMPLES_DEFAULT OFF)
set(ENABLE_TESTS_DEFAULT ON)
set(ENABLE_APP_DEFAULT ON)
if(WIN32 OR APPLE)
set(ENABLE_MILTER_DEFAULT OFF)
else()
set(ENABLE_MILTER_DEFAULT ON)
endif()
if(C_LINUX)
set(ENABLE_CLAMONACC_DEFAULT ON)
else()
set(ENABLE_CLAMONACC_DEFAULT OFF)
endif()
set(ENABLE_EXAMPLES_DEFAULT OFF)
set(ENABLE_TESTS_DEFAULT ON)
if(WIN32)
set(ENABLE_DOCS_DEFAULT OFF)
set(ENABLE_MAN_PAGES_DEFAULT OFF)
else()
set(ENABLE_DOCS_DEFAULT ON)
set(ENABLE_MAN_PAGES_DEFAULT ON)
endif()
set(ENABLE_DOXYGEN_DEFAULT OFF)
set(ENABLE_UNRAR_DEFAULT ON)
set(ENABLE_SYSTEMD_DEFAULT ON)
set(ENABLE_DOXYGEN_DEFAULT OFF)
set(ENABLE_UNRAR_DEFAULT ON)
set(ENABLE_SYSTEMD_DEFAULT ON)

# See CMakeOptions.cmake for additional options.
include(CMakeOptions.cmake)
Expand Down Expand Up @@ -127,8 +142,8 @@ else()
set(ENABLE_LIB_ONLY_DISABLED_OTHERS 0)
endif()
if(ENABLE_LIBCLAMAV_ONLY)
set(ENABLE_APP OFF)
set(ENABLE_EXAMPLES OFF)
set(ENABLE_APP OFF)
set(ENABLE_EXAMPLES OFF)
endif()

#
Expand All @@ -139,26 +154,14 @@ if(APPLE)
endif()
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

#
# Define C_LINUX because CMake only defines UNIX
#
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(C_LINUX 1)

if(C_LINUX)
if(CMAKE_COMPILER_IS_GNUCXX)
# For O_LARGEFILE, O_CLOEXEC, O_DIRECTORY, O_NOFOLLOW, etc flags on older systems
# Set _GNU_SOURCE for O_LARGEFILE, O_CLOEXEC, O_DIRECTORY, O_NOFOLLOW, etc flags on older systems
# (pre POSIX.1-2008: glibc 2.11 and earlier). #4042
set(_GNU_SOURCE 1)
endif()
endif()

#
# Set FreeBSD include path to include /usr/local/include
#
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
include_directories(/usr/local/include)
endif()

#
# Use the `lib` prefix on Windows, to match previous ClamAV build
#
Expand Down Expand Up @@ -733,7 +736,7 @@ endif()
add_subdirectory( libclamunrar_iface )

if(NOT ENABLE_EXTERNAL_MSPACK)
add_subdirectory(libclammspack)
add_subdirectory( libclammspack )
else()
find_package(MSPack)
endif()
Expand Down Expand Up @@ -761,7 +764,7 @@ if(NOT ENABLE_LIBCLAMAV_ONLY)
add_subdirectory( clamonacc )
endif()

if(NOT WIN32 AND ENABLE_MILTER)
if(ENABLE_MILTER)
add_subdirectory( clamav-milter )
endif()

Expand Down Expand Up @@ -792,13 +795,11 @@ endif()
include(CTest)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
if(ENABLE_TESTS)
add_subdirectory(test)
add_subdirectory(unit_tests)
add_subdirectory( test )
add_subdirectory( unit_tests )
endif()

if(ENABLE_DOCS)
add_subdirectory( docs )
endif()
add_subdirectory( docs )

if(ENABLE_FUZZ)
add_subdirectory( fuzz )
Expand All @@ -814,22 +815,32 @@ ${c} Package Version: ${e}${PACKAGE_STRING}
${c} libclamav version: ${e}${LIBCLAMAV_CURRENT}:${LIBCLAMAV_REVISION}:${LIBCLAMAV_AGE}
${c} libfreshclam version: ${e}${LIBFRESHCLAM_CURRENT}:${LIBFRESHCLAM_REVISION}:${LIBFRESHCLAM_AGE}
${c} Install prefix: ${e}${CMAKE_INSTALL_PREFIX}
${c} Host system: ${e}${CMAKE_HOST_SYSTEM}
${c} Target system: ${e}${CMAKE_SYSTEM}
${c} Compiler: ${e}
${b} Build type: ${e}${CMAKE_BUILD_TYPE}
${b} C compiler: ${e}${CMAKE_C_COMPILER}
${b} C++ compiler: ${e}${CMAKE_CXX_COMPILER}
${b} CFLAGS: ${e}${CMAKE_C_FLAGS_${_build_type}} ${CMAKE_C_FLAGS}
${b} CXXFLAGS: ${e}${CMAKE_CXX_FLAGS_${_build_type}} ${CMAKE_CXX_FLAGS}
${b} WARNCFLAGS: ${e}${WARNCFLAGS}
${b} WARNCFLAGS: ${e}${WARNCFLAGS}")
if(VCPKG_TOOLCHAIN)
message("\
${c} Using vcpkg: ${e}
${b} Target Triplet: ${e}${VCPKG_TARGET_TRIPLET}
${b} Target Arch: ${e}${VCPKG_TARGET_ARCHITECTURE}
${b} Get runtime DLLs: ${e}${VCPKG_APPLOCAL_DEPS}
${b} Package root path: ${e}${VCPKG_CMAKE_FIND_ROOT_PATH}")
endif()
message("\
${c} Build Options: ${e}
${b} Build apps: ${e}${ENABLE_APP}
${b} Shared library: ${e}${ENABLE_SHARED_LIB}
${b} Static library: ${e}${ENABLE_STATIC_LIB}
${b} Enable UnRAR: ${e}${ENABLE_UNRAR}
${b} Examples: ${e}${ENABLE_EXAMPLES}
${b} Tests: ${e}${ENABLE_TESTS}
${b} Build man pages: ${e}${ENABLE_DOCS}
${b} Build man pages: ${e}${ENABLE_MAN_PAGES}
${b} Build doxygen HTML: ${e}${ENABLE_DOXYGEN}")
if(NOT WIN32)
message("\
Expand Down
8 changes: 4 additions & 4 deletions CMakeOptions.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Features that can be enabled for cmake (see CMakeLists.txt)

if (WIN32)
if(WIN32)
set(APP_CONFIG_DIRECTORY
"." CACHE STRING
"App Config directory.")
Expand Down Expand Up @@ -77,9 +77,9 @@ option(ENABLE_CLAMONACC
"Build clamonacc (Linux-only, requires ENABLE_APP))."
${ENABLE_CLAMONACC_DEFAULT})

option(ENABLE_DOCS
"Generate documentation."
${ENABLE_DOCS_DEFAULT})
option(ENABLE_MAN_PAGES
"Generate man pages."
${ENABLE_MAN_PAGES_DEFAULT})

option(ENABLE_DOXYGEN
"Generate doxygen HTML documentation for clamav.h, libfreshclam.h."
Expand Down
Loading

0 comments on commit c81968d

Please sign in to comment.