Skip to content

basic: introduce the _environment compilation conditional #3337

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

@compnerd compnerd commented Jul 4, 2016

What's in this pull request?

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

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.

Windows has multiple environment flavours, each of which are different. cygwin
provides a glibc based environment, MinGW provides a msvcrt based GNU
environment, itanium provides a msvc environment with an itanium C++ ABI, and
msvc is the pure msvc, msvcprt based environment as vended by Microsoft. Due to
the differences in the environment, we need a means to differentiate them at the
stdlib level. Provide the _environment conditional which would allow you to
query what environment is being targeted.

@compnerd
Copy link
Member Author

compnerd commented Jul 4, 2016

CC: @jrose-apple

@compnerd
Copy link
Member Author

compnerd commented Jul 4, 2016

@swift-ci Please test

switch (Target.getEnvironment()) {
default: break;
case llvm::Triple::MSVC:
addPlatformConditionValue("_environment", "msvc");
Copy link
Contributor

@gribozavr gribozavr Jul 5, 2016

Choose a reason for hiding this comment

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

Please add tests for these values to appropriate files in test/Parse/ConditionalCompilation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Im confused. How is the test below now sufficient?

Windows has multiple environment flavours, each of which are different.  cygwin
provides a glibc based environment, MinGW provides a msvcrt based GNU
environment, itanium provides a msvc environment with an itanium C++ ABI, and
msvc is the pure msvc, msvcprt based environment as vended by Microsoft.  Due to
the differences in the environment, we need a means to differentiate them at the
stdlib level.  Provide the _environment conditional which would allow you to
query what environment is being targeted.
@jrose-apple
Copy link
Contributor

I'd rather not accept this right now unless we absolutely need it. Otherwise, it's worth actually going through swift-evolution and figuring out what os(…) means and what's going to be above or below that.

@compnerd
Copy link
Member Author

compnerd commented Jul 5, 2016

@jrose-apple without this, unfortunately, it means that we can't do a windows port without breaking cygwin. Could we do both?

@jrose-apple
Copy link
Contributor

jrose-apple commented Jul 5, 2016

Can you elaborate? What's something where the standard library needs different behavior between MSVC and Cygwin?

@compnerd
Copy link
Member Author

compnerd commented Jul 5, 2016

Sure, there are cases where certain functions are available on cygwin and not in MSVCRT. Other cases are where they are just different. Because that may be a bit vague, lets take concrete examples:

Just different:
errno: __errno() on cygwin, _errno() on msvcrt.

Unavailable:
lgamma_r on cygwin, not available on msvcrt.

@jrose-apple
Copy link
Contributor

Hm, got it.

I really don't want to introduce this because people will immediately start using it outside of the standard library.

@compnerd
Copy link
Member Author

compnerd commented Jul 5, 2016

Im open to alternative suggestions. I don't know how long it would take to get through everything with the swift-evolution (especially since Ive not gone through it previously).

@jrose-apple
Copy link
Contributor

Well, there's the hack of moving things into a C function for the few things that are different.

@compnerd
Copy link
Member Author

compnerd commented Jul 6, 2016

What about the larger pieces like pthread (available on cygwin, not on msvc)?

@karwa
Copy link
Contributor

karwa commented Jul 6, 2016

What about putting it behind a compiler flag? We already have one for the standard library, could it maybe fit inside -parse-stdlib?

@jrose-apple
Copy link
Contributor

If we really just want a workaround, we could also use an ad hoc -D flag.

@compnerd
Copy link
Member Author

compnerd commented Jul 7, 2016

Sure, the ad-hoc -D flag sounds like it should be sufficient for now. I think that we should work out a proper environment check though.

@jrose-apple
Copy link
Contributor

Definitely. May be worth starting a thread on swift-dev with @karwa and @hpux735? Then someone can write it up as a proper proposal for swift-evolution, and we can consider prototyping it during that time as well.

@jrose-apple
Copy link
Contributor

Oops, and @tinysun212.

@tinysun212
Copy link
Contributor

Thanks for your mention.

I started similar discussion in #2351 and swift-evolution, but it is discontinued.
I am positive to the approach in this PR, it will be useful for Foundation porting as well as standard library porting.

I tried ad hoc -D flag in Foundation PR. In there, the code is like this.

#if os(OSX) || os(iOS)
    import Darwin
#elseif os(Linux) || IS_CYGWIN
    import Glibc
#endif

I think if we use the method 'ad hoc -D flag', we need the convention for the macro name.

@compnerd
Copy link
Member Author

compnerd commented Jul 8, 2016

Ill definitely bring this up again. I used CYGWIN, as I don't want to break cygwin support as Im adding MSVCRT support. I have the work available on my own fork of the repository, and will be sending out a PR for a good chunk of it soon.

@compnerd compnerd closed this Jul 8, 2016
@compnerd compnerd deleted the environment branch July 8, 2016 06:58
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