Skip to content

WIP/Foundation: port to Windows #1812

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

Closed
wants to merge 1 commit into from

Conversation

compnerd
Copy link
Member

Unformalised changes to port Foundation to Windows

@@ -374,9 +374,13 @@ internal extension _EasyHandle {
/// errno number from last connect failure
/// - SeeAlso: https://curl.haxx.se/libcurl/c/CURLINFO_OS_ERRNO.html
var connectFailureErrno: Int {
#if os(Windows) && arch(x86_64)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is ARM64 also LLP64? Probably a good idea to audit anywhere Windows+x86_64 is mentioned and see if it applies to ARM64 as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's a good point. Windows AArch64 is LLP64 as well, and we should account for that. I believe that I did that properly in the swift side and even the CoreFoundation side. This is still just a bunch of changes to make sure build/fill in the holes. It's going to require a second pass to actually formalise this into a patch set.

@compnerd compnerd force-pushed the windows-foundation branch 2 times, most recently from e0e512c to 27d6f2f Compare December 20, 2018 05:16
@compnerd compnerd force-pushed the windows-foundation branch from 27d6f2f to cde8f3c Compare January 8, 2019 06:53
@compnerd
Copy link
Member Author

compnerd commented Jan 9, 2019

Okay, so, at this point, NSFileManager, NSHost, and NSProcess are the remaining holes in Foundation for Windows. NSFileManager has a pretty large API set that needs to be adjusted for Windows and is the one that I am currently working on. The API surface being large and the API differences makes this slightly more challenging, but, hopefully I can work through that. I imagine that NSHost might be similarly challenging as it has a fair number of interfaces for querying information network information which will need to be completely redone.

@parkera
Copy link
Contributor

parkera commented Jan 9, 2019

What do you have in mind for adjustments to the NSFileManager API?

@compnerd compnerd force-pushed the windows-foundation branch 2 times, most recently from 5a28a40 to 78a599e Compare January 9, 2019 15:43
@compnerd
Copy link
Member Author

compnerd commented Jan 9, 2019

@parkera - NSFileManager, NSHost, NSProcess, and NSTask need some fairly heavy changes unfortunately as the API is pretty different. I've pushed my local state to this branch, which is by no means ready. But, you can see the extent of the changes. As a particular example, symlink, readlink, link are not available on Windows under those names or semantics. There are equivalences now with CreateSymLink (which requires a RS3 or newer distribution of Windows, but I think that won't be too big of a deal, otherwise, you get a UAC prompt) etc, but they require a different implementation.

@parkera
Copy link
Contributor

parkera commented Jan 9, 2019

Different implementations are totally fine, and even making certain API unavailable on Windows, although unfortunate, does make sense if the concept is totally unportable. What I want to make sure of is that you don't feel like you need to change the outward facing API, so that clients can remain source compatible when porting.

Glancing at what you've got here so far seems like we're ok on that front.

Copy link
Contributor

@phausler phausler left a comment

Choose a reason for hiding this comment

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

There are a number of places that use some unsafe inner pointer usages for strings that need to be corrected. For the code base we like to keep it 4 space indents (not indented extra when in #ifdefs) and no line wrapping unless it is truly absurd. (The formatting is not a full blocker but would be nice).

#endif

import CoreFoundation

internal func __NSDataInvokeDeallocatorUnmap(_ mem: UnsafeMutableRawPointer, _ length: Int) {
#if os(Windows)
UnmapViewOfFile(mem)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we make sure to keep the indentation consistent? this seems like it has an extra depth past the 4 space.

Copy link
Member Author

Choose a reason for hiding this comment

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

This patch is absolutely atrocious in terms of indentation. I was playing around with Visual Studio and doing most of this in vim, so, its just an absolute disaster. This is going to require me to go through and fix that, which I don't think is worth it until I think that I have enough of this covered to break this into something more digestible. This should definitely not go in as is.

@compnerd
Copy link
Member Author

compnerd commented Jan 9, 2019

@parkera I think that most of the interfaces can be preserved, and that is something that I really would like to keep. I think that it really is important that as much of the API surface be the same as possible so that there is some possibility of portability of code.

@compnerd compnerd force-pushed the windows-foundation branch 2 times, most recently from fee503e to e267ca9 Compare January 14, 2019 04:59
@compnerd compnerd force-pushed the windows-foundation branch 3 times, most recently from 7265aee to 59f0767 Compare January 18, 2019 17:49
@compnerd compnerd force-pushed the windows-foundation branch 8 times, most recently from 030f4f8 to 618a404 Compare January 26, 2019 21:35
@compnerd compnerd force-pushed the windows-foundation branch 4 times, most recently from c24abe5 to b9dbf30 Compare January 29, 2019 02:06
@compnerd compnerd force-pushed the windows-foundation branch 2 times, most recently from fa2c993 to 0292783 Compare January 31, 2019 04:26
@compnerd compnerd force-pushed the windows-foundation branch 7 times, most recently from 3ab18f9 to e8c24da Compare February 14, 2019 21:22
@@ -82,6 +96,8 @@ open class FileManager : NSObject {
}
urls = mountPoints(statBuf, Int(fsCount))
}
#elseif os(Windows)
return nil
Copy link
Member Author

Choose a reason for hiding this comment

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

Bleh, this seems wrong. This should be changed to throw NSUnimplemented at the very least

Unformalised changes to port Foundation to Windows
@compnerd
Copy link
Member Author

Time to say goodbye to this PR. The only thing of use left is the -DLIBCURL_STATIC which has a whole different conversation to be had. The remaining FileManager interfaces need to be implemented, but that requires recreating the FTS semantics, so they are stubbed out for now. I've fixed the blocks issue in clang, so we have the foriegn class import (need to runtime generate it as it may be cross-module) and the root protocol conformance handling (need to runtime generate as the chained protocol witness table may be module external) to look into preventing this single line change from being useful just yet.

@compnerd compnerd closed this Feb 23, 2019
@compnerd compnerd deleted the windows-foundation branch February 23, 2019 03:12
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.

5 participants