mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Add support for conditional compilation under macCatalyst
Developers can now detect whether they are compiling for macCatalyst at
compile time with:
#if targetEnvironment(macCatalyst)
// Code only compiled under macCatalyst.
#end
37 lines
1.3 KiB
Swift
37 lines
1.3 KiB
Swift
// RUN: %swift -swift-version 4 -typecheck %s -verify -target x86_64-apple-ios12.0-macabi -parse-stdlib
|
|
// RUN: %swift-ide-test -swift-version 4 -test-input-complete -source-filename=%s -target x86_64-apple-ios12.0-macabi
|
|
|
|
// REQUIRES: OS=maccatalyst
|
|
|
|
#if targetEnvironment(macabi) // expected-warning {{'macabi' has been renamed to 'macCatalyst'}} {{23-29=macCatalyst}}
|
|
func underMacABI() {
|
|
foo() // expected-error {{use of unresolved identifier 'foo'}}
|
|
}
|
|
#endif
|
|
|
|
#if !targetEnvironment(macabi) // expected-warning {{'macabi' has been renamed to 'macCatalyst'}} {{24-30=macCatalyst}}
|
|
// This block does not typecheck but the #if prevents it from
|
|
// from being a compiler error.
|
|
let i: SomeType = "SomeString" // no-error
|
|
#endif
|
|
|
|
#if targetEnvironment(macCatalyst)
|
|
func underTargetEnvironmentMacCatalyst() {
|
|
foo() // expected-error {{use of unresolved identifier 'foo'}}
|
|
}
|
|
#endif
|
|
|
|
// Make sure we don't treat the macabi environment as a simulator.
|
|
#if targetEnvironment(simulator)
|
|
// This block does not typecheck but the #if prevents it from
|
|
// from being a compiler error.
|
|
let i: SomeType = "SomeString" // no-error
|
|
#endif
|
|
|
|
#if os(macCatalyst)
|
|
// expected-warning@-1 {{unknown operating system for build configuration 'os'}}
|
|
// expected-note@-2 *{{did you mean}}
|
|
func underOSMacCatalyst() {
|
|
}
|
|
#endif
|