-
Notifications
You must be signed in to change notification settings - Fork 471
revive the Windows port #344
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
Conversation
This is a partial patch, it still needs more work. But, it sets up a lot of the work that is needed. It also fixes cross-compilation on Linux to Windows. The assumption here is that you are using |
src/shims/tsd.h
Outdated
void *dispatch_deferred_items_key; | ||
}; | ||
|
||
extern __declspec(thread) struct dispatch_tsd __dispatch_tsd; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't you try to reuse DISPATCH_USE_THREAD_LOCAL_STORAGE
it's supposed to be the same trick, no? instead of duplicating the whole struct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, its actually the same exact structure too ... just didn't move things around to make it easier. I can do that.
I have to look at the patch more, and it's more than I can do in a timely fashion, but I've seen nothing shocking in there overall. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm an expert in neither Windows nor GCD, so I can't really comment. Nothing jumped out at me as wrong, but I also didn't understand a lot of it, like which things need to be marked stdcall
and which don't.
os/generic_win_base.h
Outdated
#define MAX(a,b) (((a)>(b))?(a):(b)) | ||
// Unicies provide `MIN` via sys/param.h | ||
#define MIN(a,b) (((a)<(b))?(a):(b)) | ||
// Unicies provide `howmany` via sys/param.h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: inconsistent between Unices
and Unicies
.
src/block.cpp
Outdated
@@ -69,7 +69,8 @@ struct dispatch_block_private_data_s { | |||
{ | |||
// copy constructor, create copy with retained references | |||
if (dbpd_voucher) voucher_retain(dbpd_voucher); | |||
if (o.dbpd_block) dbpd_block = _dispatch_Block_copy(o.dbpd_block); | |||
if (o.dbpd_block) dbpd_block = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use braces
@@ -32,7 +32,9 @@ | |||
#include <os/availability.h> | |||
#include <TargetConditionals.h> | |||
#include <os/base.h> | |||
#elif defined(__linux__) || defined(__FreeBSD__) | |||
#elif defined(_WIN32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should use TARGET_OS_WIN32
to be consistent with the rest of the tests I think
src/introspection.c
Outdated
@@ -137,7 +137,7 @@ _dispatch_introspection_thread_add(void) | |||
_dispatch_unfair_lock_unlock(&_dispatch_introspection.threads_lock); | |||
} | |||
|
|||
static void | |||
static __stdcall void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is __stdcall
defined by clang on darwin or linux?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get
<stdin>:1:6: warning: calling convention '__stdcall' ignored for this target
[-Wignored-attributes]
void __stdcall test();
^
So yeah, it might be something you want to guard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can control this by a macro
Updated to address the comments. This is further along now, with a lot more of the port formalized. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the review makes perfect sense to me, however I see a problem, where do you get TARGET_OS_WIN32
from? is there someone that defines it that I missed? os/object
uses _WIN32
as a guard but not the rest.
src/internal.h
Outdated
|
||
#if __GNUC__ | ||
#if __GNUC__ || defined(__clang__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#if defined(__GNUC__) || defined(__clang__)
would look better ;)
Oh, Good call on the style in |
There is a small amount of porting left: src/io.c (this previously was completely disabled). |
if TARGET_OS_WIN32 comes from the build system you can't have it in private.h or any header, you should use _WIN32 there, and then it is a question whether we need TARGET_OS_WIN32 at all, it seems confusing. TARGET_OS* comes from <TargetConditionals.h> which is a thing that Apple has when we build things on Windows platforms that's why it's this way. I don't think it should stay this way. have you ported all of event/event.c too? ;) because that part is the one that needs basically full reimplementation, unless windows supports kevent :P (not that it should block anything, but between having dispatch sources working and io.c I know what should be done first :P) |
so please get rid of TARGET_OS_WIN32 consistently, we use |
Hah, |
as far as kevent.c is, it's huge, but you should instead model it after |
So, the build should be complete at this point, the top patch is the only thing which I don't know how to formalize. But, the entire build now completes successfully :-) |
src/object_internal.h
Outdated
@@ -340,7 +340,7 @@ DISPATCH_ENUM(dispatch_invoke_flags, uint32_t, | |||
#define _DISPATCH_INVOKE_AUTORELEASE_MASK 0x00300000u | |||
); | |||
|
|||
enum { | |||
enum : unsigned long { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this syntax is not supported by C mode on clang I think, can you use DISPATCH_ENUM() instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Silence the enum assignment warning from clang. It is triggered by use of constants in macros that are not part of an enumeration when the parameter is of an enumerated type. This shows up when building for Windows. Rather than clutter the codebase with compiler specific macros to silence the warning, disable it.
The `DISPATCH_EXPORT` macro added an extraneous `extern` on the declaration. This was pointed out by a newer clang. Adjust the declaration accordingly. Add build rules to improve Windows builds. These additions help cross-compile to Windows with both clang-cl as well as the GNU clang driver. Use the newer Windows APIs to detect the windows CPU state. This allows us to collect all of the CPU configuration information to properly affinitise work to the preferred CPU. Use the FLS API to create thread local data storage for libdispatch's queues.
Windows uses signed enumerations by default rather than unsigned. This results in the values triggering warnings on Windows.
@swift-ci please test |
revive the Windows port Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
The
DISPATCH_EXPORT
macro added an extraneousextern
on thedeclaration. This was pointed out by a newer clang. Adjust the
declaration accordingly.
Add build rules to improve Windows builds. These additions help
cross-compile to Windows with both clang-cl as well as the GNU clang
driver.
Use the newer Windows APIs to detect the windows CPU state. This allows
us to collect all of the CPU configuration information to properly
affinitise work to the preferred CPU.
Use the FLS API to create thread local data storage for libdispatch's
queues.