From 0b87b22d9d67b9677d70a2fb82c2f53426c9f880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Delrieu?= Date: Thu, 15 Jul 2021 15:24:56 +0200 Subject: [PATCH 1/4] c++20: make tests pass --- base16/conanfile.py | 2 +- base32/conanfile.py | 2 +- base32hex/conanfile.py | 2 +- base64/conanfile.py | 2 +- base64url/conanfile.py | 2 +- base_n/conanfile.py | 2 +- codecs/conanfile.py | 2 +- .../include/mgs/codecs/concepts/byte_type.hpp | 6 ++--- .../mgs/codecs/detail/default_converter.hpp | 2 +- codecs/test/test_byte_type.cpp | 6 ++--- codecs/test/test_iterator_sentinel_source.cpp | 3 ++- config/include/mgs/config.hpp | 25 +++++++++---------- meta/conanfile.py | 2 +- meta/test/test_incrementable_traits.cpp | 5 ++++ meta/test/test_iter_concept.cpp | 15 +++++------ meta/test/test_regular.cpp | 5 +++- 16 files changed, 46 insertions(+), 37 deletions(-) diff --git a/base16/conanfile.py b/base16/conanfile.py index 037bef2..2c1c75a 100644 --- a/base16/conanfile.py +++ b/base16/conanfile.py @@ -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) diff --git a/base32/conanfile.py b/base32/conanfile.py index 65768ee..b4d13f1 100644 --- a/base32/conanfile.py +++ b/base32/conanfile.py @@ -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) diff --git a/base32hex/conanfile.py b/base32hex/conanfile.py index b293a2f..d21abc7 100644 --- a/base32hex/conanfile.py +++ b/base32hex/conanfile.py @@ -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): diff --git a/base64/conanfile.py b/base64/conanfile.py index 5231f98..d138944 100644 --- a/base64/conanfile.py +++ b/base64/conanfile.py @@ -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): diff --git a/base64url/conanfile.py b/base64url/conanfile.py index 0b776eb..2400458 100644 --- a/base64url/conanfile.py +++ b/base64url/conanfile.py @@ -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): diff --git a/base_n/conanfile.py b/base_n/conanfile.py index 7da0ec1..adb05de 100644 --- a/base_n/conanfile.py +++ b/base_n/conanfile.py @@ -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) diff --git a/codecs/conanfile.py b/codecs/conanfile.py index 6c4439e..0213f6a 100644 --- a/codecs/conanfile.py +++ b/codecs/conanfile.py @@ -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) diff --git a/codecs/include/mgs/codecs/concepts/byte_type.hpp b/codecs/include/mgs/codecs/concepts/byte_type.hpp index 0bfcae4..1fa4ed1 100644 --- a/codecs/include/mgs/codecs/concepts/byte_type.hpp +++ b/codecs/include/mgs/codecs/concepts/byte_type.hpp @@ -8,8 +8,8 @@ #include #include -#if MGS_HAS_CPP17 -#include +#ifdef MGS_HAS_CPP17 +# include #endif namespace mgs @@ -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::value || #endif (meta::is_integral::value && diff --git a/codecs/include/mgs/codecs/detail/default_converter.hpp b/codecs/include/mgs/codecs/detail/default_converter.hpp index 1d06944..f909e48 100644 --- a/codecs/include/mgs/codecs/detail/default_converter.hpp +++ b/codecs/include/mgs/codecs/detail/default_converter.hpp @@ -119,7 +119,7 @@ struct default_converter typename Iterator = meta::iterator_t>, typename = std::enable_if_t< // Guaranteed copy-elision -#if MGS_HAS_CPP17 +#ifdef MGS_HAS_CPP17 (meta::is_move_constructible::value || meta::is_copy_constructible::value) && #endif diff --git a/codecs/test/test_byte_type.cpp b/codecs/test/test_byte_type.cpp index 91624b4..ffa28ad 100644 --- a/codecs/test/test_byte_type.cpp +++ b/codecs/test/test_byte_type.cpp @@ -1,10 +1,10 @@ #include -#include #include +#include -#include #include +#include using namespace mgs::codecs; @@ -21,7 +21,7 @@ TEST_CASE("byte_type") static_assert(is_byte_type::value, ""); static_assert(is_byte_type::value, ""); -#if MGS_HAS_CPP17 +#ifdef MGS_HAS_CPP17 static_assert(is_byte_type::value, ""); #endif } diff --git a/codecs/test/test_iterator_sentinel_source.cpp b/codecs/test/test_iterator_sentinel_source.cpp index fc6cbfe..54e9fcb 100644 --- a/codecs/test/test_iterator_sentinel_source.cpp +++ b/codecs/test/test_iterator_sentinel_source.cpp @@ -116,7 +116,8 @@ TEST_CASE("codecs::iterator_sentinel_source") SECTION("range") { static_assert(is_range>::value, ""); - static_assert(is_semiregular>::value, ""); + static_assert(is_semiregular>::value, + ""); auto source = make_iterator_sentinel_source("000"); CHECK(std::count(source.begin(), source.end(), '0') == 3); diff --git a/config/include/mgs/config.hpp b/config/include/mgs/config.hpp index 7016cdd..e984880 100644 --- a/config/include/mgs/config.hpp +++ b/config/include/mgs/config.hpp @@ -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 diff --git a/meta/conanfile.py b/meta/conanfile.py index ad70c02..e30af7c 100644 --- a/meta/conanfile.py +++ b/meta/conanfile.py @@ -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) diff --git a/meta/test/test_incrementable_traits.cpp b/meta/test/test_incrementable_traits.cpp index 38e5311..8f8259e 100644 --- a/meta/test/test_incrementable_traits.cpp +++ b/meta/test/test_incrementable_traits.cpp @@ -5,6 +5,7 @@ #include +#include #include #include @@ -49,9 +50,13 @@ TEST_CASE("incrementable_traits") ""); static_assert(std::is_same, int>::value, ""); static_assert(std::is_same, 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>>, void>::value, ""); +#endif } diff --git a/meta/test/test_iter_concept.cpp b/meta/test/test_iter_concept.cpp index f8b4e13..f678d5e 100644 --- a/meta/test/test_iter_concept.cpp +++ b/meta/test/test_iter_concept.cpp @@ -34,9 +34,9 @@ struct iterator_traits TEST_CASE("iter_concept") { - static_assert( - std::is_same, std::random_access_iterator_tag>::value, - ""); + static_assert(std::is_base_of>::value, + ""); static_assert(std::is_same::iterator>, std::bidirectional_iterator_tag>::value, ""); @@ -50,11 +50,12 @@ TEST_CASE("iter_concept") static_assert( std::is_same, std::random_access_iterator_tag>::value, ""); - static_assert(std::is_same, - std::random_access_iterator_tag>::value, + // C++20 introduces contiguous iterators, use is_base_of instead of is_same + static_assert(std::is_base_of>::value, ""); - static_assert(std::is_same, - std::random_access_iterator_tag>::value, + static_assert(std::is_base_of>::value, ""); static_assert( std::is_same, struct incomplete>::value, diff --git a/meta/test/test_regular.cpp b/meta/test/test_regular.cpp index a5640e0..3dd7862 100644 --- a/meta/test/test_regular.cpp +++ b/meta/test/test_regular.cpp @@ -3,9 +3,9 @@ #include #include -#include #include #include +#include using namespace mgs::meta; @@ -29,6 +29,9 @@ struct almost_regular bool operator==(almost_regular const&, almost_regular const&); +// Have to explicitly delete it since C++20 introduces default comparisons +bool operator!=(almost_regular const&, almost_regular const&) = delete; + struct valid_regular { }; From d3f9cd7c9eb25eead1e218dca7615693731ea28b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Delrieu?= Date: Thu, 15 Jul 2021 15:28:55 +0200 Subject: [PATCH 2/4] ci: add cxx20 jobs, remove old compilers --- .github/workflows/ci.yml | 54 +++++++++++++++++-- ci/conan-profiles/{clang++-3.9 => clang++-10} | 2 +- ci/conan-profiles/{clang++-4.0 => clang++-11} | 2 +- ci/conan-profiles/{clang++-5.0 => clang++-12} | 2 +- ci/conan-profiles/clang++-6.0 | 3 -- ci/conan-profiles/{g++-5 => g++-10} | 2 +- ci/conan-profiles/g++-6 | 3 -- ci/conan-profiles/g++-7 | 3 -- ci/conan-profiles/vs2019 | 1 + ci/conan-profiles/vs2019-cxx20 | 10 ++++ ci/run-ci.py | 13 +++-- 11 files changed, 74 insertions(+), 21 deletions(-) rename ci/conan-profiles/{clang++-3.9 => clang++-10} (57%) rename ci/conan-profiles/{clang++-4.0 => clang++-11} (57%) rename ci/conan-profiles/{clang++-5.0 => clang++-12} (57%) delete mode 100644 ci/conan-profiles/clang++-6.0 rename ci/conan-profiles/{g++-5 => g++-10} (54%) delete mode 100644 ci/conan-profiles/g++-6 delete mode 100644 ci/conan-profiles/g++-7 create mode 100644 ci/conan-profiles/vs2019-cxx20 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1375cbd..d9fefdf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-18.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 @@ -23,8 +23,8 @@ 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' + # Already the default compiler on ubuntu 20.04 + if: matrix.compiler != 'clang++-12' run: sudo apt-get install ${{ matrix.compiler }} - name: Install build tools run: sudo apt-get install ninja-build @@ -46,7 +46,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: @@ -89,3 +106,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 + diff --git a/ci/conan-profiles/clang++-3.9 b/ci/conan-profiles/clang++-10 similarity index 57% rename from ci/conan-profiles/clang++-3.9 rename to ci/conan-profiles/clang++-10 index b81d731..fc9dd72 100644 --- a/ci/conan-profiles/clang++-3.9 +++ b/ci/conan-profiles/clang++-10 @@ -1,3 +1,3 @@ include(clang++) [settings] -compiler.version=3.9 +compiler.version=10 diff --git a/ci/conan-profiles/clang++-4.0 b/ci/conan-profiles/clang++-11 similarity index 57% rename from ci/conan-profiles/clang++-4.0 rename to ci/conan-profiles/clang++-11 index e626b41..dc1a921 100644 --- a/ci/conan-profiles/clang++-4.0 +++ b/ci/conan-profiles/clang++-11 @@ -1,3 +1,3 @@ include(clang++) [settings] -compiler.version=4.0 +compiler.version=11 diff --git a/ci/conan-profiles/clang++-5.0 b/ci/conan-profiles/clang++-12 similarity index 57% rename from ci/conan-profiles/clang++-5.0 rename to ci/conan-profiles/clang++-12 index e07110c..8800e89 100644 --- a/ci/conan-profiles/clang++-5.0 +++ b/ci/conan-profiles/clang++-12 @@ -1,3 +1,3 @@ include(clang++) [settings] -compiler.version=5.0 +compiler.version=12 diff --git a/ci/conan-profiles/clang++-6.0 b/ci/conan-profiles/clang++-6.0 deleted file mode 100644 index 5182aae..0000000 --- a/ci/conan-profiles/clang++-6.0 +++ /dev/null @@ -1,3 +0,0 @@ -include(clang++) -[settings] -compiler.version=6.0 diff --git a/ci/conan-profiles/g++-5 b/ci/conan-profiles/g++-10 similarity index 54% rename from ci/conan-profiles/g++-5 rename to ci/conan-profiles/g++-10 index 897dccd..b2b5552 100644 --- a/ci/conan-profiles/g++-5 +++ b/ci/conan-profiles/g++-10 @@ -1,3 +1,3 @@ include(g++) [settings] -compiler.version=5 +compiler.version=10 diff --git a/ci/conan-profiles/g++-6 b/ci/conan-profiles/g++-6 deleted file mode 100644 index 972c1e5..0000000 --- a/ci/conan-profiles/g++-6 +++ /dev/null @@ -1,3 +0,0 @@ -include(g++) -[settings] -compiler.version=6 diff --git a/ci/conan-profiles/g++-7 b/ci/conan-profiles/g++-7 deleted file mode 100644 index 5287cbc..0000000 --- a/ci/conan-profiles/g++-7 +++ /dev/null @@ -1,3 +0,0 @@ -include(g++) -[settings] -compiler.version=7 diff --git a/ci/conan-profiles/vs2019 b/ci/conan-profiles/vs2019 index e0e0d96..d28bec3 100644 --- a/ci/conan-profiles/vs2019 +++ b/ci/conan-profiles/vs2019 @@ -6,4 +6,5 @@ arch_build=x86_64 compiler=Visual Studio compiler.version=16 compiler.runtime=MD +compiler.cppstd=14 arch=x86_64 diff --git a/ci/conan-profiles/vs2019-cxx20 b/ci/conan-profiles/vs2019-cxx20 new file mode 100644 index 0000000..362d654 --- /dev/null +++ b/ci/conan-profiles/vs2019-cxx20 @@ -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 diff --git a/ci/run-ci.py b/ci/run-ci.py index 66a0a7f..9af2498 100644 --- a/ci/run-ci.py +++ b/ci/run-ci.py @@ -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") @@ -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) From f3972d15205f331e583ce4a4d7ae317cb3428290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Delrieu?= Date: Thu, 15 Jul 2021 15:31:28 +0200 Subject: [PATCH 3/4] ci: upgrade to ubuntu 20.04 --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d9fefdf..26de484 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ env: jobs: build-linux: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: matrix: compiler: [clang++-10, clang++-11, clang++-12, g++-8, g++-10] @@ -23,7 +23,6 @@ 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 20.04 if: matrix.compiler != 'clang++-12' run: sudo apt-get install ${{ matrix.compiler }} - name: Install build tools @@ -31,7 +30,7 @@ jobs: - 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 From f7bf11e463e506e037bae042b2074b1f0c4506fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Delrieu?= Date: Thu, 15 Jul 2021 15:42:45 +0200 Subject: [PATCH 4/4] ci: bump conan to 1.38.0 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26de484..2253cec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,7 @@ on: - pull_request env: - CONAN_VERSION: 1.32.0 + CONAN_VERSION: 1.38.0 PATH_VERSION: 13.1.0 jobs: