Skip to content

Commit

Permalink
Merge pull request #12 from theodelrieu/compat/c++20
Browse files Browse the repository at this point in the history
Compat/c++20
  • Loading branch information
theodelrieu authored Jul 16, 2021
2 parents 7f609cd + f7bf11e commit 1c16e33
Show file tree
Hide file tree
Showing 27 changed files with 122 additions and 61 deletions.
59 changes: 52 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ on:
- pull_request

env:
CONAN_VERSION: 1.32.0
CONAN_VERSION: 1.38.0
PATH_VERSION: 13.1.0

jobs:
build-linux:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
matrix:
compiler: [clang++-3.9, clang++-4.0, clang++-5.0, clang++-6.0, g++-5, g++-6, g++-7, g++-8]
compiler: [clang++-10, clang++-11, clang++-12, g++-8, g++-10]
steps:
- name: Setup Python environment
uses: actions/setup-python@v2
Expand All @@ -23,15 +23,14 @@ jobs:
- name: Install conan and path
run: pip install conan==$CONAN_VERSION path==$PATH_VERSION --user
- name: Install C++ compiler
# Already the default compiler on ubuntu 18.04
if: matrix.compiler != 'clang++-6.0'
if: matrix.compiler != 'clang++-12'
run: sudo apt-get install ${{ matrix.compiler }}
- name: Install build tools
run: sudo apt-get install ninja-build
- name: Build and test
run: CXX=${{ matrix.compiler }} python $GITHUB_WORKSPACE/ci/run-ci.py build-and-test --profile $GITHUB_WORKSPACE/ci/conan-profiles/${{ matrix.compiler }}
build-linux-cxx17:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- name: Setup Python environment
uses: actions/setup-python@v2
Expand All @@ -46,7 +45,24 @@ jobs:
- name: Install build tools
run: sudo apt-get install ninja-build
- name: Build and test
run: CXX=g++-8 python $GITHUB_WORKSPACE/ci/run-ci.py build-and-test --profile $GITHUB_WORKSPACE/ci/conan-profiles/g++-8 --cxx17
run: CXX=g++-8 python $GITHUB_WORKSPACE/ci/run-ci.py build-and-test --profile $GITHUB_WORKSPACE/ci/conan-profiles/g++-8 --cxx 17
build-linux-cxx20:
runs-on: ubuntu-20.04
steps:
- name: Setup Python environment
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Checkout repository
uses: actions/checkout@v1
- name: Install conan and path
run: pip install conan==$CONAN_VERSION path==$PATH_VERSION --user
- name: Install C++ compiler
run: sudo apt-get install g++-10
- name: Install build tools
run: sudo apt-get install ninja-build
- name: Build and test
run: CXX=g++-10 python $GITHUB_WORKSPACE/ci/run-ci.py build-and-test --profile $GITHUB_WORKSPACE/ci/conan-profiles/g++-10 --cxx 20
build-macos:
runs-on: macos-latest
steps:
Expand Down Expand Up @@ -89,3 +105,32 @@ jobs:
run: |
set CXX=cl
"${{ matrix.vcvars_cmd }}" ${{ matrix.vcvars_args }} && python %GITHUB_WORKSPACE%/ci/run-ci.py build-and-test --profile %GITHUB_WORKSPACE%/ci/conan-profiles/${{ matrix.compiler }}
build-windows-cxx20:
runs-on: windows-latest
strategy:
matrix:
compiler: [vs2019]
include:
- os: windows-latest
compiler: vs2019
vcvars_cmd: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat
vcvars_args: x64 10.0.18362.0

steps:
- name: Setup Python environment
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install conan and path
run: pip install conan==$env:CONAN_VERSION path==$env:PATH_VERSION --user
- name: Checkout repository
uses: actions/checkout@v1
- name: Install build tools
run: cinst ninja -y
- name: Build and test
shell: cmd
run: |
set CXX=cl
"${{ matrix.vcvars_cmd }}" ${{ matrix.vcvars_args }} && python %GITHUB_WORKSPACE%/ci/run-ci.py build-and-test --profile %GITHUB_WORKSPACE%/ci/conan-profiles/vs2019-cxx20
2 changes: 1 addition & 1 deletion base16/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def build_requirements(self):
self.build_requires("mgs_cmake/%s" % self.version)
if self.develop:
self.build_requires("mgs_meta/%s" % self.version)
self.build_requires("catch2/2.11.0")
self.build_requires("catch2/2.13.6")

def requirements(self):
self.requires("mgs_base_n/%s" % self.version)
Expand Down
2 changes: 1 addition & 1 deletion base32/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def build_requirements(self):
self.build_requires("mgs_cmake/%s" % self.version)
if self.develop:
self.build_requires("mgs_meta/%s" % self.version)
self.build_requires("catch2/2.11.0")
self.build_requires("catch2/2.13.6")

