Skip to content

Set versions in CMake #453

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

Merged
merged 3 commits into from
May 9, 2024
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
15 changes: 13 additions & 2 deletions .github/workflows/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on: workflow_call
permissions:
contents: read

env:
# for installation testing - it should match with version set in CMake
UMF_VERSION: 0.1.0

jobs:
icx-build:
# TODO: we could merge ICX build with gcc/clang (using our dockers) Issue: #259
Expand Down Expand Up @@ -34,7 +38,10 @@ jobs:
- name: Install apt packages
run: |
apt-get update
apt-get install -y libnuma-dev libjemalloc-dev libtbb-dev libhwloc-dev sudo
apt-get install -y libnuma-dev libjemalloc-dev libtbb-dev libhwloc-dev python3-pip sudo

- name: Install Python requirements
run: python3 -m pip install -r third_party/requirements.txt

- name: Configure build
run: >
Expand Down Expand Up @@ -71,6 +78,7 @@ jobs:
--disjoint-pool
--jemalloc-pool
--scalable-pool
--umf-version ${{env.UMF_VERSION}}
${{ matrix.shared_library == 'ON' && '--shared-library' || ''}}

ubuntu-build:
Expand Down Expand Up @@ -170,6 +178,7 @@ jobs:
--disjoint-pool
--jemalloc-pool
--scalable-pool
--umf-version ${{env.UMF_VERSION}}
${{ matrix.shared_library == 'ON' && '--shared-library' || '' }}

windows-build:
Expand Down Expand Up @@ -258,6 +267,7 @@ jobs:
--disjoint-pool
--jemalloc-pool
--scalable-pool
--umf-version ${{env.UMF_VERSION}}
${{ matrix.shared_library == 'ON' && '--shared-library' || ''}}

macos-build:
Expand Down Expand Up @@ -304,7 +314,8 @@ jobs:
--build-dir ${{env.BUILD_DIR}}
--install-dir ${{env.INSTL_DIR}}
--build-type ${{env.BUILD_TYPE}}
--shared-library
--disjoint-pool
--jemalloc-pool
--scalable-pool
--umf-version ${{env.UMF_VERSION}}
--shared-library
22 changes: 16 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ project(
VERSION 0.1.0
LANGUAGES C)

