Skip to content
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

Add #if os(Darwin) shorthand for checking for Darwin platforms #59426

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Add #if os(Darwin) shorthand for checking for Darwin platforms #59426

wants to merge 8 commits into from

Conversation

NSAntoine
Copy link
Contributor

This PR adds support for Darwin as a platform that can be used in a #if os statement, so the following code:

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#endif

You could instead do:

#if os(Darwin)
import Darwin
#endif

@NSAntoine NSAntoine marked this pull request as draft June 14, 2022 09:57
@NSAntoine
Copy link
Contributor Author

@hamishknight Looks good ^? Could you ask it to test?

lib/Basic/LangOptions.cpp Outdated Show resolved Hide resolved
lib/Basic/LangOptions.cpp Outdated Show resolved Hide resolved
…test compiler invokation, call OSX on checkPlatformCondition rather than macOS
@NSAntoine
Copy link
Contributor Author

@hamishknight look all good?

@hamishknight
Copy link
Contributor

@swift-ci please test

@NSAntoine
Copy link
Contributor Author

@hamishknight looks like we couldn't use types from the stdlib, fixed that, could you ask it to test again?

@hamishknight
Copy link
Contributor

Yeah -parse-stdlib disables the implicit stdlib import as it's primarily used for building the standard library

@swift-ci please test

@NSAntoine
Copy link
Contributor Author

@AnthonyLatsis did Linux just immediately fail?

@hamishknight
Copy link
Contributor

@swift-ci please test Linux

@hamishknight
Copy link
Contributor

Probably just Jenkins flakiness

@NSAntoine
Copy link
Contributor Author

@hamishknight seems it’s working, could you ask it to build a toolchain?

@hamishknight
Copy link
Contributor

@swift-ci please build toolchain

@NSAntoine NSAntoine marked this pull request as ready for review June 14, 2022 23:45
@NSAntoine
Copy link
Contributor Author

Works locally :)

@NSAntoine
Copy link
Contributor Author

@hamishknight Ready for merge now?

@NSAntoine NSAntoine changed the title [WIP] Add #if os support for a generic Darwin platform Add #if os(Darwin) shorthand for checking for Darwin platforms Jun 15, 2022
@hamishknight
Copy link
Contributor

Implementation looks good to me, though I think this will probably require evolution discussion before being merged.

@hamishknight hamishknight added the swift evolution pending discussion Flag → feature: A feature that has a Swift evolution proposal currently in review label Jun 15, 2022
@NSAntoine
Copy link
Contributor Author

Implementation looks good to me, though I think this will probably require evolution discussion before being merged.

I’ve opened a discussion post here, one thing I was considering was @available support aswell but that doesn’t seem too reasonable considering that most devs don’t know the Darwin-XNU version numbers for each release, what do you think?

@hamishknight
Copy link
Contributor

hamishknight commented Jun 15, 2022

Yeah, note you would also need a way to map the Darwin version numbers to the individual platform version numbers, which I'm not sure we'd want to bake into the compiler. FWIW we use availability macros (e.g SwiftStdlib 5.7) for this kind of purpose in the stdlib. These mappings are defined in https://github.com/apple/swift/blob/main/utils/availability-macros.def, and are passed as compiler arguments when compiling the stdlib specifically, so aren't a hardcoded feature of the compiler. See https://github.com/apple/swift/blob/649889fd5e566ad18c6bb27258a1e11b5df96421/docs/StandardLibraryProgrammersManual.md#availability.

@CodaFi
Copy link
Contributor

CodaFi commented Jun 16, 2022

Thank you for tackling this!

lib/Basic/LangOptions.cpp Outdated Show resolved Hide resolved
@NSAntoine
Copy link
Contributor Author

@CodaFi Could you ask CI to test?

@CodaFi
Copy link
Contributor

CodaFi commented Jun 18, 2022

@swift-ci smoke test

@NSAntoine
Copy link
Contributor Author

@CodaFi Works great! Thanks for letting me know of that method, all that's left now is for the proposal to be reviewed & approved, which I just opened yesterday

@NSAntoine NSAntoine closed this by deleting the head repository Oct 19, 2022
@NSAntoine
Copy link
Contributor Author

mistake^

@NSAntoine NSAntoine reopened this Oct 20, 2022
@CodaFi
Copy link
Contributor

CodaFi commented Oct 21, 2022

It's been a while so let's re-test this

@swift-ci smoke test

@NSAntoine
Copy link
Contributor Author

is ci borked

@CodaFi
Copy link
Contributor

CodaFi commented Oct 21, 2022

The trigger I used picked up my words and tried to interpret them as a repository.

@CodaFi
Copy link
Contributor

CodaFi commented Oct 21, 2022

@swift-ci smoke test

@al45tair
Copy link
Contributor

al45tair commented Apr 18, 2024

I think we should exclude DriverKit from #if os(Darwin), since it's quite different from the other platforms currently covered by Target.isOSDarwin(). (I would comment on the source line in question, but I get an error from Github when I try that.)

i.e. instead of Target.isOSDarwin(), it should be Target.isOSDarwin() && !Target.isDriverKit(), I think.

@NSAntoine
Copy link
Contributor Author

I think we should exclude DriverKit from #if os(Darwin), since it's quite different from the other platforms currently covered by Target.isOSDarwin(). (I would comment on the source line in question, but I get an error from Github when I try that.)

i.e. instead of Target.isOSDarwin(), it should be Target.isOSDarwin() && !Target.isDriverKit(), I think.

The pr is dead. Though I agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
swift evolution pending discussion Flag → feature: A feature that has a Swift evolution proposal currently in review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants