Skip to content

Commit f6224bd

Browse files
committed
Allow libraries to specify to be compiled against the internal variant of the SDKs
We will need this to switch the darwin targets over to use ICU instead of going to NSString for string operations. The public SDK does not contain the headers for ICU - only the dylib. For builds using a public SDK users can specify the path to an ICU install where the headers can be found. If this path is specified the logic will not use internal SDK variants. Swift SVN r31471
1 parent a75b083 commit f6224bd

File tree

3 files changed

+70
-12
lines changed

3 files changed

+70
-12
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ option(SWIFT_RUNTIME_CRASH_REPORTER_CLIENT
128128
"Whether to enable CrashReporter integration"
129129
FALSE)
130130

131+
set(SWIFT_DARWIN_ICU_INCLUDE_PATH "" CACHE STRING
132+
"Path to the directory where the ICU headers are located")
133+
131134
#
132135
# User-configurable debugging options.
133136
#

cmake/modules/AddSwift.cmake

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ endfunction()
4040

4141

4242
function(_add_variant_c_compile_link_flags
43-
sdk arch build_type enable_assertions result_var_name)
44-
set(result ${${result_var_name}})
43+
sdk arch build_type enable_assertions use_internal_sdk result_var_name)
44+
set(result
45+
${${result_var_name}}
46+
"-target" "${SWIFT_SDK_${sdk}_ARCH_${arch}_TRIPLE}")
4547

46-
list(APPEND result
47-
"-isysroot" "${SWIFT_SDK_${sdk}_PATH}"
48-
"-target" "${SWIFT_SDK_${sdk}_ARCH_${arch}_TRIPLE}")
48+
if(use_internal_sdk)
49+
list(APPEND result
50+
"-isysroot" "${SWIFT_SDK_${sdk}_INTERNAL_PATH}")
51+
else()
52+
list(APPEND result
53+
"-isysroot" "${SWIFT_SDK_${sdk}_PATH}")
54+
endif()
4955

5056
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
5157
list(APPEND result
@@ -59,14 +65,15 @@ function(_add_variant_c_compile_link_flags
5965
endfunction()
6066

6167
function(_add_variant_c_compile_flags
62-
sdk arch build_type enable_assertions result_var_name)
68+
sdk arch build_type enable_assertions use_internal_sdk result_var_name)
6369
set(result ${${result_var_name}})
6470

6571
_add_variant_c_compile_link_flags(
6672
"${sdk}"
6773
"${arch}"
6874
"${build_type}"
6975
"${enable_assertions}"
76+
${use_internal_sdk}
7077
result)
7178

7279
is_build_type_optimized("${build_type}" optimized)
@@ -135,7 +142,7 @@ function(_add_variant_swift_compile_flags
135142
endfunction()
136143

137144
function(_add_variant_link_flags
138-
sdk arch build_type enable_assertions result_var_name)
145+
sdk arch build_type enable_assertions use_internal_sdk result_var_name)
139146

140147
if("${sdk}" STREQUAL "")
141148
message(FATAL_ERROR "Should specify an SDK")
@@ -152,6 +159,7 @@ function(_add_variant_link_flags
152159
"${arch}"
153160
"${build_type}"
154161
"${enable_assertions}"
162+
${use_internal_sdk}
155163
result)
156164

157165
if("${sdk}" STREQUAL "LINUX")
@@ -626,6 +634,7 @@ endfunction()
626634
# _add_swift_library_single(
627635
# target
628636
# name
637+
# [USE_INTERNAL_SDK]
629638
# [SHARED]
630639
# [SDK sdk]
631640
# [ARCHITECTURE architecture]
@@ -706,12 +715,15 @@ endfunction()
706715
# INSTALL_IN_COMPONENT comp
707716
# The Swift installation component that this library belongs to.
708717
#
718+
# USE_INTERNAL_SDK
719+
# Use the 'internal' sdk variant.
720+
#
709721
# source1 ...
710722
# Sources to add into this library
711723
function(_add_swift_library_single target name)
712724
set(SWIFTLIB_SINGLE_options
713725
SHARED IS_STDLIB IS_STDLIB_CORE IS_SDK_OVERLAY
714-
API_NOTES_NON_OVERLAY DONT_EMBED_BITCODE)
726+
API_NOTES_NON_OVERLAY DONT_EMBED_BITCODE USE_INTERNAL_SDK)
715727
cmake_parse_arguments(SWIFTLIB_SINGLE
716728
"${SWIFTLIB_SINGLE_options}"
717729
"SDK;ARCHITECTURE;INSTALL_IN_COMPONENT"
@@ -963,9 +975,17 @@ function(_add_swift_library_single target name)
963975
target_link_libraries("${target}" INTERFACE ${SWIFTLIB_SINGLE_LINK_LIBRARIES})
964976
endif()
965977

978+
# Don't add the icucore target.
979+
set(SWIFTLIB_SINGLE_LINK_LIBRARIES_WITHOUT_ICU)
980+
foreach(item ${SWIFTLIB_SINGLE_LINK_LIBRARIES})
981+
if(NOT "${item}" STREQUAL "icucore")
982+
list(APPEND SWIFTLIB_SINGLE_LINK_LIBRARIES_WITHOUT_ICU "{$item}")
983+
endif()
984+
endforeach()
985+
966986
if(target_static)
967987
_list_add_string_suffix(
968-
"${SWIFTLIB_SINGLE_LINK_LIBRARIES}"
988+
"${SWIFTLIB_SINGLE_LINK_LIBRARIES_WITHOUT_ICU}"
969989
"-static"
970990
target_static_depends)
971991
# FIXME: should this be target_link_libraries?
@@ -1006,12 +1026,14 @@ function(_add_swift_library_single target name)
10061026
"${SWIFTLIB_SINGLE_ARCHITECTURE}"
10071027
"${build_type}"
10081028
"${enable_assertions}"
1029+
${SWIFTLIB_SINGLE_USE_INTERNAL_SDK}
10091030
c_compile_flags)
10101031
_add_variant_link_flags(
10111032
"${SWIFTLIB_SINGLE_SDK}"
10121033
"${SWIFTLIB_SINGLE_ARCHITECTURE}"
10131034
"${build_type}"
10141035
"${enable_assertions}"
1036+
${SWIFTLIB_SINGLE_USE_INTERNAL_SDK}
10151037
link_flags)
10161038

10171039
# Configure plist creation for OS X.
@@ -1187,12 +1209,15 @@ endfunction()
11871209
# INSTALL_IN_COMPONENT comp
11881210
# The Swift installation component that this library belongs to.
11891211
#
1212+
# USE_INTERNAL_SDK
1213+
# Use the 'internal' sdk variant.
1214+
#
11901215
# source1 ...
11911216
# Sources to add into this library.
11921217
function(add_swift_library name)
11931218
set(SWIFTLIB_options
11941219
SHARED IS_STDLIB IS_STDLIB_CORE IS_SDK_OVERLAY TARGET_LIBRARY
1195-
API_NOTES_NON_OVERLAY DONT_EMBED_BITCODE)
1220+
API_NOTES_NON_OVERLAY DONT_EMBED_BITCODE USE_INTERNAL_SDK)
11961221
cmake_parse_arguments(SWIFTLIB
11971222
"${SWIFTLIB_options}"
11981223
"INSTALL_IN_COMPONENT"
@@ -1328,6 +1353,7 @@ function(add_swift_library name)
13281353
_add_swift_library_single(
13291354
${VARIANT_NAME}
13301355
${name}
1356+
${SWIFTLIB_USE_INTERNAL_SDK_keyword}
13311357
${SWIFTLIB_SHARED_keyword}
13321358
${SWIFTLIB_SOURCES}
13331359
SDK ${sdk}
@@ -1351,15 +1377,19 @@ function(add_swift_library name)
13511377

13521378
# Add dependencies on the (not-yet-created) custom lipo target.
13531379
foreach(DEP ${SWIFTLIB_LINK_LIBRARIES})
1354-
add_dependencies(${VARIANT_NAME}
1380+
if (NOT "${DEP}" STREQUAL "icucore")
1381+
add_dependencies(${VARIANT_NAME}
13551382
"${DEP}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}")
1383+
endif()
13561384
endforeach()
13571385

13581386
if (SWIFT_BUILD_STATIC_STDLIB AND SWIFTLIB_IS_STDLIB)
13591387
# Add dependencies on the (not-yet-created) custom lipo target.
13601388
foreach(DEP ${SWIFTLIB_LINK_LIBRARIES})
1361-
add_dependencies("${VARIANT_NAME}-static"
1389+
if (NOT "${DEP}" STREQUAL "icucore")
1390+
add_dependencies("${VARIANT_NAME}-static"
13621391
"${DEP}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-static")
1392+
endif()
13631393
endforeach()
13641394
endif()
13651395

@@ -1490,6 +1520,7 @@ function(add_swift_library name)
14901520
_add_swift_library_single(
14911521
${name}
14921522
${name}
1523+
${SWIFTLIB_USE_INTERNAL_SDK_keyword}
14931524
${SWIFTLIB_SHARED_keyword}
14941525
${SWIFTLIB_SOURCES}
14951526
SDK ${sdk}
@@ -1563,12 +1594,14 @@ function(_add_swift_executable_single name)
15631594
"${SWIFTEXE_SINGLE_ARCHITECTURE}"
15641595
"${CMAKE_BUILD_TYPE}"
15651596
"${LLVM_ENABLE_ASSERTIONS}"
1597+
FALSE
15661598
c_compile_flags)
15671599
_add_variant_link_flags(
15681600
"${SWIFTEXE_SINGLE_SDK}"
15691601
"${SWIFTEXE_SINGLE_ARCHITECTURE}"
15701602
"${CMAKE_BUILD_TYPE}"
15711603
"${LLVM_ENABLE_ASSERTIONS}"
1604+
FALSE
15721605
link_flags)
15731606

15741607
list(APPEND link_flags
@@ -1801,6 +1834,7 @@ function(add_swift_llvm_loadable_module name)
18011834
"${arch}"
18021835
"${CMAKE_BUILD_TYPE}"
18031836
"${LLVM_ENABLE_ASSERTIONS}"
1837+
FALSE
18041838
c_compile_flags)
18051839

18061840
set(link_flags)
@@ -1809,6 +1843,7 @@ function(add_swift_llvm_loadable_module name)
18091843
"${arch}"
18101844
"${CMAKE_BUILD_TYPE}"
18111845
"${LLVM_ENABLE_ASSERTIONS}"
1846+
FALSE
18121847
link_flags)
18131848

18141849
# Convert variables to space-separated strings.

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,25 @@ macro(configure_sdk_darwin
9797
set(SWIFT_SDK_${prefix}_PATH "${SWIFT_SDK_${prefix}_PUBLIC_PATH}")
9898
endif()
9999

100+
# Find the internal SDK if the user has not specified to use an external ICU
101+
# library. Otherwise, we will just use the regular SDK.
102+
set(SWIFT_SDK_${prefix}_INTERNAL_PATH "" CACHE PATH "Path to the internal ${name} SDK")
103+
if (NOT SWIFT_DARWIN_ICU_INCLUDE_PATH)
104+
if ("${prefix}" STREQUAL "IOS_SIMULATOR" OR
105+
"${prefix}" STREQUAL "WATCHOS_SIMULATOR" OR
106+
"${prefix}" STREQUAL "TVOS_SIMULATOR")
107+
set(SWIFT_SDK_${prefix}_INTERNAL_PATH "${SWIFT_SDK_${prefix}_PATH}")
108+
else()
109+
execute_process(
110+
COMMAND "xcrun" "--sdk" "${xcrun_name}.internal" "--show-sdk-path"
111+
OUTPUT_VARIABLE SWIFT_SDK_${prefix}_INTERNAL_PATH
112+
OUTPUT_STRIP_TRAILING_WHITESPACE)
113+
endif()
114+
else()
115+
set(SWIFT_SDK_${prefix}_INTERNAL_PATH "${SWIFT_SDK_${prefix}_PATH}")
116+
endif()
117+
118+
100119
if(NOT EXISTS "${SWIFT_SDK_${prefix}_PATH}/System/Library/Frameworks/module.map")
101120
message(FATAL_ERROR "${name} SDK not found at SWIFT_SDK_${prefix}_PATH.")
102121
endif()
@@ -139,6 +158,7 @@ macro(configure_sdk_unix
139158
set(SWIFT_SDK_${prefix}_NAME "${name}")
140159
set(SWIFT_SDK_${prefix}_PATH "/")
141160
set(SWIFT_SDK_${prefix}_PUBLIC_PATH "/")
161+
set(SWIFT_SDK_${prefix}_INTERNAL_PATH "/")
142162
set(SWIFT_SDK_${prefix}_VERSION "don't use")
143163
set(SWIFT_SDK_${prefix}_BUILD_NUMBER "don't use")
144164
set(SWIFT_SDK_${prefix}_DEPLOYMENT_VERSION "don't use")

0 commit comments

Comments
 (0)