# needed when UMF is used as an external project
set(UMF_CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

list(APPEND CMAKE_MODULE_PATH "${UMF_CMAKE_SOURCE_DIR}/cmake")
include(helpers)

# CMAKE_PROJECT_VERSION[_MAJOR|_MINOR|_PATCH] variables are set via 'project'
# command. They cannot contain any "pre-release" part, though. We use custom
# "UMF_SRC_VERSION" to store more accurate (source) version - this var should be
# used, e.g., for creating packages.
set_source_version()
message(
STATUS
"UMF version: ${CMAKE_PROJECT_VERSION} (source version: ${UMF_SRC_VERSION})"
)

# Build Options
option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
option(UMF_BUILD_LEVEL_ZERO_PROVIDER "Build Level Zero memory provider" ON)
Expand Down Expand Up @@ -109,12 +125,6 @@ include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
find_package(PkgConfig)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(helpers)

# needed when UMF is used as an external project
set(UMF_CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_UMF_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
Expand Down
64 changes: 64 additions & 0 deletions cmake/helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,70 @@
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)

# src version shows the current version, as reported by 'git describe', unless
# 'git' is not available, then fall back to the top-level defined version
function(set_source_version)
execute_process(
COMMAND git describe --always
OUTPUT_VARIABLE GIT_VERSION
WORKING_DIRECTORY ${UMF_CMAKE_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)

if(GIT_VERSION)
# 1.5.0 - we're on a tag
string(REGEX MATCHALL "\^([0-9]+\.[0-9]+\.[0-9]+)\$" MATCHES
${GIT_VERSION})
if(MATCHES)
set(UMF_SRC_VERSION
"${CMAKE_MATCH_1}"
PARENT_SCOPE)
return()
endif()

# 1.5.0-rc1 - we're on a RC tag
string(REGEX MATCHALL "\^([0-9]+\.[0-9]+\.[0-9]+\-rc[0-9]+)\$" MATCHES
${GIT_VERSION})
if(MATCHES)
set(UMF_SRC_VERSION
"${CMAKE_MATCH_1}"
PARENT_SCOPE)
return()
endif()

# 1.5.0-rc1-19-gb8f78a329 -> 1.5.0-rc1.git19.gb8f78a329
string(REGEX MATCHALL "([0-9.]*)-rc([0-9]*)-([0-9]*)-([0-9a-g]*)"
MATCHES ${GIT_VERSION})
if(MATCHES)
set(UMF_SRC_VERSION
"${CMAKE_MATCH_1}-rc${CMAKE_MATCH_2}.git${CMAKE_MATCH_3}.${CMAKE_MATCH_4}"
PARENT_SCOPE)
return()
endif()

# 1.5.0-19-gb8f78a329 -> 1.5.0-git19.gb8f78a329
string(REGEX MATCHALL "([0-9.]*)-([0-9]*)-([0-9a-g]*)" MATCHES
${GIT_VERSION})
if(MATCHES)
set(UMF_SRC_VERSION
"${CMAKE_MATCH_1}-git${CMAKE_MATCH_2}.${CMAKE_MATCH_3}"
PARENT_SCOPE)
return()
endif()

# no full version is available (e.g. only a hash commit) or a pattern
# was not recognized
set(UMF_SRC_VERSION
"${CMAKE_PROJECT_VERSION}.git.${GIT_VERSION}"
PARENT_SCOPE)
else()
# git reported no version. Use version set up in the top-level CMake
# with a "devel" suffix
set(UMF_SRC_VERSION
"${CMAKE_PROJECT_VERSION}-devel"
PARENT_SCOPE)
endif()
endfunction()

# Sets ${ret} to version of program specified by ${name} in major.minor format
function(get_program_version_major_minor name ret)
execute_process(
Expand Down
7 changes: 5 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,11 @@ if(UMF_BUILD_SHARED_LIBRARY)
WINDOWS_DEF_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libumf.def)
set(UMF_PRIVATE_COMPILE_DEFINITIONS ${UMF_PRIVATE_COMPILE_DEFINITIONS}
"UMF_SHARED_LIBRARY")
set_target_properties(umf PROPERTIES RUNTIME_OUTPUT_DIRECTORY
${CMAKE_UMF_OUTPUT_DIRECTORY})
set_target_properties(
umf
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_UMF_OUTPUT_DIRECTORY}
VERSION ${CMAKE_PROJECT_VERSION}
SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR})
else()
add_umf_library(
NAME umf
Expand Down
2 changes: 2 additions & 0 deletions src/proxy_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ add_umf_library(
LIBS ${PROXY_LIBS}
LINUX_MAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/proxy_lib.map
WINDOWS_DEF_FILE ${CMAKE_CURRENT_SOURCE_DIR}/proxy_lib.def)
set_target_properties(umf_proxy PROPERTIES SOVERSION
${CMAKE_PROJECT_VERSION_MAJOR})

add_library(${PROJECT_NAME}::proxy ALIAS umf_proxy)

Expand Down
45 changes: 42 additions & 3 deletions test/test_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import argparse
import difflib
from packaging.version import Version
from pathlib import Path
import platform
import subprocess # nosec B404
Expand All @@ -25,6 +26,7 @@ class UmfInstaller:
build_type (str): Debug or Release build type passed to the script
shared_library (bool): Determines if the UMF was built as a shared library
pools (List[str]): A list of enabled pools during the UMF compilation
umf_version (Version): UMF version currently being built and installed
match_list (List[str]): A list of relative paths of files that should be installed
"""

Expand All @@ -36,13 +38,15 @@ def __init__(
build_type: str,
shared_library: bool,
pools: List[str],
umf_version: Version,
):
self.workspace_dir = workspace_dir
self.build_dir = build_dir
self.install_dir = install_dir
self.build_type = build_type
self.shared_library = shared_library
self.pools = pools
self.umf_version = umf_version
self.match_list = self._create_match_list()

def _create_match_list(self) -> List[str]:
Expand Down Expand Up @@ -95,11 +99,34 @@ def _create_match_list(self) -> List[str]:
]
for pool in self.pools:
lib.append(f"lib/{lib_prefix}{pool}.{lib_ext_static}")
lib_ext = lib_ext_shared if self.shared_library else lib_ext_static
lib.append(f"lib/{lib_prefix}umf.{lib_ext}")
if self.shared_library:
lib.append(f"lib/{lib_prefix}umf.{lib_ext_shared}")

if platform.system() == "Linux":
lib.append(
f"lib/{lib_prefix}umf.{lib_ext_shared}.{self.umf_version.major}"
)
lib.append(f"lib/{lib_prefix}umf.{lib_ext_shared}.{self.umf_version}")
elif platform.system() == "Darwin": # MacOS
lib.append(
f"lib/{lib_prefix}umf.{self.umf_version.major}.{lib_ext_shared}"
)
lib.append(f"lib/{lib_prefix}umf.{self.umf_version}.{lib_ext_shared}")
else:
lib.append(f"lib/{lib_prefix}umf.{lib_ext_static}")

if is_umf_proxy:
lib.append(f"lib/{lib_prefix}umf_proxy.{lib_ext_shared}")

if platform.system() == "Linux":
lib.append(
f"lib/{lib_prefix}umf_proxy.{lib_ext_shared}.{self.umf_version.major}"
)
elif platform.system() == "Darwin": # MacOS
lib.append(
f"lib/{lib_prefix}umf_proxy.{self.umf_version.major}.{lib_ext_shared}"
)

share = []
share = [
"share",
Expand Down Expand Up @@ -155,9 +182,14 @@ def validate_installed_files(self) -> None:
)
]

expected_files = [
str(entry)
for entry in sorted(self.match_list, key=lambda x: str(x).casefold())
]

diff = list(
difflib.unified_diff(
self.match_list,
expected_files,
installed_files,
fromfile="Expected files",
tofile="Installed files",
Expand Down Expand Up @@ -252,6 +284,11 @@ def parse_arguments(self) -> argparse.Namespace:
action="store_true",
help="Add this argument if the UMF was built with Scalable Pool enabled",
)
self.parser.add_argument(
"--umf-version",
action="store",
help="Current version of the UMF, e.g. 1.0.0",
)
return self.parser.parse_args()

def run(self) -> None:
Expand All @@ -269,6 +306,7 @@ def run(self) -> None:
pools.append("jemalloc_pool")
if self.args.scalable_pool:
pools.append("scalable_pool")
umf_version = Version(self.args.umf_version)

umf_installer = UmfInstaller(
workspace_dir,
Expand All @@ -277,6 +315,7 @@ def run(self) -> None:
self.args.build_type,
self.args.shared_library,
pools,
umf_version,
)

print("Installation test - BEGIN", flush=True)
Expand Down
2 changes: 2 additions & 0 deletions third_party/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
clang-format==15.0.7
cmake-format==0.6.13
black==24.3.0
# Tests
packaging==24.0
# Generating HTML documentation
pygments==2.15.1
sphinxcontrib_applehelp==1.0.4
Expand Down