Skip to content

Support compiling on MSYS2 #814

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

Merged
merged 2 commits into from
Feb 19, 2024
Merged

Conversation

qmfrederik
Copy link
Contributor

This patch consists of two commits:

  • The first commit contains a minimal set of changes to make libdispatch compile on the MSYS2 environments. There are slight differences in headers, which are accounted for, and the -fms-extensions variable is passed to clang to enable the __popcnt64 intrinsic
  • The second commit adds a GitHub actions job to validate the changes

If this project doesn't want to use GitHub actions, I can remove the second commit.

@@ -1,6 +1,8 @@

if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC" OR MINGW)
# TODO: someone needs to provide the msvc equivalent warning flags
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this project compiles on Windows using clang-cl. In that case, all of the compiler options defined below can be passed to the clang-cl compiler. That surfaces a bunch of warnings, which could be fixed in a follow-up PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, -fms-extensions are non-conforming extensions and we should not be enabling them. If MinGW requires that, then it should be done under a MINGW specific clause.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need -fms-extensions because __popcnt64 is used in hw_config.h. That's a Microsoft-specific extension.

The source code, as it stands, requires this Microsoft-specific extension when targeting the Windows platform. I assume you don't need to make it explicit on Windows because you're using clang-cl (which enables -fms-extensions by default), or the MSVC compiler.

I think the proper condition is "when targeting Windows but not using a MSVC-compatible compiler`, let me try to refine that if clause.

Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub Actions can't be used on repositories in this org, so the workflow file would have to be removed before this can be reviewed.

@qmfrederik
Copy link
Contributor Author

@MaxDesiatov Roger that, removed the GitHub actions.

@@ -1,6 +1,8 @@

if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC" OR MINGW)
# TODO: someone needs to provide the msvc equivalent warning flags
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, -fms-extensions are non-conforming extensions and we should not be enabling them. If MinGW requires that, then it should be done under a MINGW specific clause.

@@ -24,7 +24,10 @@
// Unices provide `howmany` via sys/param.h
#define howmany(x, y) (((x) + ((y) - 1)) / (y))

#ifndef _MODE_T_
#define _MODE_T_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no generic way to avoid this? I'd rather not encode the macro that MinGW uses for this into the header. Why not hoist this into a check in CMake and use HAVE_MODE_T instead?

@@ -7,7 +7,9 @@
#include <Windows.h>

typedef int kern_return_t;
#ifndef _PID_T_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar

@MaxDesiatov MaxDesiatov dismissed their stale review February 15, 2024 19:27

Dismissing the change request as feedback was addressed.

@qmfrederik
Copy link
Contributor Author

@compnerd I've used CMake checks for pid_t and mode_t, and refined the usage of -fms-extensions. Let me know if this helps.

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@compnerd
Copy link
Member

@swift-ci please test

@qmfrederik
Copy link
Contributor Author

@MaxDesiatov
Copy link
Contributor

@swift-ci test windows

@compnerd compnerd merged commit 5529d35 into swiftlang:main Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants