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

Vector unit tests, move to a separately compiled library #3

Merged
merged 8 commits into from
Jan 12, 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
106 changes: 106 additions & 0 deletions .github/workflows/gh-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
name: Build & Test on Ubuntu, macOS, and Windows

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false

# Set up a matrix to run the following 3 configurations:
# 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator>
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
# 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator>
#
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
build_type: [Release]
c_compiler: [clang, clang-cl]
include:
- os: windows-latest
c_compiler: clang-cl
cpp_compiler: clang-cl
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
- os: macos-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: clang-cl
- os: macos-latest
c_compiler: clang-cl

steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Install LLVM and Clang on Ubuntu
if: matrix.os == 'ubuntu-latest'
run: |
wget https://apt.llvm.org/llvm.sh
chmod u+x llvm.sh
sudo ./llvm.sh 17 all
echo "PATH=/usr/lib/llvm-17/bin:$PATH" >> $GITHUB_ENV
echo "LLVM_PATH=/usr/lib/llvm-17" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=/usr/lib/llvm-17/lib" >> $GITHUB_ENV
echo "DYLD_LIBRARY_PATH=/usr/lib/llvm-17/lib" >> $GITHUB_ENV
echo "CC=/usr/lib/llvm-17/bin/clang" >> $GITHUB_ENV
echo "CXX=/usr/lib/llvm-17/bin/clang++" >> $GITHUB_ENV
shell: sh

- name: Install LLVM and Clang on MacOS
if: matrix.os == 'macos-latest'
uses: KyleMayes/[email protected]
with:
version: "15.0.7"

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}

- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: >
cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} &&
cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --target vm_unit_tests


- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: >
cd ${{ steps.strings.outputs.build-output-dir }}/test &&
ctest --build-config ${{ matrix.build_type }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
*.swp

out/*
build/*
bin/*
.vs/*
95 changes: 95 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
cmake_minimum_required( VERSION 3.27.0 )

project( vm )

###################
## Deps
###################

# Download CPM.cmake

file(
DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.38.3/CPM.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
EXPECTED_HASH SHA256=cc155ce02e7945e7b8967ddfaff0b050e958a723ef7aad3766d368940cb15494
)
set( CPM_SOURCE_CACHE "${CMAKE_CURRENT_BINARY_DIR}/deps" ) # Using this ensures shallow clones
include( ${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake )


# Add packages

set( boost_ver boost-1.84.0 )
CPMAddPackage( "gh:boostorg/static_assert#${boost_ver}" ) # Boost::core dependency
CPMAddPackage( "gh:boostorg/throw_exception#${boost_ver}" ) # Boost::core dependency
CPMAddPackage( "gh:boostorg/config#${boost_ver}" ) # Boost::core dependency
CPMAddPackage( "gh:boostorg/io#${boost_ver}" ) # Boost::utility dependency
CPMAddPackage( "gh:boostorg/type_traits#${boost_ver}" ) # Boost::utility dependency
CPMAddPackage( "gh:boostorg/predef#${boost_ver}" ) # Boost::winapi dependency
CPMAddPackage( "gh:boostorg/assert#${boost_ver}" )
CPMAddPackage( "gh:boostorg/core#${boost_ver}" )
CPMAddPackage( "gh:boostorg/preprocessor#${boost_ver}" )
CPMAddPackage( "gh:boostorg/winapi#${boost_ver}" )
CPMAddPackage( "gh:boostorg/utility#${boost_ver}" )

CPMAddPackage( "gh:psiha/config_ex#master" )
CPMAddPackage( "gh:psiha/std_fix#master" )
CPMAddPackage( "gh:psiha/err#master" )
CPMAddPackage( "gh:psiha/build#master" )

if ( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
set( PSI_USE_LINKER "lld" ) # for thinlto-cache-dir support
endif()
include( ${build_SOURCE_DIR}/build_options.cmake )

PSI_add_compile_options( Debug ${PSI_compiler_runtime_sanity_checks} )
PSI_add_link_options ( Debug ${PSI_linker_runtime_sanity_checks} )

PSI_add_compile_options( Release ${PSI_compiler_LTO} ${PSI_compiler_optimize_for_size} ${PSI_compiler_disable_thread_safe_init} ${PSI_compiler_fastmath} ${PSI_compiler_debug_symbols} )

if ( WIN32 )
add_compile_definitions( WIN32_LEAN_AND_MEAN NOMINMAX NOCOMM )
endif()

if ( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
PSI_add_link_options( Release -flto ) # lld does not seem to be enough
add_compile_options( -stdlib=libc++ )
# Needed under WSL for some reason?
PSI_add_link_options( Debug -lc++ -lc++abi -lubsan )
else()
set( CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE true )
PSI_add_link_options( Release ${PSI_linker_LTO} )
endif()


###################
## Target(s)
###################

include( vm.cmake )

target_link_libraries( psi_vm PUBLIC
Boost::core
Boost::assert
Boost::preprocessor
Boost::winapi
Boost::utility
)

target_include_directories( psi_vm PUBLIC
"${build_SOURCE_DIR}/include"
"${config_ex_SOURCE_DIR}/include"
"${err_SOURCE_DIR}/include"
)

target_include_directories( psi_vm PRIVATE
"${std_fix_SOURCE_DIR}/include"
)

###################
## Testing
###################

enable_testing()
add_subdirectory( "${PROJECT_SOURCE_DIR}/test" )
3 changes: 2 additions & 1 deletion include/psi/vm/align.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ namespace align_detail
#ifdef __clang__
[[ using gnu: const, always_inline ]] constexpr auto is_aligned( auto const value, auto const alignment ) noexcept { return __builtin_is_aligned( value, alignment ); }
#else
[[ using gnu: const, always_inline ]] constexpr auto is_aligned( auto const value, auto const alignment ) noexcept { return value % alignment == 0; }
[[ using gnu: const, always_inline ]] constexpr auto is_aligned( auto const value, auto const alignment ) noexcept { return value % alignment == 0; }
[[ using gnu: const, always_inline ]] constexpr auto is_aligned( auto * const ptr , auto const alignment ) noexcept { return is_aligned( reinterpret_cast<std::uintptr_t>( ptr ), alignment ); }
#endif
[[ using gnu: const, always_inline ]] constexpr auto align_down( auto const value, auto const alignment ) noexcept
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <sys/mman.h>
#endif // OS

#include "../span.hpp"
#include <psi/vm/span.hpp>

#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -55,7 +55,7 @@ inline std::uint32_t constexpr reserve_granularity{ 64 * 1024 };

#else // POSIX

enum class allocation_type
enum class allocation_type : int
{
reserve = PROT_NONE,
commit = PROT_READ | PROT_WRITE
Expand Down
47 changes: 0 additions & 47 deletions include/psi/vm/amalgamated_lib.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions include/psi/vm/detail/impl_inline.hpp

This file was deleted.

43 changes: 21 additions & 22 deletions include/psi/vm/detail/impl_selection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,40 @@
///
////////////////////////////////////////////////////////////////////////////////
//------------------------------------------------------------------------------
#ifndef impl_selection_hpp__05AF14B5_B23B_4CB8_A253_FD2D07B37ECF
#define impl_selection_hpp__05AF14B5_B23B_4CB8_A253_FD2D07B37ECF
#pragma once
//------------------------------------------------------------------------------
#include <boost/config.hpp>
#include <boost/preprocessor/cat.hpp>

#include <boost/preprocessor/stringize.hpp>

// Implementation note:
// "Anti-pattern" forward includes to reduce the verbosity of files that
// include this header.
// Required for PSI_VM_DIR_IMPL_INCLUDE users.
// (26.08.2011.) (Domagoj Saric)
#include <boost/preprocessor/facilities/empty.hpp>
#include <boost/preprocessor/facilities/identity.hpp>
//------------------------------------------------------------------------------
#if !defined( PSI_VM_IMPL )
#if defined( _WIN32 )
#define PSI_VM_IMPL() win32
#elif defined( _WIN32_WINNT )
#define PSI_VM_IMPL() nt
#elif defined( BOOST_HAS_UNISTD_H )
#define PSI_VM_IMPL() posix
#define PSI_VM_POSIX_INLINE inline
#else
#define PSI_VM_IMPL() xsi
#endif
# if defined( _WIN32 )
# define PSI_VM_IMPL() win32
# elif defined( _WIN32_WINNT )
# define PSI_VM_IMPL() nt
# elif __has_include( <unistd.h> )
# define PSI_VM_IMPL() posix
# define PSI_VM_POSIX_INLINE inline
# else
# define PSI_VM_IMPL() xsi
# endif
#endif // !defined( PSI_VM_IMPL )

#ifndef PSI_VM_POSIX_INLINE
#define PSI_VM_POSIX_INLINE
# define PSI_VM_POSIX_INLINE
#endif // PSI_VM_POSIX_INLINE

#define PSI_VM_IMPL_INCLUDE( prefix_path, include ) \
BOOST_PP_STRINGIZE( prefix_path()PSI_VM_IMPL()include() )
#define PSI_VM_DIR_IMPL_INCLUDE( include ) \
BOOST_PP_STRINGIZE( PSI_VM_IMPL()/include() )

#define PSI_VM_DIR_IMPL_PREFIXED_INCLUDE( prefix_path, include ) \
BOOST_PP_STRINGIZE( prefix_path()/PSI_VM_IMPL()/include() )

#define PSI_VM_IMPL_INCLUDE( include ) \
BOOST_PP_STRINGIZE( include.PSI_VM_IMPL().hpp )
//------------------------------------------------------------------------------
namespace psi::vm
{
Expand All @@ -58,4 +58,3 @@ inline namespace PSI_VM_IMPL() {}
//------------------------------------------------------------------------------
} // namespace psi::vm
//------------------------------------------------------------------------------
#endif // impl_selection_hpp
Loading