Skip to content

[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

Merged
merged 1 commit into from
Jan 17, 2017

Conversation

tinysun212
Copy link
Contributor

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:

  • Test pull request on Swift continuous integration.

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

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

A smoke test on macOS does the following:

  1. Builds the compiler incrementally.
  2. Builds the standard library only for macOS. Simulator standard libraries and
    device standard libraries are not built.
  3. lldb is not built.
  4. The test and validation-test targets are run only for macOS. The optimized
    version of these tests are not run.

A smoke test on Linux does the following:

  1. Builds the compiler incrementally.
  2. Builds the standard library incrementally.
  3. lldb is built incrementally.
  4. The swift test and validation-test targets are run. The optimized version of these
    tests are not run.
  5. lldb is tested.

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

@tinysun212
Copy link
Contributor Author

@gribozavr, @compnerd, Please review this PR.


if waitpid(pid, statusPtr, 0) < 0 {
preconditionFailure("waitpid() failed")
}
Copy link
Contributor

@gribozavr gribozavr Jul 30, 2016

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.

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 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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@tinysun212 tinysun212 force-pushed the pr-stdlib-cygwin-3 branch from e03a455 to 2d5cf62 Compare July 30, 2016 12:17
@@ -320,6 +320,13 @@ module SwiftGlibc [system] {
}
% end

% if CMAKE_SDK in ["CYGWIN"]:
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@compnerd compnerd Aug 13, 2016

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.

Copy link
Contributor Author

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.

@tinysun212 tinysun212 force-pushed the pr-stdlib-cygwin-3 branch from 2d5cf62 to daca8f4 Compare July 31, 2016 05:41
#if CYGWIN
func asFdSetPtr(
_ p: UnsafeMutablePointer<UInt>?
) -> UnsafeMutablePointer<_types_fd_set>? {
Copy link
Contributor Author

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.

Copy link
Member

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)?

Copy link
Contributor Author

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 ...)

Copy link
Member

@compnerd compnerd Aug 14, 2016

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.

@@ -1437,6 +1438,8 @@ public enum OSVersion : CustomStringConvertible {
return "PS4"
case .android:
return "Android"
case .windows:
return "Windows"
Copy link
Contributor

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?

@gribozavr
Copy link
Contributor

@swift-ci Please test

@gribozavr
Copy link
Contributor

@tinysun212 Thank you! The changes LGTM modulo a small request to add a test for StdlibUnittest changes.

@tinysun212 tinysun212 force-pushed the pr-stdlib-cygwin-3 branch 3 times, most recently from 1c90d4d to 1bb1cd5 Compare August 12, 2016 21:07
@tinysun212
Copy link
Contributor Author

@gribozavr I changed for StdlibUnittest.

@CodaFi
Copy link
Contributor

CodaFi commented Aug 12, 2016

Dmitri is on vacation for a while. In the meantime, is there a reason you called this windowsCygnus and not cygwin or windowsCygwin?

@CodaFi
Copy link
Contributor

CodaFi commented Aug 12, 2016

@swift-ci please test OS X platform.

@tinysun212
Copy link
Contributor Author

It is only for the clear expression that Cygwin is related to Windows.
windowsCygnus is from the llvm target string, *-*-windows-cygnus.

I'm preparing a PR for MinGW, it will have windowsGnu which is analogous to *-*-windows-gnu, and they evaluate the TestRunPredicate .windowsAny to be true .

@CodaFi
Copy link
Contributor

CodaFi commented Aug 14, 2016

Ah, thanks. LGTM.

@swift-ci please test.

@tinysun212
Copy link
Contributor Author

validation-test/StdlibUnittest/Cygwin.swift was failed and patched.

@CodaFi
Copy link
Contributor

CodaFi commented Aug 14, 2016

Ok...

@swift-ci please smoke test OS X platform.

@tinysun212
Copy link
Contributor Author

@compnerd I applied your review, thanks.
@CodaFi Now I applied all of the reviews.

@@ -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)
Copy link
Member

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?

Copy link
Contributor Author

@tinysun212 tinysun212 Aug 16, 2016

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 ?

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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 ?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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).

Copy link
Member

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!

@CodaFi
Copy link
Contributor

CodaFi commented Aug 19, 2016

In the meantime @tinysun212, could you please rebase again?

tinysun212 added a commit to tinysun212/swift-windows that referenced this pull request Aug 19, 2016
Patched for compnerd review in PR swiftlang#3886.
@CodaFi
Copy link
Contributor

CodaFi commented Aug 23, 2016

@swift-ci please smoke test macOS platform.

@swift-ci
Copy link
Contributor

swift-ci commented Oct 4, 2016

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 29af0ca6b110eac3f8531510a15faaac5fcd6c31
Test requested by - @moiseev

@tinysun212
Copy link
Contributor Author

In the building console of Swift Test OS X Platform, there is a liking error for Benchmark_Onone-arm64-apple-ios8.0.
Does it caused by this changes?

@moiseev
Copy link
Contributor

moiseev commented Oct 4, 2016

@tinysun212 I don't think this change is responsible for the failure. Let's try again.
@swift-ci Please smoke test macOS platform

@moiseev
Copy link
Contributor

moiseev commented Oct 5, 2016

@swift-ci Please smoke test macOS platform

@tinysun212
Copy link
Contributor Author

I found a strange message in the CI test log.

pull request #35 from tinysun212/pr-cygwin-1, what is this?, I don't have the PR of number 35.

11:21:11 + git fetch --recurse-submodules=yes
11:21:12 + git clean -fdx
11:21:12 + git submodule foreach --recursive git clean -fdx
11:21:12 + git submodule foreach --recursive git reset --hard HEAD
11:21:12 + git reset --hard HEAD
11:21:12 HEAD is now at c324ee3 Merge pull request #35 from tinysun212/pr-cygwin-1
11:21:12 + git checkout master
11:21:12 Already on 'master'
11:21:12 Your branch is up-to-date with 'origin/master'.
11:21:12 + git reset --hard origin/master
11:21:12 HEAD is now at c324ee3 Merge pull request #35 from tinysun212/pr-cygwin-1
11:21:12 + git fetch --recurse-submodules=yes
11:21:12 + git clean -fdx
11:21:13 + git submodule foreach --recursive git clean -fdx
11:21:13 + git submodule foreach --recursive git reset --hard HEAD
11:21:13 + git reset --hard HEAD
11:21:13 HEAD is now at 5af77f3 Merge pull request #95 from kainjow/master

@tinysun212
Copy link
Contributor Author

Anyway, I rebased to most recent commit.
I tested on macOS with build-script.sh -R -t, couldn't see any failed message.
Please test again ?

@shahmishal
Copy link
Member

@tinysun212 Do you have the CI build link where you saw this message?

@tinysun212
Copy link
Contributor Author

Yes, here.

@shahmishal
Copy link
Member

shahmishal commented Oct 8, 2016

@tinysun212 this came from ToT llbuild repo, looks like this was merged recently. (Not really recently, but ToT)

swiftlang/swift-llbuild#35

@tinysun212
Copy link
Contributor Author

That was my PR, I can remember now, I'm sorry I forgot it. The CI build log displayed it under the line
From https://github.com/apple/swift-llvm, so I couldn't think about that.

Although that was not the cause of the fail of tests, please smoke test again?

@shahmishal
Copy link
Member

@swift-ci Please smoke test

@tinysun212
Copy link
Contributor Author

This time, the error is caused by duplicating glibc modulemap changes with #5131 which was merged 1 hour ago. I'll soon resolve this.

@tinysun212
Copy link
Contributor Author

Resolving the duplicate, I rebased and merged to one commit.

@tinysun212
Copy link
Contributor Author

please test

@gparker42
Copy link
Contributor

@swift-ci Please test

@slavapestov
Copy link
Contributor

@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 slavapestov self-assigned this Jan 11, 2017
@tinysun212
Copy link
Contributor Author

@slavapestov I will resolve this PR this weekend.

@slavapestov
Copy link
Contributor

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
@slavapestov
Copy link
Contributor

@swift-ci Please test

@slavapestov slavapestov merged commit 928a319 into swiftlang:master Jan 17, 2017
@@ -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)
Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

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

And here

@tinysun212 tinysun212 deleted the pr-stdlib-cygwin-3 branch October 21, 2018 01:11
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.

9 participants