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

Fix building on Windows with MSYS2 #192

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
77 changes: 69 additions & 8 deletions .github/workflows/build_cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: cmake gcc 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: cmake clang 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
Expand All @@ -116,17 +138,26 @@ jobs:
sudo apt update
sudo apt install ${{ matrix.config.packages }}

- name: Install dependencies on windows
if: startsWith(matrix.config.os, 'windows')
- name: Install dependencies on windows (MSVC)
if: startsWith(matrix.config.os, 'windows') && matrix.config.msystem == ''
run: |
choco install ${{ matrix.config.packages }}

- name: Install dependencies on windows (MSYS2)
if: startsWith(matrix.config.os, 'windows') && 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: |
brew install ${{ matrix.config.packages }}

- name: Configure project
if: matrix.config.msystem == ''
shell: bash
run: |
export CC=${{ matrix.config.cc }}
Expand All @@ -135,18 +166,49 @@ 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: 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 }}

Expand All @@ -167,4 +229,3 @@ jobs:
with:
path-to-lcov: ${{ github.workspace }}/build/coverage.info
github-token: ${{ secrets.GITHUB_TOKEN }}

4 changes: 2 additions & 2 deletions cmake/GhcHelper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<$<BOOL:${CYGWIN}>:-Wa,-mbig-obj>)
target_compile_options(${targetName} PRIVATE $<$<OR:$<BOOL:${CYGWIN}>,$<BOOL:${MINGW}>>:-Wa,-mbig-obj>)
target_compile_definitions(${targetName} PRIVATE USE_STD_FS)
endif()

Expand Down Expand Up @@ -69,7 +69,7 @@ macro(AddTestExecutableWithStdCpp cppStd)
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wpedantic -Werror -Wno-error=deprecated-declarations>
$<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wpedantic -Wno-psabi -Werror -Wno-error=deprecated-declarations>
$<$<CXX_COMPILER_ID:MSVC>:/WX /wd4996>
$<$<BOOL:${CYGWIN}>:-Wa,-mbig-obj>
$<$<OR:$<BOOL:${CYGWIN}>,$<BOOL:${MINGW}>>:-Wa,-mbig-obj>
$<$<BOOL:${GHC_COVERAGE}>:--coverage>)
if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
target_compile_definitions(filesystem_test_cpp${cppStd} PRIVATE _CRT_SECURE_NO_WARNINGS)
Expand Down
29 changes: 25 additions & 4 deletions include/ghc/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1941,15 +1941,15 @@ 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__)
#pragma warning(push)
#pragma warning(disable : 4191)
#endif
static CreateSymbolicLinkW_fp api_call = reinterpret_cast<CreateSymbolicLinkW_fp>(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)
Expand All @@ -1970,15 +1970,15 @@ 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__)
#pragma warning(push)
#pragma warning(disable : 4191)
#endif
static CreateHardLinkW_fp api_call = reinterpret_cast<CreateHardLinkW_fp>(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)
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -2152,6 +2159,10 @@ typedef struct _REPARSE_DATA_BUFFER
#endif
#endif

#if defined(__clang__) && defined(__MINGW32__)
#pragma clang diagnostic pop
#endif

template <class T>
struct free_deleter
{
Expand Down Expand Up @@ -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 <typename INFO>
GHC_INLINE uintmax_t hard_links_from_INFO(const INFO* info)
{
return static_cast<uintmax_t>(-1);
}

#if defined(__clang__) && defined(__MINGW32__)
#pragma clang diagnostic pop
#endif

template <>
GHC_INLINE uintmax_t hard_links_from_INFO<BY_HANDLE_FILE_INFORMATION>(const BY_HANDLE_FILE_INFORMATION* info)
{
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function(SetTestCompileOptions target_name)
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wpedantic -Werror -Wno-deprecated-declarations>
$<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wpedantic -Wno-psabi -Werror -Wno-deprecated-declarations>
$<$<CXX_COMPILER_ID:MSVC>:/WX /wd4996>
$<$<BOOL:${CYGWIN}>:-Wa,-mbig-obj>)
$<$<OR:$<BOOL:${CYGWIN}>,$<BOOL:${MINGW}>>:-Wa,-mbig-obj>)
endfunction()

if(GHC_COVERAGE)
Expand Down