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 cmake build system #1049

Merged
merged 8 commits into from
Sep 7, 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
7 changes: 7 additions & 0 deletions .configure-custom.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
trws marked this conversation as resolved.
Show resolved Hide resolved

ENABLE_VARS="code-coverage|On|ENABLE_COVERAGE docs|On|ENABLE_DOCS"
DISABLE_VARS="docs|Off|ENABLE_DOCS"
ENABLE_ENABLE_COVERAGE_DOC="enable coverage analysis"
ENABLE_ENABLE_DOCS_DOC="enable building manpages"
ENABLE_DISABLE_DOCS_DOC="disable building manpages"
49 changes: 41 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
on: [ pull_request, push, workflow_dispatch ]
on: [ pull_request, push, workflow_dispatch, merge_group]
name: ci
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
check-pr:
name: validate commits
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
Expand Down Expand Up @@ -86,7 +89,7 @@ jobs:
fail-fast: false
name: ${{matrix.name}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
Expand All @@ -97,10 +100,11 @@ jobs:
github.ref != 'refs/heads/master'
run: |
# Ensure git-describe works on a tag.
# (checkout@v2 action may have left current tag as
# (checkout@v3 action may have left current tag as
# lightweight instead of annotated. See
# https://github.com/actions/checkout/issues/290)
#
echo github.ref == ${{ github.ref }} ;
git fetch -f origin ${{ github.ref }}:${{ github.ref }} ;
echo git describe now reports $(git describe --always)

Expand All @@ -114,14 +118,25 @@ jobs:
pip3 install --upgrade pip ;
pip3 install --upgrade --force-reinstall coverage ;


- name: docker buildx
uses: docker/setup-buildx-action@v2
if: matrix.needs_buildx

- uses: dbhi/qus/action@main
with:
targets: aarch64

- name: docker-run-checks
env: ${{matrix.env}}
run: ${{matrix.command}}

- name: annotate errors
if: failure() || cancelled()
env: ${{matrix.env}}
run: src/test/checks-annotate.sh
- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
with:
name: ${{matrix.name}}-results.xml
path: test-results.xml

- name: coverage report
if: success() && matrix.coverage
Expand Down Expand Up @@ -150,6 +165,24 @@ jobs:
prerelease: true
body: |
View [Release Notes](https://github.com/${{ github.repository }}/blob/${{ matrix.tag }}/NEWS.md) for flux-sched ${{ matrix.tag }}
generate-manifest:
name: Generate docker manifest
runs-on: ubuntu-latest
needs: [ci-checks]
env:
DOCKER_REPO: fluxrm/flux-core
DOCKER_USERNAME: travisflux
DOCKER_PASSWORD: ${{ secrets.DOCKER_HUB_TRAVISFLUX_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: make and push manifest as fluxrm/flux-core
if: >
(startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master')
run: |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
# maybe bring back later: fluxrm/flux-core:bookworm-386
docker manifest create fluxrm/flux-core:bookworm fluxrm/flux-core:bookworm-amd64 fluxrm/flux-core:bookworm-arm64
docker manifest push fluxrm/flux-core:bookworm

- name: upload tarball
id: upload-tarball
Expand Down
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,33 @@ libtool
.libs/
libltdl/

# cmake and ninja
*.counts
.ninja_deps
.ninja_log
.cmake/
/*build*
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps

# directory management
.direnv

# MacOS
.DS_Store

# vim local
.vim

# generated library version header
/src/common/libflux/version.h

Expand Down
212 changes: 212 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
cmake_minimum_required(VERSION 3.14)
trws marked this conversation as resolved.
Show resolved Hide resolved
set(VER_FILE ${CMAKE_BINARY_DIR}/flux-sched.ver)
if(DEFINED FLUX_SCHED_VER)
# do nothing, user said so
elseif(DEFINED ENV{FLUX_SCHED_VERSION})
set(FLUX_SCHED_VER "$ENV{FLUX_SCHED_VERSION}")
elseif(EXISTS ${VER_FILE})
file(READ ${VER_FILE} FLUX_SCHED_VER)
string(STRIP ${FLUX_SCHED_VER} FLUX_SCHED_VER)
else()
execute_process(COMMAND sh -c [=[git describe --always | awk '/.*/ {sub(/^v/, ""); printf "%s",$1; exit}']=] OUTPUT_VARIABLE FLUX_SCHED_VER)
endif()
message(STATUS "VER ${FLUX_SCHED_VER}")
string(REGEX REPLACE "-.*$" "" FLUX_SCHED_VER_NOGIT "${FLUX_SCHED_VER}")
project(flux-sched VERSION ${FLUX_SCHED_VER_NOGIT} LANGUAGES CXX C)
trws marked this conversation as resolved.
Show resolved Hide resolved
message(STATUS "Building flux-sched version ${FLUX_SCHED_VER}")

if(POLICY CMP0140)
cmake_policy(SET CMP0140 NEW)
endif()

set(CMAKE_CXX_STANDARD 14 CACHE STRING "The C++ standard to use")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# The lines below will generate the config.h based on the options above
# The file will be in the ${CMAKE_BINARY_DIR} location
set(CONFIG_H ${CMAKE_BINARY_DIR}/config.h)
string(TIMESTAMP CURRENT_TIMESTAMP)
file(WRITE ${CONFIG_H} "/* WARNING: This file is auto-generated by CMake on ${CURRENT_TIMESTAMP}. DO NOT EDIT!!! */\n\n")

## !!! WARNING These are the defines that were defined regardless of an option.
## !!! Or the script couldn't match them. Match them accordingly, delete them or keep them
file(APPEND ${CONFIG_H} "/* Define _GNU_SOURCE so that we get all necessary prototypes */\n")
file(APPEND ${CONFIG_H} "#define _GNU_SOURCE 1 \n\n ")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: wrap the commit body at 72 or 80 characters (can't remember which is preferred for git).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments are ending up on lines of code rather than on commits, not sure if there's anything to do about that but it would be good to find a way to make the link to the commit more obvious.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has always been annoying that there's no way to comment on a commit message itself. However, going through the commits in the "Commits" tab will only show the comments pertaining to that commit (though it still appears attached to a line of code)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I keep hoping we can do something better for that. Tools like stacked git, jujutsu, and even facebook's sapling with their experimental example stacked PR UI for github look promising, but nothing first party. 😢

Short of going as far as reviewing with a third-party UI or switching to gerritt it feels like we're a bit stuck.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the UI I was referring to from facebook: https://reviewstack.dev/ it also works with ghstack, if only

include( GNUInstallDirs ) # convenience names for gnu-style directories
# RPATH setup
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
set( CMAKE_BUILD_RPATH
${CMAKE_BINARY_DIR}/resource:${CMAKE_BINARY_DIR}/src/common/libtap )
# the RPATH to be used when installing, but only if it's not a system directory
trws marked this conversation as resolved.
Show resolved Hide resolved
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")


# Setting the include directory for the application to find config.h
include_directories( ${CMAKE_BINARY_DIR} )
# Since we have created a config.h add a global define for it
add_definitions( "-DHAVE_CONFIG_H" )
add_definitions( "-DPACKAGE_VERSION=\"${FLUX_SCHED_VER}\"" )

# We build a lot of shared libs, build them all with PIC
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# variable to store paths to add to module path for tests

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX})

# external dependencies
find_package(PkgConfig REQUIRED)
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
find_package(FluxCore REQUIRED)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
message(STATUS "flux core found and no specific prefix specified, using ${FLUX_CORE_PREFIX}")
trws marked this conversation as resolved.
Show resolved Hide resolved
set(CMAKE_INSTALL_PREFIX ${FLUX_CORE_PREFIX} CACHE PATH "..." FORCE)
endif()
if(DEFINED ENV{PYTHON})
set(Python_EXECUTABLE $ENV{PYTHON} CACHE FILEPATH "")
endif()
find_package(Python 3.6...<4.0 COMPONENTS Interpreter Development REQUIRED) # 3.6 or higher
execute_process(
COMMAND "${Python_EXECUTABLE}" -c "import sysconfig as sc; print(sc.get_path('purelib', vars={'base':'${CMAKE_INSTALL_PREFIX}'}))"
OUTPUT_VARIABLE PYTHON_INSTALL_SITELIB
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND "${Python_EXECUTABLE}" -c "import sysconfig as sc; print(sc.get_path('platlib', vars={'platbase':'${CMAKE_INSTALL_PREFIX}'}))"
OUTPUT_VARIABLE PYTHON_INSTALL_SITEARCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
pkg_check_modules(yaml-cpp REQUIRED IMPORTED_TARGET yaml-cpp)
pkg_check_modules(LIBEDIT REQUIRED IMPORTED_TARGET libedit)
pkg_check_modules(CZMQ REQUIRED IMPORTED_TARGET libczmq>=3.0.0)
pkg_check_modules(HWLOC REQUIRED IMPORTED_TARGET hwloc>=1.11.1)
pkg_check_modules(JANSSON REQUIRED IMPORTED_TARGET jansson>=2.10)
pkg_check_modules(UUID REQUIRED IMPORTED_TARGET uuid)

set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.50 REQUIRED COMPONENTS
system
filesystem
graph
regex)
message(STATUS "Boost version: ${Boost_VERSION}")

# Install paths
set(FLUX_CMD_DIR "${CMAKE_INSTALL_PREFIX}/libexec/cmd")
set(FLUX_LIB_DIR "${CMAKE_INSTALL_LIBDIR}/flux")
set(FLUX_MOD_DIR "${FLUX_LIB_DIR}/modules")
set(FLUX_SHELL_PLUGIN_DIR "${FLUX_LIB_DIR}/shell/plugins")
set(FLUX_RC1_DIR "${CMAKE_INSTALL_SYSCONFDIR}/flux/rc1.d")
set(FLUX_RC3_DIR "${CMAKE_INSTALL_SYSCONFDIR}/flux/rc3.d")

include(config_testing)
### HELPERS
function(flux_find_python_module Name Version)
execute_process(
COMMAND ${Python_EXECUTABLE} -c "import ${Name}; print(${Name}.__version__)"
RESULT_VARIABLE EXIT_CODE
OUTPUT_VARIABLE MOD_VER
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
# COMMAND_ECHO STDOUT
)
if(MOD_VER VERSION_GREATER_EQUAL Version)
set(${Name}_MOD $MOD_VER PARENT_SCOPE)
else()
set(${Name}_MOD NOTFOUND PARENT_SCOPE)
message(FATAL_ERROR "Python module ${Name} not found or version too low, need ${Version} got ${MOD_VER}")
endif()
endfunction()
function(flux_add_plugin TargetName PluginType)
# This odd construction is as close as we can get to
# generic argument forwarding
set(options "NOINSTALL")
set(oneValueArgs "")
set(multiValueArgs "")

if(PluginType STREQUAL "MODULE")
set(LinkerOpts "LINKER:--no-undefined")
set(InstallDest ${FLUX_MOD_DIR})
elseif(PluginType STREQUAL "SHELL")
set(InstallDest ${FLUX_SHELL_PLUGIN_DIR})
endif()

cmake_parse_arguments(PARSE_ARGV 2 ARG
"${options}" "${oneValueArgs}" "${multiValueArgs}")

set(__argsQuoted)
foreach(__item IN LISTS ARG_UNPARSED_ARGUMENTS)
string(APPEND __argsQuoted " [==[${__item}]==]")
endforeach()
cmake_language(EVAL CODE "
add_library(
${TargetName}
${LibFlags}
MODULE
# List these last so they can override things we set above
${__argsQuoted}
)"
)
target_link_options(${TargetName} PRIVATE
"LINKER:--version-script=${CMAKE_SOURCE_DIR}/flux-plugin.map" ${LinkerOpts})
target_link_libraries(${TargetName} PRIVATE flux::core)
if (NOT ARG_NOINSTALL)
install(TARGETS ${TargetName}
LIBRARY DESTINATION ${InstallDest})
endif()
set_property(TARGET ${TargetName} PROPERTY PREFIX "")
endfunction()
### END HELPERS
flux_find_python_module(yaml 3.10)
flux_find_python_module(jsonschema 2.3.0)

if(ENABLE_COVERAGE)
include(CodeCoverage)

SET(COVERAGE_FLAGS "--coverage -g -fprofile-arcs -ftest-coverage")
SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_FLAGS}" )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS}" )
SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${COVERAGE_FLAGS}" )
endif()

include_directories(.)
add_subdirectory( etc )
add_subdirectory( src )
add_subdirectory( resource )
add_subdirectory( qmanager )
add_subdirectory( doc )
add_subdirectory( t )

if(ENABLE_COVERAGE)
blt_add_code_coverage_target(NAME flux-sched-coverage
DEPENDS check
RUNNER ${CMAKE_CTEST_COMMAND}
REMOVE "*/include/boost/*" "/nix/store/*" "*/include/boost/*" "*/src/common/libutil/*" "*/src/common/libtap/*" "*/src/common/yggdrasil/*")
add_custom_target(check-code-coverage
DEPENDS flux-sched-coverage)
endif()
set(CTEST_COMMON_FLAGS --output-on-failure --output-junit
${CMAKE_CURRENT_BINARY_DIR}/test-results.xml)
add_custom_target(check
DEPENDS ${check_targets}
COMMAND ${CMAKE_CTEST_COMMAND} ${CTEST_COMMON_FLAGS}
)
add_custom_target(installcheck
COMMAND env FLUX_SCHED_TEST_INSTALLED=1 ${CMAKE_CTEST_COMMAND} ${CTEST_COMMON_FLAGS})
# run installcheck, if it passes then write out version information and pack up
# a tarball with the result
add_custom_target(distcheck
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target check
COMMAND git archive --format=tar.gz
--add-virtual-file=flux-sched.ver:${FLUX_SCHED_VER}
--prefix=flux-sched-${FLUX_SCHED_VER}/
--output=${CMAKE_BINARY_DIR}/flux-sched-${FLUX_SCHED_VER}.tar.gz
HEAD .
)
5 changes: 0 additions & 5 deletions autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,3 @@
# libtool macros can be found if libtool is in PATH, but its
# macros are not in default aclocal search path.
#
echo "Running libtoolize --automake --copy ... "
libtoolize --automake --copy || exit
echo "Running autoreconf --verbose --install"
autoreconf --verbose --install || exit
echo "Now run ./configure."
Loading
Loading