From 84fa1ac50aaa91e259b2b9c12c108e3e00ea0b12 Mon Sep 17 00:00:00 2001 From: 500-internal-server-error <76838083+500-internal-server-error@users.noreply.github.com> Date: Wed, 19 Feb 2025 20:23:27 +0700 Subject: [PATCH 1/7] Fix building on Windows with Clang in MinGW mode Apply GCC `#pragma`s to Clang too, and also more to fix the things Clang catches that GCC doesn't --- include/ghc/filesystem.hpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 89fccfd..c77058d 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -1941,7 +1941,7 @@ GHC_INLINE void create_symlink(const path& target_name, const path& new_symlink, ec = detail::make_error_code(detail::portable_error::not_supported); return; } -#if defined(__GNUC__) && __GNUC__ >= 8 +#if (defined(__GNUC__) && __GNUC__ >= 8) || defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-function-type" #elif defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__clang__) @@ -1949,7 +1949,7 @@ GHC_INLINE void create_symlink(const path& target_name, const path& new_symlink, #pragma warning(disable : 4191) #endif static CreateSymbolicLinkW_fp api_call = reinterpret_cast(GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "CreateSymbolicLinkW")); -#if defined(__GNUC__) && __GNUC__ >= 8 +#if (defined(__GNUC__) && __GNUC__ >= 8) || defined(__clang__) #pragma GCC diagnostic pop #elif defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__clang__) #pragma warning(pop) @@ -1970,7 +1970,7 @@ GHC_INLINE void create_symlink(const path& target_name, const path& new_symlink, GHC_INLINE void create_hardlink(const path& target_name, const path& new_hardlink, std::error_code& ec) { -#if defined(__GNUC__) && __GNUC__ >= 8 +#if (defined(__GNUC__) && __GNUC__ >= 8) || defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-function-type" #elif defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__clang__) @@ -1978,7 +1978,7 @@ GHC_INLINE void create_hardlink(const path& target_name, const path& new_hardlin #pragma warning(disable : 4191) #endif static CreateHardLinkW_fp api_call = reinterpret_cast(GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "CreateHardLinkW")); -#if defined(__GNUC__) && __GNUC__ >= 8 +#if (defined(__GNUC__) && __GNUC__ >= 8) || defined(__clang__) #pragma GCC diagnostic pop #elif defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__clang__) #pragma warning(pop) @@ -2116,6 +2116,13 @@ class unique_handle element_type _handle; }; +// It seems GCC doesn't catch this, but Clang does +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72751 +#if defined(__clang__) && defined(__MINGW32__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wnested-anon-types" +#endif + #ifndef REPARSE_DATA_BUFFER_HEADER_SIZE typedef struct _REPARSE_DATA_BUFFER { @@ -2152,6 +2159,10 @@ typedef struct _REPARSE_DATA_BUFFER #endif #endif +#if defined(__clang__) && defined(__MINGW32__) +#pragma clang diagnostic pop +#endif + template struct free_deleter { @@ -2246,12 +2257,22 @@ GHC_INLINE void timeToFILETIME(time_t t, FILETIME& ft) ft.dwHighDateTime = ull.HighPart; } +// Not sure why GCC doesn't catch this here, but Clang does +#if defined(__clang__) && defined(__MINGW32__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" +#endif + template GHC_INLINE uintmax_t hard_links_from_INFO(const INFO* info) { return static_cast(-1); } +#if defined(__clang__) && defined(__MINGW32__) +#pragma clang diagnostic pop +#endif + template <> GHC_INLINE uintmax_t hard_links_from_INFO(const BY_HANDLE_FILE_INFORMATION* info) { From d7d5e314dbf728217a877b426480552b585e2961 Mon Sep 17 00:00:00 2001 From: 500-internal-server-error <76838083+500-internal-server-error@users.noreply.github.com> Date: Wed, 19 Feb 2025 20:24:57 +0700 Subject: [PATCH 2/7] Fix building with (mostly) default flags on Windows MinGW It's already being done for Cygwin, presumably for the same reasons. Clang auto-applies `-mbig-obj` as needed it seems: https://reviews.llvm.org/D102419 Tests against `std::filesystem` remain broken, though, and building with MinGW still requires disabling them manually with `-DGHC_FILESYSTEM_BUILD_STD_TESTING=NO`: https://github.com/gulrak/filesystem/issues/189#issuecomment-2571334165 --- cmake/GhcHelper.cmake | 4 ++-- test/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/GhcHelper.cmake b/cmake/GhcHelper.cmake index 4d9e5a0..ad72fd2 100644 --- a/cmake/GhcHelper.cmake +++ b/cmake/GhcHelper.cmake @@ -40,7 +40,7 @@ if (CMAKE_COMPILER_IS_GNUCXX AND (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 8.0 O if(${CMAKE_SYSTEM_NAME} MATCHES "Haiku") target_link_libraries(${targetName} network) endif() - target_compile_options(${targetName} PRIVATE $<$:-Wa,-mbig-obj>) + target_compile_options(${targetName} PRIVATE $<$,$>:-Wa,-mbig-obj>) target_compile_definitions(${targetName} PRIVATE USE_STD_FS) endif() @@ -69,7 +69,7 @@ macro(AddTestExecutableWithStdCpp cppStd) $<$,$>:-Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wpedantic -Werror -Wno-error=deprecated-declarations> $<$:-Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wpedantic -Wno-psabi -Werror -Wno-error=deprecated-declarations> $<$:/WX /wd4996> - $<$:-Wa,-mbig-obj> + $<$,$>:-Wa,-mbig-obj> $<$:--coverage>) if(CMAKE_CXX_COMPILER_ID MATCHES MSVC) target_compile_definitions(filesystem_test_cpp${cppStd} PRIVATE _CRT_SECURE_NO_WARNINGS) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1401ef0..5a529a2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,7 +14,7 @@ function(SetTestCompileOptions target_name) $<$,$>:-Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wpedantic -Werror -Wno-deprecated-declarations> $<$:-Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wpedantic -Wno-psabi -Werror -Wno-deprecated-declarations> $<$:/WX /wd4996> - $<$:-Wa,-mbig-obj>) + $<$,$>:-Wa,-mbig-obj>) endfunction() if(GHC_COVERAGE) From 08f6074ade2f67b615f4dfd334ff662b2dcb190d Mon Sep 17 00:00:00 2001 From: 500-internal-server-error <76838083+500-internal-server-error@users.noreply.github.com> Date: Wed, 19 Feb 2025 20:56:52 +0700 Subject: [PATCH 3/7] Add CI for Windows MinGW builds --- .github/workflows/build_cmake.yml | 43 ++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build_cmake.yml b/.github/workflows/build_cmake.yml index 59aca66..1fc54b8 100644 --- a/.github/workflows/build_cmake.yml +++ b/.github/workflows/build_cmake.yml @@ -85,12 +85,34 @@ jobs: - name: "Windows MSVC 2019" os: windows-2019 build_type: Release + build_std_testing: 'OFF' packages: ninja generator: "Visual Studio 16 2019" compatibility: "cxx_std_11;cxx_std_17;cxx_std_20" cc: cl cxx: cl + - name: "Windows MSYS2 UCRT64" + os: windows-2019 + msystem: ucrt64 + build_type: Release + build_std_testing: 'OFF' + packages: mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-ninja + generator: Ninja + compatibility: "cxx_std_11;cxx_std_17;cxx_std_20" + cc: gcc + cxx: g++ + + - name: "Windows MSYS2 CLANG64" + os: windows-2019 + msystem: clang64 + build_type: Release + packages: mingw-w64-clang-x86_64-cmake mingw-w64-clang-x86_64-clang mingw-w64-clang-x86_64-ninja + generator: Ninja + compatibility: "cxx_std_11;cxx_std_17;cxx_std_20" + cc: clang + cxx: clang++ + - name: "macOS 13 AppleClang" os: macos-13 build_type: Release @@ -116,11 +138,19 @@ jobs: sudo apt update sudo apt install ${{ matrix.config.packages }} - - name: Install dependencies on windows + - name: Install dependencies on windows (MSVC) if: startsWith(matrix.config.os, 'windows') run: | choco install ${{ matrix.config.packages }} + - name: Install dependencies on windows (MSYS2) + if: matrix.config.msystem != '' + uses: msys2/setup-msys2@v2 + with: + msystem: ${{ matrix.config.msystem }} + update: true + pacboy: ${{ matrix.config.packages }} + - name: Install dependencies on macOS if: startsWith(matrix.config.os, 'macos') run: | @@ -135,11 +165,11 @@ jobs: cmake --version mkdir build mkdir install - if [[ "${{ matrix.config.build_type }}" == "Debug" ]]; then - cmake -G "${{ matrix.config.generator }}" -S . -B build -DCMAKE_BUILD_TYPE=Debug -DGHC_COVERAGE=ON -DGHC_FILESYSTEM_TEST_COMPILE_FEATURES="${{ matrix.config.compatibility }}" -DCMAKE_INSTALL_PREFIX:PATH=install - else - cmake -G "${{ matrix.config.generator }}" -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} -DGHC_FILESYSTEM_TEST_COMPILE_FEATURES="${{ matrix.config.compatibility }}" -DCMAKE_INSTALL_PREFIX:PATH=install - fi + args=(-G "${{ matrix.config.generator }}" -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }}) + [[ "${{ matrix.config.build_type }}" == "Debug" ]] && args+=(-DGHC_COVERAGE=ON) + [[ -n "${{ matrix.config.msystem }}" ]] && args+=(-DGHC_FILESYSTEM_BUILD_STD_TESTING=NO) + args+=(-DCMAKE_INSTALL_PREFIX:PATH=install) + cmake "${args[@]}" - name: Build project shell: bash @@ -167,4 +197,3 @@ jobs: with: path-to-lcov: ${{ github.workspace }}/build/coverage.info github-token: ${{ secrets.GITHUB_TOKEN }} - From a2d86dbf31070b126493bb470d9afc56b2901eae Mon Sep 17 00:00:00 2001 From: 500-internal-server-error <76838083+500-internal-server-error@users.noreply.github.com> Date: Wed, 19 Feb 2025 21:35:08 +0700 Subject: [PATCH 4/7] Fix CI for Windows MSVC builds --- .github/workflows/build_cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_cmake.yml b/.github/workflows/build_cmake.yml index 1fc54b8..7e5bbd6 100644 --- a/.github/workflows/build_cmake.yml +++ b/.github/workflows/build_cmake.yml @@ -139,7 +139,7 @@ jobs: sudo apt install ${{ matrix.config.packages }} - name: Install dependencies on windows (MSVC) - if: startsWith(matrix.config.os, 'windows') + if: matrix.config.msystem == '' run: | choco install ${{ matrix.config.packages }} From e12be06b234a32efb29a17cb77fa70bd5bc4fbdb Mon Sep 17 00:00:00 2001 From: 500-internal-server-error <76838083+500-internal-server-error@users.noreply.github.com> Date: Wed, 19 Feb 2025 21:37:52 +0700 Subject: [PATCH 5/7] Fix CI --- .github/workflows/build_cmake.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_cmake.yml b/.github/workflows/build_cmake.yml index 7e5bbd6..33da26d 100644 --- a/.github/workflows/build_cmake.yml +++ b/.github/workflows/build_cmake.yml @@ -139,12 +139,12 @@ jobs: sudo apt install ${{ matrix.config.packages }} - name: Install dependencies on windows (MSVC) - if: matrix.config.msystem == '' + if: startsWith(matrix.config.os, 'windows') && matrix.config.msystem == '' run: | choco install ${{ matrix.config.packages }} - name: Install dependencies on windows (MSYS2) - if: matrix.config.msystem != '' + if: startsWith(matrix.config.os, 'windows') && matrix.config.msystem != '' uses: msys2/setup-msys2@v2 with: msystem: ${{ matrix.config.msystem }} From 6fe45fb5368ca006c65f0b8a2b1b5996bc182664 Mon Sep 17 00:00:00 2001 From: 500-internal-server-error <76838083+500-internal-server-error@users.noreply.github.com> Date: Wed, 19 Feb 2025 21:41:33 +0700 Subject: [PATCH 6/7] Fix CI for Windows MinGW builds --- .github/workflows/build_cmake.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_cmake.yml b/.github/workflows/build_cmake.yml index 33da26d..e45e448 100644 --- a/.github/workflows/build_cmake.yml +++ b/.github/workflows/build_cmake.yml @@ -97,7 +97,7 @@ jobs: msystem: ucrt64 build_type: Release build_std_testing: 'OFF' - packages: mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-ninja + packages: cmake gcc ninja generator: Ninja compatibility: "cxx_std_11;cxx_std_17;cxx_std_20" cc: gcc @@ -107,7 +107,7 @@ jobs: os: windows-2019 msystem: clang64 build_type: Release - packages: mingw-w64-clang-x86_64-cmake mingw-w64-clang-x86_64-clang mingw-w64-clang-x86_64-ninja + packages: cmake clang ninja generator: Ninja compatibility: "cxx_std_11;cxx_std_17;cxx_std_20" cc: clang From 300d4e0135673afb6703a1b36a034fdfe2e77a7f Mon Sep 17 00:00:00 2001 From: 500-internal-server-error <76838083+500-internal-server-error@users.noreply.github.com> Date: Wed, 19 Feb 2025 21:53:51 +0700 Subject: [PATCH 7/7] Fix CI for Windows MinGW builds --- .github/workflows/build_cmake.yml | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/.github/workflows/build_cmake.yml b/.github/workflows/build_cmake.yml index e45e448..10d2044 100644 --- a/.github/workflows/build_cmake.yml +++ b/.github/workflows/build_cmake.yml @@ -157,6 +157,7 @@ jobs: brew install ${{ matrix.config.packages }} - name: Configure project + if: matrix.config.msystem == '' shell: bash run: | export CC=${{ matrix.config.cc }} @@ -171,12 +172,43 @@ jobs: args+=(-DCMAKE_INSTALL_PREFIX:PATH=install) cmake "${args[@]}" + - name: Configure project (MSYS2) + if: matrix.config.msystem != '' + shell: msys2 {0} + run: | + export CC=${{ matrix.config.cc }} + export CXX=${{ matrix.config.cxx }} + ninja --version + cmake --version + mkdir build + mkdir install + args=(-G "${{ matrix.config.generator }}" -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }}) + [[ "${{ matrix.config.build_type }}" == "Debug" ]] && args+=(-DGHC_COVERAGE=ON) + [[ -n "${{ matrix.config.msystem }}" ]] && args+=(-DGHC_FILESYSTEM_BUILD_STD_TESTING=NO) + args+=(-DCMAKE_INSTALL_PREFIX:PATH=install) + cmake "${args[@]}" + - name: Build project + if: matrix.config.msystem == '' shell: bash run: | cmake --build build --config ${{ matrix.config.build_type }} + - name: Build project (MSYS2) + if: matrix.config.msystem != '' + shell: msys2 {0} + run: | + cmake --build build --config ${{ matrix.config.build_type }} + - name: Run tests + if: matrix.config.msystem == '' + shell: bash + run: | + cd build && ctest -C ${{ matrix.config.build_type }} + + - name: Run tests (MSYS2) + if: matrix.config.msystem != '' + shell: msys2 {0} run: | cd build && ctest -C ${{ matrix.config.build_type }}