Skip to content

Commit ea17483

Browse files
committed
Add CMake options and #ifs to hide tvOS
Swift SVN r28752
1 parent b5b787b commit ea17483

21 files changed

+93
-18
lines changed

CMakeLists.txt

+22-16
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ option(SWIFT_ENABLE_TARGET_LINUX
5656
"Enable compiler support for targeting Linux"
5757
TRUE)
5858

59+
option(SWIFT_ENABLE_TARGET_TVOS
60+
"Enable compiler support for targeting tvOS"
61+
TRUE)
62+
5963
set(SWIFT_VERSION "2.0" CACHE STRING
6064
"The user-visible version of the Swift compiler")
6165
set(SWIFT_VENDOR "" CACHE STRING
@@ -399,23 +403,25 @@ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
399403
IOS_SIMULATOR-R "iOS Release" IOS_SIMULATOR R "Release")
400404
endif()
401405

402-
is_sdk_requested(TVOS swift_build_tvos)
403-
if(swift_build_tvos AND ${swift_can_crosscompile_stdlib})
404-
configure_sdk_darwin(TVOS "tvOS" "9.0" appletvos tvos tvos "arm64" TRUE)
405-
configure_target_variant(TVOS-DA "tvOS Debug+Asserts" TVOS DA "Debug+Asserts")
406-
configure_target_variant(TVOS-RA "tvOS Release+Asserts" TVOS RA "Release+Asserts")
407-
configure_target_variant(TVOS-R "tvOS Release" TVOS R "Release")
408-
endif()
406+
if(${SWIFT_ENABLE_TARGET_TVOS})
407+
is_sdk_requested(TVOS swift_build_tvos)
408+
if(swift_build_tvos AND ${swift_can_crosscompile_stdlib})
409+
configure_sdk_darwin(TVOS "tvOS" "9.0" appletvos tvos tvos "arm64" TRUE)
410+
configure_target_variant(TVOS-DA "tvOS Debug+Asserts" TVOS DA "Debug+Asserts")
411+
configure_target_variant(TVOS-RA "tvOS Release+Asserts" TVOS RA "Release+Asserts")
412+
configure_target_variant(TVOS-R "tvOS Release" TVOS R "Release")
413+
endif()
409414

410-
is_sdk_requested(TVOS_SIMULATOR swift_build_tvos_simulator)
411-
if(swift_build_tvos_simulator AND ${swift_can_crosscompile_stdlib})
412-
configure_sdk_darwin(TVOS_SIMULATOR "tvOS Simulator" "9.0" appletvsimulator tvos-simulator tvos "x86_64" FALSE)
413-
configure_target_variant(
414-
TVOS_SIMULATOR-DA "tvOS Debug+Asserts" TVOS_SIMULATOR DA "Debug+Asserts")
415-
configure_target_variant(
416-
TVOS_SIMULATOR-RA "tvOS Release+Asserts" TVOS_SIMULATOR RA "Release+Asserts")
417-
configure_target_variant(
418-
TVOS_SIMULATOR-R "tvOS Release" TVOS_SIMULATOR R "Release")
415+
is_sdk_requested(TVOS_SIMULATOR swift_build_tvos_simulator)
416+
if(swift_build_tvos_simulator AND ${swift_can_crosscompile_stdlib})
417+
configure_sdk_darwin(TVOS_SIMULATOR "tvOS Simulator" "9.0" appletvsimulator tvos-simulator tvos "x86_64" FALSE)
418+
configure_target_variant(
419+
TVOS_SIMULATOR-DA "tvOS Debug+Asserts" TVOS_SIMULATOR DA "Debug+Asserts")
420+
configure_target_variant(
421+
TVOS_SIMULATOR-RA "tvOS Release+Asserts" TVOS_SIMULATOR RA "Release+Asserts")
422+
configure_target_variant(
423+
TVOS_SIMULATOR-R "tvOS Release" TVOS_SIMULATOR R "Release")
424+
endif()
419425
endif()
420426

421427
is_sdk_requested(WATCHOS swift_build_watchos)

cmake/modules/AddSwift.cmake

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ function(_add_variant_c_compile_link_flags
5555
"-m${SWIFT_SDK_${sdk}_VERSION_MIN_NAME}-version-min=${SWIFT_SDK_${sdk}_DEPLOYMENT_VERSION}")
5656
endif()
5757

58+
if(${SWIFT_ENABLE_TARGET_TVOS})
59+
list(APPEND result
60+
" -DSWIFT_ENABLE_TARGET_TVOS=\"1\"")
61+
endif()
62+
5863
set("${result_var_name}" "${result}" PARENT_SCOPE)
5964
endfunction()
6065

include/swift/AST/PlatformKinds.def

+4
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@
2323

2424
// Reordering these platforms will break serialization.
2525
AVAILABILITY_PLATFORM(iOS, "iOS")
26+
#if defined(SWIFT_ENABLE_TARGET_TVOS)
2627
AVAILABILITY_PLATFORM(tvOS, "tvOS")
28+
#endif // SWIFT_ENABLE_TARGET_TVOS
2729
AVAILABILITY_PLATFORM(watchOS, "watchOS")
2830
AVAILABILITY_PLATFORM(OSX, "OS X")
2931
AVAILABILITY_PLATFORM(iOSApplicationExtension, "iOS application extension")
32+
#if defined(SWIFT_ENABLE_TARGET_TVOS)
3033
AVAILABILITY_PLATFORM(tvOSApplicationExtension, "tvOS application extension")
34+
#endif // SWIFT_ENABLE_TARGET_TVOS
3135
AVAILABILITY_PLATFORM(watchOSApplicationExtension, "watchOS application extension")
3236
AVAILABILITY_PLATFORM(OSXApplicationExtension, "OS X application extension")
3337

include/swift/Basic/Platform.h

+2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ namespace swift {
2424
/// Returns true if the given triple represents iOS running in a simulator.
2525
bool tripleIsiOSSimulator(const llvm::Triple &triple);
2626

27+
#if defined(SWIFT_ENABLE_TARGET_TVOS)
2728
/// Returns true if the given triple represents AppleTV running in a simulator.
2829
bool tripleIsAppleTVSimulator(const llvm::Triple &triple);
30+
#endif // SWIFT_ENABLE_TARGET_TVOS
2931

3032
/// Returns true if the given triple represents watchOS running in a simulator.
3133
bool tripleIsWatchSimulator(const llvm::Triple &triple);

lib/AST/PlatformKind.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ bool swift::isPlatformActive(PlatformKind Platform, LangOptions &LangOpts) {
7171
case PlatformKind::iOS:
7272
case PlatformKind::iOSApplicationExtension:
7373
return LangOpts.Target.isiOS() && !LangOpts.Target.isTvOS();
74+
#if defined(SWIFT_ENABLE_TARGET_TVOS)
7475
case PlatformKind::tvOS:
7576
case PlatformKind::tvOSApplicationExtension:
7677
return LangOpts.Target.isTvOS();
78+
#endif // SWIFT_ENABLE_TARGET_TVOS
7779
case PlatformKind::watchOS:
7880
case PlatformKind::watchOSApplicationExtension:
7981
return LangOpts.Target.isWatchOS();
@@ -90,11 +92,13 @@ PlatformKind swift::targetPlatform(LangOptions &LangOpts) {
9092
: PlatformKind::OSX);
9193
}
9294

95+
#if defined(SWIFT_ENABLE_TARGET_TVOS)
9396
if (LangOpts.Target.isTvOS()) {
9497
return (LangOpts.EnableAppExtensionRestrictions
9598
? PlatformKind::tvOSApplicationExtension
9699
: PlatformKind::tvOS);
97100
}
101+
#endif // SWIFT_ENABLE_TARGET_TVOS
98102

99103
if (LangOpts.Target.isWatchOS()) {
100104
return (LangOpts.EnableAppExtensionRestrictions

lib/Basic/LangOptions.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ void LangOptions::setTarget(llvm::Triple triple) {
6060
// Set the "os" target configuration.
6161
if (Target.isMacOSX())
6262
addTargetConfigOption("os", "OSX");
63+
#if defined(SWIFT_ENABLE_TARGET_TVOS)
6364
else if (triple.isTvOS())
6465
addTargetConfigOption("os", "tvOS");
66+
#endif // SWIFT_ENABLE_TARGET_TVOS
6567
else if (triple.isWatchOS())
6668
addTargetConfigOption("os", "watchOS");
6769
else if (triple.isiOS())

lib/Basic/Platform.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ bool swift::tripleIsiOSSimulator(const llvm::Triple &triple) {
2121
(arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64));
2222
}
2323

24+
#if defined(SWIFT_ENABLE_TARGET_TVOS)
2425
bool swift::tripleIsAppleTVSimulator(const llvm::Triple &triple) {
2526
llvm::Triple::ArchType arch = triple.getArch();
2627
return (triple.isTvOS() &&
2728
(arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64));
2829
}
30+
#endif // SWIFT_ENABLE_TARGET_TVOS
2931

3032
bool swift::tripleIsWatchSimulator(const llvm::Triple &triple) {
3133
llvm::Triple::ArchType arch = triple.getArch();
@@ -35,11 +37,13 @@ bool swift::tripleIsWatchSimulator(const llvm::Triple &triple) {
3537

3638
StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
3739
if (triple.isiOS()) {
40+
#if defined(SWIFT_ENABLE_TARGET_TVOS)
3841
if (triple.isTvOS()) {
3942
if (tripleIsAppleTVSimulator(triple))
4043
return "appletvsimulator";
4144
return "appletvos";
4245
}
46+
#endif // SWIFT_ENABLE_TARGET_TVOS
4347

4448
if (tripleIsiOSSimulator(triple))
4549
return "iphonesimulator";

lib/ClangImporter/ClangImporter.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,11 @@ ClangImporter::create(ASTContext &ctx,
277277
unsigned major, minor, micro;
278278
if (triple.isiOS()) {
279279
bool isiOSSimulator = swift::tripleIsiOSSimulator(triple);
280+
#if defined(SWIFT_ENABLE_TARGET_TVOS)
280281
if (triple.isTvOS()) {
282+
#else
283+
if (/* DISABLES CODE */ (false)) {
284+
#endif // SWIFT_ENABLE_TARGET_TVOS
281285
if (isiOSSimulator)
282286
minVersionOpt << "-mtvos-simulator-version-min=";
283287
else
@@ -912,7 +916,11 @@ ClangImporter::Implementation::Implementation(ASTContext &ctx,
912916
// applies in Swift, and if so, what is the cutoff for deprecated
913917
// declarations that are now considered unavailable in Swift.
914918

915-
if (ctx.LangOpts.Target.isiOS() && !ctx.LangOpts.Target.isTvOS()) {
919+
if (ctx.LangOpts.Target.isiOS()
920+
#if defined(SWIFT_ENABLE_TARGET_TVOS)
921+
&& !ctx.LangOpts.Target.isTvOS()
922+
#endif // SWIFT_ENABLE_TARGET_TVOS
923+
) {
916924
if (!ctx.LangOpts.EnableAppExtensionRestrictions) {
917925
PlatformAvailabilityFilter =
918926
[](StringRef Platform) { return Platform == "ios"; };
@@ -929,6 +937,7 @@ ClangImporter::Implementation::Implementation(ASTContext &ctx,
929937
DeprecatedAsUnavailableMessage =
930938
"APIs deprecated as of iOS 7 and earlier are unavailable in Swift";
931939
}
940+
#if defined(SWIFT_ENABLE_TARGET_TVOS)
932941
else if (ctx.LangOpts.Target.isTvOS()) {
933942
if (!ctx.LangOpts.EnableAppExtensionRestrictions) {
934943
PlatformAvailabilityFilter =
@@ -946,6 +955,7 @@ ClangImporter::Implementation::Implementation(ASTContext &ctx,
946955
DeprecatedAsUnavailableMessage =
947956
"APIs deprecated as of iOS 7 and earlier are unavailable in Swift";
948957
}
958+
#endif // SWIFT_ENABLE_TARGET_TVOS
949959
else if (ctx.LangOpts.Target.isWatchOS()) {
950960
if (!ctx.LangOpts.EnableAppExtensionRestrictions) {
951961
PlatformAvailabilityFilter =

lib/ClangImporter/ImportDecl.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -5387,13 +5387,17 @@ void ClangImporter::Implementation::importAttributes(
53875387
llvm::StringSwitch<Optional<PlatformKind>>(Platform)
53885388
.Case("ios", PlatformKind::iOS)
53895389
.Case("macosx", PlatformKind::OSX)
5390+
#if defined(SWIFT_ENABLE_TARGET_TVOS)
53905391
.Case("tvos", PlatformKind::tvOS)
5392+
#endif // SWIFT_ENABLE_TARGET_TVOS
53915393
.Case("watchos", PlatformKind::watchOS)
53925394
.Case("ios_app_extension", PlatformKind::iOSApplicationExtension)
53935395
.Case("macosx_app_extension",
53945396
PlatformKind::OSXApplicationExtension)
5397+
#if defined(SWIFT_ENABLE_TARGET_TVOS)
53955398
.Case("tvos_app_extension",
53965399
PlatformKind::tvOSApplicationExtension)
5400+
#endif // SWIFT_ENABLE_TARGET_TVOS
53975401
.Case("watchos_app_extension",
53985402
PlatformKind::watchOSApplicationExtension)
53995403
.Default(None);

lib/Driver/Driver.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,15 @@ static void validateArgs(DiagnosticEngine &diags, const ArgList &Args) {
129129
diags.diagnose(SourceLoc(), diag::error_os_minimum_deployment,
130130
"OS X 10.9");
131131
} else if (triple.isiOS()) {
132+
#if defined(SWIFT_ENABLE_TARGET_TVOS)
132133
if (triple.isTvOS()) {
133134
if (triple.isOSVersionLT(9, 0)) {
134135
diags.diagnose(SourceLoc(), diag::error_os_minimum_deployment,
135136
"tvOS 9.0");
136137
return;
137138
}
138139
}
140+
#endif // SWIFT_ENABLE_TARGET_TVOS
139141
if (triple.isOSVersionLT(7))
140142
diags.diagnose(SourceLoc(), diag::error_os_minimum_deployment,
141143
"iOS 7");
@@ -1965,7 +1967,9 @@ const ToolChain *Driver::getToolChain(const ArgList &Args,
19651967
case llvm::Triple::Darwin:
19661968
case llvm::Triple::MacOSX:
19671969
case llvm::Triple::IOS:
1970+
#if defined(SWIFT_ENABLE_TARGET_TVOS)
19681971
case llvm::Triple::TvOS:
1972+
#endif // SWIFT_ENABLE_TARGET_TVOS
19691973
case llvm::Triple::WatchOS:
19701974
TC = new toolchains::Darwin(*this, Target);
19711975
break;

lib/Driver/Tools.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,11 @@ Job *darwin::Linker::constructJob(const JobAction &JA,
758758

759759
StringRef RT;
760760
if (Triple.isiOS()) {
761+
#if defined(SWIFT_ENABLE_TARGET_TVOS)
761762
if (Triple.isTvOS())
762763
RT = "tvos";
763764
else
765+
#endif // SWIFT_ENABLE_TARGET_TVOS
764766
RT = "ios";
765767
}
766768
else if (Triple.isWatchOS())
@@ -781,12 +783,15 @@ Job *darwin::Linker::constructJob(const JobAction &JA,
781783
assert(Triple.isiOS() || Triple.isWatchOS() || Triple.isMacOSX());
782784
if (Triple.isiOS()) {
783785
bool isiOSSimulator = tripleIsiOSSimulator(Triple);
786+
#if defined(SWIFT_ENABLE_TARGET_TVOS)
784787
if (Triple.isTvOS()) {
785788
if (isiOSSimulator)
786789
Arguments.push_back("-tvos_simulator_version_min");
787790
else
788791
Arguments.push_back("-tvos_version_min");
789-
} else {
792+
} else
793+
#endif // SWIFT_ENABLE_TARGET_TVOS
794+
{
790795
if (isiOSSimulator)
791796
Arguments.push_back("-ios_simulator_version_min");
792797
else

test/BuildConfigurations/arm64AppleTVOSTarget.swift

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// RUN: %swift -parse %s -verify -D FOO -D BAR -target arm64-apple-tvos9.0 -D FOO -parse-stdlib
22
// RUN: %swift-ide-test -test-input-complete -source-filename=%s -target arm64-apple-tvos9.0
33

4+
// REQUIRES: enable_target_appletvos
5+
6+
zzzzzz
7+
48
#if os(iOS)
59
// This block should not parse.
610
// os(tvOS) or os(watchOS) does not imply os(iOS).

test/BuildConfigurations/i386AppleTVOSTarget.swift

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %swift -parse %s -verify -D FOO -D BAR -target i386-apple-tvos9.0 -D FOO -parse-stdlib
22
// RUN: %swift-ide-test -test-input-complete -source-filename=%s -target i386-apple-tvos9.0
33

4+
// REQUIRES: enable_target_appletvos
5+
46
#if os(iOS)
57
// This block should not parse.
68
// os(tvOS) or os(watchOS) does not imply os(iOS).

test/BuildConfigurations/x64AppleTVOSTarget.swift

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %swift -parse %s -verify -D FOO -D BAR -target x86_64-apple-tvos9.0 -D FOO -parse-stdlib
22
// RUN: %swift-ide-test -test-input-complete -source-filename=%s -target x86_64-apple-tvos9.0
33

4+
// REQUIRES: enable_target_appletvos
5+
46
#if os(iOS)
57
// This block should not parse.
68
// os(tvOS) or os(watchOS) does not imply os(iOS).

test/Driver/linker.swift

+3
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,6 @@
153153

154154
// Clean up the test executable because hard links are expensive.
155155
// RUN: rm -rf %t/DISTINCTIVE-PATH/usr/bin/swiftc
156+
157+
// REQUIRES: enable_target_appletvos
158+

test/Driver/os-deployment.swift

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
// CHECK-IOS: Swift requires a minimum deployment target of iOS 7
99
// CHECK-tvOS: Swift requires a minimum deployment target of tvOS 9.0
1010
// CHECK-watchOS: Swift requires a minimum deployment target of watchOS 2.0
11+
12+
// REQUIRES: enable_target_appletvos

test/Driver/profiling.swift

+3
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@
2525

2626
// LINUX: clang++{{"? }}
2727
// LINUX: lib/swift/clang/{{[^ ]*}}/lib/linux/libclang_rt.profile-x86_64.a
28+
29+
// REQUIRES: enable_target_appletvos
30+

test/Driver/sdk.swift

+3
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,6 @@
8686

8787
// SDK-TOO-OLD: error: Swift does not support the SDK '{{.+}}.sdk'{{$}}
8888
// SDK-OKAY: -sdk {{.*}}/{{[^/ ]+}}sdk
89+
90+
// REQUIRES: enable_target_appletvos
91+

test/IDE/complete_decl_attribute.swift

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=KEYWORD5 | FileCheck %s -check-prefix=KEYWORD5
88
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=KEYWORD_LAST | FileCheck %s -check-prefix=KEYWORD_LAST
99

10+
// REQUIRES: enable_target_appletvos
11+
1012
@available(#^AVAILABILITY1^#)
1113

1214
// AVAILABILITY1: Begin completions, 9 items

test/attr/attr_availability.swift

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %target-parse-verify-swift
22

3+
// REQUIRES: enable_target_appletvos
4+
35
@available(*, unavailable)
46
func unavailable_func() {}
57

test/attr/attr_availability_tvos.swift

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %swift -parse -verify -parse-stdlib -target i386-apple-tvos9.0 %s
22

3+
// REQUIRES: enable_target_appletvos
4+
35
@available(tvOS, introduced=1.0, deprecated=2.0, obsoleted=9.0,
46
message="you don't want to do that anyway")
57
func doSomething() { }

0 commit comments

Comments
 (0)