-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] Fixed for Cygwin #3886
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
@gribozavr, @compnerd, Please review this PR. |
|
||
if waitpid(pid, statusPtr, 0) < 0 { | ||
preconditionFailure("waitpid() failed") | ||
} |
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.
Sorry, could you explain how does this work? Why does the system waitpid()
function need a Swift box? It would help if you could paste the imported signature of waitpid()
on your system.
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 captured the signature in /usr/include/sys/wait.h
on Cygwin.
/* Allow `int' and `union wait' for the status. */
typedef union
{
int *__int_ptr;
union wait *__union_wait_ptr;
} __wait_status_ptr_t __attribute__ ((__transparent_union__));
pid_t waitpid (pid_t __pid, __wait_status_ptr_t __status, int __options);
I'll be happy if someone suggests any simpler way.
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.
withUnsafePointer(to: status) {
statusPtr in
let statusPtrWrapper = __wait_status_ptr_t(__int_ptr: statusPtr)
waitpid(pid, statusPtrWrapper, 0)
}
should work I think.
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.
It is successfully compiled after 1st line is changed to withUnsafeMutablePointer(&status) {
.
The compiler taught me how to change. Thank you.
e03a455
to
2d5cf62
Compare
@@ -320,6 +320,13 @@ module SwiftGlibc [system] { | |||
} | |||
% end | |||
|
|||
% if CMAKE_SDK in ["CYGWIN"]: |
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.
Why limit this to CYGWIN?
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.
Foundation's ./Foundation/NSFileHandle.swift
uses Glibc's L_SET
, L_INCR
, L_XTND
. In Linux, it is enough only include unistd.h
, but Cygwin's unistd.h
doesn't define them.
To support L_xxx macro, Cygwin should include sys/file.h
which defines them. But other platforms which already support Foundation would already have the definitions.
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 think that we can just include module on all targets which have the header.
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.
OK. I'll change this.
2d5cf62
to
daca8f4
Compare
#if CYGWIN | ||
func asFdSetPtr( | ||
_ p: UnsafeMutablePointer<UInt>? | ||
) -> UnsafeMutablePointer<_types_fd_set>? { |
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.
Updating to 7/29 snapshot, I added new patches.
BTW, I don't know why this is differ to Linux.
The definition part in sys/select.h
is as follows.
typedef struct _types_fd_set {
fd_mask fds_bits[_howmany(FD_SETSIZE, NFDBITS)];
} _types_fd_set;
#define fd_set _types_fd_set
fd_set
did not work, but _types_fd_set
worked.
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.
Probably because we are dropping the aliasing in the clang import. Can you please file a SR and send it my way with a tiny test case (something like creating a function which uses fd_set
)?
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.
Could you explain some more detail, please? (dropping aliasing, tiny test case ...)
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. The clang-importer will ignore the #define
based aliasing as its not a real type alias, but rather a token replacement via the preprocessor. The result is that the module does not contain a definition for fd_set
although, we should. We could handle simple token replacements which replace type aliased names with an additional type alias. This would allow us to use the definition.
After writing out this explanation, Im left wondering, why don't we work around this for now with:
typealias fd_set = _types_fd_set
As to the test case, a simple swift file which demonstrates the lost type alias so that we could have a test case for this is what I was asking for. Something like this should do the trick:
#ifndef MODULE_H
#define MODULE_H
typedef struct s { int i; } _s;
#define s _s
#endif
import module
let _ = s(32)
This would currently fail as the type alias of s would be dropped, and is entirely standalone.
daca8f4
to
bbe021e
Compare
@@ -1437,6 +1438,8 @@ public enum OSVersion : CustomStringConvertible { | |||
return "PS4" | |||
case .android: | |||
return "Android" | |||
case .windows: | |||
return "Windows" |
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.
For this change to StdlibUnittest, would you mind adding a test like validation-test/StdlibUnittest/Linux.swift
?
@swift-ci Please test |
@tinysun212 Thank you! The changes LGTM modulo a small request to add a test for StdlibUnittest changes. |
1c90d4d
to
1bb1cd5
Compare
@gribozavr I changed for StdlibUnittest. |
Dmitri is on vacation for a while. In the meantime, is there a reason you called this |
@swift-ci please test OS X platform. |
It is only for the clear expression that Cygwin is related to Windows. I'm preparing a PR for MinGW, it will have |
Ah, thanks. LGTM. @swift-ci please test. |
1bb1cd5
to
229d968
Compare
|
Ok... @swift-ci please smoke test OS X platform. |
@@ -2,7 +2,7 @@ | |||
// REQUIRES: executable_test | |||
|
|||
import StdlibUnittest | |||
#if os(Linux) || os(FreeBSD) || os(PS4) || os(Android) | |||
#if os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Windows) |
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.
Doesn't this break on MSVC hosts?
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.
Not tested on windows-msvc. Only tested on Cygwin, and I believe it will be passed for MinGW.
Did you build an alternatives to Glibc for MSVC ?
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.
Yes, msvcrt :-). Its a swift wrapper for ucrt and visualc.
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.
Would you change after this PR?
I think the code would be like this.
#if os(Windows) && MSVC
import Ucrt
import VisualC
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Windows)
import Glibc
#else
import Darwin
#endif
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.
@compnerd Could you share the build script (or manual) for MSVC ?
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 build on Linux. Just set INCLUDE and LIB as per Windows (adjust them for the movement from C:\ to whatever you're using) and add WINDOWS to the targets to build. I can give you my cmake/ninja invocation later when I'm near a computer.
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 just do the following:
add -DSWIFT_SDKS="LINUX;WINDOWS" -DCMAKE_AR=$(which llvm-ar) -DCMAKE_RANLIB=$(which llvm-ranlib) -DSWIFT_WINDOWS_ICU_I18N_INCLUDE=${SWIFT_TOP_SRCDIR}/build/icu/source/i18n -DSWIFT_WINDOWS_ICU_UC_INCLUDE=${SWIFT_TOP_SRCDIR}/build/icu/source/common
via --extra-cmake-options
You need to make sure that ld.lld is available to your toolchain, as building for Windows (MSVC) on !Windows will enable lld.
Additionally, I have the following environment variables setup:
INCLUDE='${SDK_TOP_SRCDIR}/Microsoft Visual Studio 14.0/VC/include;${SDK_TOP_SRCDIR}/Windows Kits/10/Include/10.0.10586.0/ucrt;${SDK_TOP_SRCDIR}/Windows Kits/10/Include/10.0.10586.0/um;${SDK_TOP_SRCDIR}/Windows Kits/10/Include/10.0.10586.0/shared'
LIB='${SDK_TOP_SRCDIR}/Microsoft Visual Studio 14.0/VC/lib;${SDK_TOP_SRCDIR}/Windows Kits/10/Lib/10.0.10586.0/ucrt/x86;${SDK_TOP_SRCDIR}/Windows Kits/10/Lib/10.0.10586.0/um/x86'
Within those paths which are directly lifted from a windows SDK installation, I have two symlinks constructed: ${SDK_TOP_SRCDIR}/Microsoft Visual Studio 14.0/VC/include/module.map -> ${SWIFT_TOP_SRCDIR}/swift/stdlib/public/Platform/visualc.modulemap
${SDK_TOP_SRCDIR}/Windows Kits/10/Include/10.0.10586.0/ucrt -> ${SWIFT_TOP_SRCDIR}/swift/stdlib/public/Platform/ucrt.modulemap
The import libraries for ICU are in the build directory as well. That tends to be sufficient to cross-compile from Linux x86_64 to Windows x86.
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.
Thanks you.
Did you use the swift/clang compiler for Linux ?
I'll run those on my Linux machine.
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.
Yeah, Ive been doing the entire build on Linux (and should be pretty trivial to reproduce on Darwin).
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 still breaks the non-cygwin case :/ You never addressed this!
In the meantime @tinysun212, could you please rebase again? |
c341902
to
f400376
Compare
Patched for compnerd review in PR swiftlang#3886.
@swift-ci please smoke test macOS platform. |
Build failed |
In the building console of Swift Test OS X Platform, there is a liking error for |
@tinysun212 I don't think this change is responsible for the failure. Let's try again. |
@swift-ci Please smoke test macOS platform |
29af0ca
to
a78eb04
Compare
I found a strange message in the CI test log.
|
Anyway, I rebased to most recent commit. |
@tinysun212 Do you have the CI build link where you saw this message? |
Yes, here. |
@tinysun212 this came from ToT llbuild repo, looks like this was merged recently. (Not really recently, but ToT) |
That was my PR, I can remember now, I'm sorry I forgot it. The CI build log displayed it under the line Although that was not the cause of the fail of tests, please smoke test again? |
@swift-ci Please smoke test |
This time, the error is caused by duplicating glibc modulemap changes with #5131 which was merged 1 hour ago. I'll soon resolve this. |
a78eb04
to
f43b97e
Compare
Resolving the duplicate, I rebased and merged to one commit. |
please test |
@swift-ci Please test |
@tinysun212 Sorry for dropping the ball on this PR. Do you mind rebasing and fixing the merge conflicts so that we can get this merged in? |
@slavapestov I will resolve this PR this weekend. |
Thanks! |
- CYGWIN symbol is used to distinguish Cygwin environment from other OS and other environment in Windows. - Added windows and windowsCygnus to OSVersion in StdlibUnittest
f43b97e
to
a8dec7f
Compare
@swift-ci Please test |
@@ -2,7 +2,7 @@ | |||
// REQUIRES: executable_test | |||
|
|||
import StdlibUnittest | |||
#if os(Linux) || os(FreeBSD) || os(PS4) || os(Android) | |||
#if os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Windows) |
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.
Doesnt os(Windows)
evaluate true for MSVC builds? This breaks Windows.
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.
os(Windows) is true for MSVC, MinGW, Cygwin.
@@ -2,7 +2,7 @@ | |||
// REQUIRES: executable_test | |||
|
|||
import StdlibUnittest | |||
#if os(Linux) || os(FreeBSD) || os(PS4) || os(Android) | |||
#if os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Windows) |
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.
Same.
@@ -6,7 +6,7 @@ import StdlibUnittest | |||
|
|||
#if os(OSX) || os(iOS) || os(tvOS) || os(watchOS) | |||
import Darwin | |||
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) | |||
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Windows) |
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.
And here
What's in this pull request?
I submitted PR #2351 which has stdlib patch for Cygwin, but it is not merged since
os(Cygwin)
is not widely accepted. Now the conditional variable CYGWIN can be used for the files of *.swift and *.swift.gyb.This PR uses CYGWIN instead of the previous unaccepted symbol and has more patch.
Resolved bug number: (SR-)
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
A smoke test on macOS does the following:
device standard libraries are not built.
version of these tests are not run.
A smoke test on Linux does the following:
tests are not run.
Validation Testing
Lint Testing
Note: Only members of the Apple organization can trigger swift-ci.