def requirements(self):
self.requires("mgs_base_n/%s" % self.version)
Expand Down
2 changes: 1 addition & 1 deletion base32hex/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ConanMgsBase32hex(ConanFile):
def build_requirements(self):
self.build_requires("mgs_cmake/%s" % self.version)
if self.develop:
self.build_requires("catch2/2.11.0")
self.build_requires("catch2/2.13.6")
self.build_requires("mgs_meta/%s" % self.version)

def requirements(self):
Expand Down
2 changes: 1 addition & 1 deletion base64/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ConanMgsBase64(ConanFile):
def build_requirements(self):
self.build_requires("mgs_cmake/%s" % self.version)
if self.develop:
self.build_requires("catch2/2.11.0")
self.build_requires("catch2/2.13.6")
self.build_requires("mgs_meta/%s" % self.version)

def requirements(self):
Expand Down
2 changes: 1 addition & 1 deletion base64url/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ConanMgsBase64Url(ConanFile):
def build_requirements(self):
self.build_requires("mgs_cmake/%s" % self.version)
if self.develop:
self.build_requires("catch2/2.11.0")
self.build_requires("catch2/2.13.6")
self.build_requires("mgs_meta/%s" % self.version)

def requirements(self):
Expand Down
2 changes: 1 addition & 1 deletion base_n/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ConanMgsBinaryToText(ConanFile):
def build_requirements(self):
self.build_requires("mgs_cmake/%s" % self.version)
if self.develop:
self.build_requires("catch2/2.11.0")
self.build_requires("catch2/2.13.6")

def requirements(self):
self.requires("mgs_meta/%s" % self.version)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include(clang++)
[settings]
compiler.version=3.9
compiler.version=10
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include(clang++)
[settings]
compiler.version=4.0
compiler.version=11
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include(clang++)
[settings]
compiler.version=5.0
compiler.version=12
3 changes: 0 additions & 3 deletions ci/conan-profiles/clang++-6.0

This file was deleted.

2 changes: 1 addition & 1 deletion ci/conan-profiles/g++-5 → ci/conan-profiles/g++-10
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include(g++)
[settings]
compiler.version=5
compiler.version=10
3 changes: 0 additions & 3 deletions ci/conan-profiles/g++-6

This file was deleted.

3 changes: 0 additions & 3 deletions ci/conan-profiles/g++-7

This file was deleted.

1 change: 1 addition & 0 deletions ci/conan-profiles/vs2019
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ arch_build=x86_64
compiler=Visual Studio
compiler.version=16
compiler.runtime=MD
compiler.cppstd=14
arch=x86_64
10 changes: 10 additions & 0 deletions ci/conan-profiles/vs2019-cxx20
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[settings]
os=Windows
os_build=Windows
build_type=Release
arch_build=x86_64
compiler=Visual Studio
compiler.version=16
compiler.runtime=MD
compiler.cppstd=20
arch=x86_64
13 changes: 9 additions & 4 deletions ci/run-ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ def install_conan_workspace(profile):
)


def build_and_test(profile, cxx17):
def build_and_test(profile, cxx):
root_path = Path(__file__).abspath().parent.parent
build_path = root_path / "build"
build_path.makedirs_p()


if cxx == None:
_cxx = "14"
else:
_cxx = cxx
with build_path:
install_conan_workspace(profile)
run_cmake("-GNinja", "..", "-DCMAKE_CXX_STANDARD=%s" % ("17" if cxx17 else "14"))
run_cmake("-GNinja", "..", "-DCMAKE_CXX_STANDARD=%s" % _cxx)
run_cmake("--build", ".")
run_cmake("--build", ".", "--target", "test")

Expand All @@ -48,11 +53,11 @@ def main():

build_and_test_parser = subparsers.add_parser("build-and-test")
build_and_test_parser.add_argument("--profile", required=True)
build_and_test_parser.add_argument("--cxx17", action="store_true")
build_and_test_parser.add_argument("--cxx")
args = parser.parse_args()

if args.command == "build-and-test":
build_and_test(Path(args.profile), args.cxx17)
build_and_test(Path(args.profile), args.cxx)
else:
parser.print_help()
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion codecs/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ConanMgsCodecsBase(ConanFile):
def build_requirements(self):
self.build_requires("mgs_cmake/%s" % self.version)
if self.develop:
self.build_requires("catch2/2.11.0")
self.build_requires("catch2/2.13.6")

def requirements(self):
self.requires("mgs_meta/%s" % self.version)
Expand Down
6 changes: 3 additions & 3 deletions codecs/include/mgs/codecs/concepts/byte_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <mgs/meta/concepts/integral.hpp>
#include <mgs/meta/concepts/same_as.hpp>

#if MGS_HAS_CPP17
#include <cstddef>
#ifdef MGS_HAS_CPP17
# include <cstddef>
#endif

namespace mgs
Expand All @@ -22,7 +22,7 @@ struct is_byte_type
using requirements = std::tuple<>;

static constexpr auto const value =
#if MGS_HAS_CPP17
#ifdef MGS_HAS_CPP17
meta::is_same_as<std::byte, T>::value ||
#endif
(meta::is_integral<T>::value &&
Expand Down
2 changes: 1 addition & 1 deletion codecs/include/mgs/codecs/detail/default_converter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ struct default_converter
typename Iterator = meta::iterator_t<codecs::basic_input_range<T>>,
typename = std::enable_if_t<
// Guaranteed copy-elision
#if MGS_HAS_CPP17
#ifdef MGS_HAS_CPP17
(meta::is_move_constructible<R>::value ||
meta::is_copy_constructible<R>::value) &&
#endif
Expand Down
6 changes: 3 additions & 3 deletions codecs/test/test_byte_type.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <catch2/catch.hpp>

#include <cstdint>
#include <cstddef>
#include <cstdint>

#include <mgs/config.hpp>
#include <mgs/codecs/concepts/byte_type.hpp>
#include <mgs/config.hpp>

using namespace mgs::codecs;

Expand All @@ -21,7 +21,7 @@ TEST_CASE("byte_type")
static_assert(is_byte_type<std::uint8_t>::value, "");
static_assert(is_byte_type<std::int8_t>::value, "");

#if MGS_HAS_CPP17
#ifdef MGS_HAS_CPP17
static_assert(is_byte_type<std::byte>::value, "");
#endif
}
3 changes: 2 additions & 1 deletion codecs/test/test_iterator_sentinel_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ TEST_CASE("codecs::iterator_sentinel_source")
SECTION("range")
{
static_assert(is_range<iterator_sentinel_source<char const*>>::value, "");
static_assert(is_semiregular<iterator_sentinel_source<char const*>>::value, "");
static_assert(is_semiregular<iterator_sentinel_source<char const*>>::value,
"");

auto source = make_iterator_sentinel_source("000");
CHECK(std::count(source.begin(), source.end(), '0') == 3);
Expand Down
25 changes: 12 additions & 13 deletions config/include/mgs/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

#ifdef _MSC_VER
# if _MSVC_LANG >= 201402L
# define MGS_HAS_CPP14 1
# define MGS_HAS_CPP14
# if _MSVC_LANG >= 201703L
# define MGS_HAS_CPP17 1
# if _MSVC_LANG > 201703L
# define MGS_HAS_CPP20 1
# endif
# define MGS_HAS_CPP17
# define MGS_HAS_CPP20
# endif
# endif
#else
# if __cplusplus >= 201402L
# define MGS_HAS_CPP14 1
# if __cplusplus >= 201703L
# define MGS_HAS_CPP17 1
# if __cplusplus > 201703L
# define MGS_HAS_CPP20 1
# endif
# endif
# if __cplusplus >= 201709L
# define MGS_HAS_CPP20
# define MGS_HAS_CPP17
# define MGS_HAS_CPP14
# elif __cplusplus >= 201703L
# define MGS_HAS_CPP17
# define MGS_HAS_CPP14
# elif __cplusplus >= 201402L
# define MGS_HAS_CPP14
# endif
#endif
2 changes: 1 addition & 1 deletion meta/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ConanMgsMeta(ConanFile):
def build_requirements(self):
self.build_requires("mgs_cmake/%s" % self.version)
if self.develop:
self.build_requires("catch2/2.11.0")
self.build_requires("catch2/2.13.6")

def requirements(self):
self.requires("mgs_config/%s" % self.version)
Expand Down
5 changes: 5 additions & 0 deletions meta/test/test_incrementable_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <catch2/catch.hpp>

#include <mgs/config.hpp>
#include <mgs/meta/incrementable_traits.hpp>
#include <mgs/meta/iter_difference_t.hpp>

Expand Down Expand Up @@ -49,9 +50,13 @@ TEST_CASE("incrementable_traits")
"");
static_assert(std::is_same<iter_difference_t<valid>, int>::value, "");
static_assert(std::is_same<iter_difference_t<both>, char>::value, "");
// in C++20, difference_type should be std::ptrdiff_t, but it depends on
// compiler support, so skip this test for now
#ifndef MGS_HAS_CPP20
static_assert(
std::is_same<
iter_difference_t<std::back_insert_iterator<std::vector<int>>>,
void>::value,
"");
#endif
}
Loading

0 comments on commit 1c16e33

Please sign in to comment.