1
+ include (macCatalystUtils )
1
2
include (SwiftUtils )
2
3
3
4
# Process the sources within the given variable, pulling out any Swift
@@ -7,6 +8,9 @@ include(SwiftUtils)
7
8
#
8
9
# Usage:
9
10
# handle_swift_sources(sourcesvar externalvar)
11
+ #
12
+ # MACCATALYST_BUILD_FLAVOR
13
+ # Possible values are 'ios-like', 'macos-like', 'zippered', 'unzippered-twin'
10
14
function (handle_swift_sources
11
15
dependency_target_out_var_name
12
16
dependency_module_target_out_var_name
@@ -16,7 +20,7 @@ function(handle_swift_sources
16
20
sourcesvar externalvar name )
17
21
cmake_parse_arguments (SWIFTSOURCES
18
22
"IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMBED_BITCODE"
19
- "SDK;ARCHITECTURE;INSTALL_IN_COMPONENT"
23
+ "SDK;ARCHITECTURE;INSTALL_IN_COMPONENT;MACCATALYST_BUILD_FLAVOR "
20
24
"DEPENDS;COMPILE_FLAGS;MODULE_NAME"
21
25
${ARGN} )
22
26
translate_flag (${SWIFTSOURCES_IS_MAIN} "IS_MAIN" IS_MAIN_arg )
@@ -63,6 +67,12 @@ function(handle_swift_sources
63
67
if (swift_sources )
64
68
set (objsubdir "/${SWIFTSOURCES_SDK} /${SWIFTSOURCES_ARCHITECTURE} " )
65
69
70
+ get_maccatalyst_build_flavor (maccatalyst_build_flavor
71
+ "${SWIFTSOURCES_SDK} " "${SWIFTSOURCES_MACCATALYST_BUILD_FLAVOR} " )
72
+ if (maccatalyst_build_flavor STREQUAL "ios-like" )
73
+ set (objsubdir "/MACCATALYST/${SWIFTSOURCES_ARCHITECTURE} " )
74
+ endif ()
75
+
66
76
file (MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}${objsubdir} " )
67
77
68
78
set (swift_obj
@@ -91,7 +101,8 @@ function(handle_swift_sources
91
101
${IS_SDK_OVERLAY_arg}
92
102
${EMBED_BITCODE_arg}
93
103
${STATIC_arg}
94
- INSTALL_IN_COMPONENT "${SWIFTSOURCES_INSTALL_IN_COMPONENT} " )
104
+ INSTALL_IN_COMPONENT "${SWIFTSOURCES_INSTALL_IN_COMPONENT} "
105
+ MACCATALYST_BUILD_FLAVOR "${SWIFTSOURCES_MACCATALYST_BUILD_FLAVOR} " )
95
106
set ("${dependency_target_out_var_name} " "${dependency_target} " PARENT_SCOPE )
96
107
set ("${dependency_module_target_out_var_name} " "${module_dependency_target} " PARENT_SCOPE )
97
108
set ("${dependency_sib_target_out_var_name} " "${sib_dependency_target} " PARENT_SCOPE )
@@ -131,6 +142,7 @@ endfunction()
131
142
# OUTPUT objfile # Name of the resulting object file
132
143
# SOURCES swift_src [swift_src...] # Swift source files to compile
133
144
# FLAGS -module-name foo # Flags to add to the compilation
145
+ # MACCATALYST_BUILD_FLAVOR flavor # macCatalyst flavor
134
146
# [SDK sdk] # SDK to build for
135
147
# [ARCHITECTURE architecture] # Architecture to build for
136
148
# [DEPENDS cmake_target...] # CMake targets on which the object
@@ -151,7 +163,7 @@ function(_compile_swift_files
151
163
dependency_sibgen_target_out_var_name )
152
164
cmake_parse_arguments (SWIFTFILE
153
165
"IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMBED_BITCODE"
154
- "OUTPUT;MODULE_NAME;INSTALL_IN_COMPONENT"
166
+ "OUTPUT;MODULE_NAME;INSTALL_IN_COMPONENT;MACCATALYST_BUILD_FLAVOR "
155
167
"SOURCES;FLAGS;DEPENDS;SDK;ARCHITECTURE;OPT_FLAGS;MODULE_DIR"
156
168
${ARGN} )
157
169
@@ -175,6 +187,27 @@ function(_compile_swift_files
175
187
precondition (SWIFTFILE_ARCHITECTURE MESSAGE "Should specify an architecture" )
176
188
precondition (SWIFTFILE_INSTALL_IN_COMPONENT MESSAGE "INSTALL_IN_COMPONENT is required" )
177
189
190
+ # Determine if/what macCatalyst build variant we are
191
+ get_maccatalyst_build_flavor (maccatalyst_build_flavor
192
+ "${SWIFTFILE_SDK} " "${SWIFTFILE_MACCATALYST_BUILD_FLAVOR} " )
193
+
194
+ # Determine target triples
195
+ get_target_triple (target_triple ignored_target_variant_triple
196
+ "${SWIFTFILE_SDK} "
197
+ "${SWIFTFILE_ARCHITECTURE} "
198
+ DEPLOYMENT_VERSION "${SWIFT_SDK_${SWIFTFILE_SDK} _DEPLOYMENT_VERSION}" )
199
+
200
+ get_target_triple (maccatalyst_target_triple ignored_target_variant_triple
201
+ "${SWIFTFILE_SDK} "
202
+ "${SWIFTFILE_ARCHITECTURE} "
203
+ DEPLOYMENT_VERSION "${SWIFT_SDK_${SWIFTFILE_SDK} _DEPLOYMENT_VERSION}"
204
+ MACCATALYST_BUILD_FLAVOR "${maccatalyst_build_flavor} " )
205
+
206
+ # macCatalyst ios-like target triple
207
+ if (maccatalyst_build_flavor STREQUAL "ios-like" )
208
+ set (target_triple "${maccatalyst_target_triple} " )
209
+ endif ()
210
+
178
211
if ("${SWIFTFILE_MODULE_NAME} " STREQUAL "" )
179
212
get_filename_component (SWIFTFILE_MODULE_NAME "${first_output} " NAME_WE )
180
213
message (SEND_ERROR
@@ -202,17 +235,18 @@ function(_compile_swift_files
202
235
"${SWIFTFILE_ARCHITECTURE} "
203
236
"${SWIFT_STDLIB_BUILD_TYPE} "
204
237
"${SWIFT_STDLIB_ASSERTIONS} "
205
- swift_flags )
238
+ swift_flags
239
+ MACCATALYST_BUILD_FLAVOR "${maccatalyst_build_flavor} "
240
+ )
206
241
207
242
# Determine the subdirectory where the binary should be placed.
208
243
compute_library_subdir (library_subdir
209
244
"${SWIFTFILE_SDK} " "${SWIFTFILE_ARCHITECTURE} " )
210
245
211
- # Allow import of other Swift modules we just built.
212
- list (APPEND swift_flags
213
- "-I" "${SWIFTLIB_DIR} /${library_subdir} " )
214
- # FIXME: should we use '-resource-dir' here? Seems like it has no advantage
215
- # over '-I' in this case.
246
+ if (maccatalyst_build_flavor STREQUAL "ios-like" )
247
+ compute_library_subdir (library_subdir
248
+ "MACCATALYST" "${SWIFTFILE_ARCHITECTURE} " )
249
+ endif ()
216
250
217
251
# If we have a custom module cache path, use it.
218
252
if (SWIFT_MODULE_CACHE_PATH )
@@ -308,7 +342,8 @@ function(_compile_swift_files
308
342
list (APPEND swift_flags "-parse-as-library" )
309
343
310
344
set (module_base "${module_dir} /${SWIFTFILE_MODULE_NAME} " )
311
- if (SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS )
345
+ if (SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS OR
346
+ SWIFTFILE_SDK STREQUAL "MACCATALYST" )
312
347
set (specific_module_dir "${module_base} .swiftmodule" )
313
348
set (specific_module_project_dir "${specific_module_dir} /Project" )
314
349
set (source_info_file "${specific_module_project_dir} /${SWIFTFILE_ARCHITECTURE} .swiftsourceinfo" )
@@ -338,6 +373,57 @@ function(_compile_swift_files
338
373
"-Xfrontend" "-experimental-skip-non-inlinable-function-bodies" )
339
374
endif ()
340
375
376
+ set (module_outputs "${module_file} " "${module_doc_file} " )
377
+
378
+ if (interface_file )
379
+ list (APPEND module_outputs "${interface_file} " )
380
+ endif ()
381
+
382
+ set (optional_arg )
383
+ if (SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS OR
384
+ SWIFTFILE_SDK STREQUAL "MACCATALYST" )
385
+ # Allow installation of stdlib without building all variants on Darwin.
386
+ set (optional_arg "OPTIONAL" )
387
+ endif ()
388
+
389
+ if (SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS OR
390
+ SWIFTFILE_SDK STREQUAL "MACCATALYST" )
391
+ swift_install_in_component (DIRECTORY "${specific_module_dir} "
392
+ DESTINATION "lib${LLVM_LIBDIR_SUFFIX} /swift/${library_subdir} "
393
+ COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT} " )
394
+ else ()
395
+ swift_install_in_component (FILES ${module_outputs}
396
+ DESTINATION "lib${LLVM_LIBDIR_SUFFIX} /swift/${library_subdir} "
397
+ COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT} " )
398
+ endif ()
399
+
400
+ # macCatalyst zippered module setup
401
+ if (maccatalyst_build_flavor STREQUAL "zippered" )
402
+ compute_library_subdir (maccatalyst_library_subdir
403
+ "MACCATALYST" "${SWIFTFILE_ARCHITECTURE} " )
404
+
405
+ if (SWIFTFILE_MODULE_DIR )
406
+ set (maccatalyst_module_dir "${SWIFTFILE_MODULE_DIR} " )
407
+ elseif (SWIFTFILE_IS_STDLIB )
408
+ set (maccatalyst_module_dir "${SWIFTLIB_DIR} /${maccatalyst_library_subdir} " )
409
+ else ()
410
+ message (FATAL_ERROR "Don't know where to put the module files" )
411
+ endif ()
412
+
413
+ set (maccatalyst_specific_module_dir
414
+ "${maccatalyst_module_dir} /${SWIFTFILE_MODULE_NAME} .swiftmodule" )
415
+ set (maccatalyst_module_base "${maccatalyst_specific_module_dir} /${SWIFTFILE_ARCHITECTURE} " )
416
+ set (maccatalyst_module_file "${maccatalyst_module_base} .swiftmodule" )
417
+ set (maccatalyst_module_doc_file "${maccatalyst_module_base} .swiftdoc" )
418
+
419
+ set (maccatalyst_module_outputs "${maccatalyst_module_file} " "${maccatalyst_module_doc_file} " )
420
+
421
+ swift_install_in_component (DIRECTORY ${maccatalyst_specific_module_dir}
422
+ DESTINATION "lib${LLVM_LIBDIR_SUFFIX} /swift/${maccatalyst_library_subdir} "
423
+ COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT} "
424
+ "${optional_arg} " )
425
+ endif ()
426
+
341
427
# If we have extra regexp flags, check if we match any of the regexps. If so
342
428
# add the relevant flags to our swift_flags.
343
429
if (SWIFT_EXPERIMENTAL_EXTRA_REGEXP_FLAGS OR SWIFT_EXPERIMENTAL_EXTRA_NEGATIVE_REGEXP_FLAGS )
@@ -401,6 +487,26 @@ function(_compile_swift_files
401
487
set (sibopt_outputs "${sibopt_file} " )
402
488
set (sibgen_outputs "${sibgen_file} " )
403
489
490
+ # macCatalyst zippered swiftmodule
491
+ if (maccatalyst_build_flavor STREQUAL "zippered" )
492
+ set (maccatalyst_swift_flags "${swift_flags} " )
493
+ list (APPEND maccatalyst_swift_flags
494
+ "-I" "${SWIFTLIB_DIR} /${maccatalyst_library_subdir} " )
495
+ set (maccatalyst_swift_module_flags ${swift_module_flags} )
496
+ elseif (maccatalyst_build_flavor STREQUAL "ios-like" )
497
+ compute_library_subdir (maccatalyst_library_subdir
498
+ "MACCATALYST" "${SWIFTFILE_ARCHITECTURE} " )
499
+ list (APPEND swift_flags
500
+ "-I" "${SWIFTLIB_DIR} /${maccatalyst_library_subdir} " )
501
+ else ()
502
+ # Allow import of other Swift modules we just built.
503
+ list (APPEND swift_flags
504
+ "-I" "${SWIFTLIB_DIR} /${library_subdir} " )
505
+
506
+ # FIXME: should we use '-resource-dir' here? Seems like it has no advantage
507
+ # over '-I' in this case.
508
+ endif ()
509
+
404
510
if (XCODE )
405
511
# HACK: work around an issue with CMake Xcode generator and the Swift
406
512
# driver.
@@ -424,6 +530,12 @@ function(_compile_swift_files
424
530
COMMAND "${CMAKE_COMMAND} " -E touch ${sibopt_outputs} )
425
531
set (command_touch_sibgen_outputs
426
532
COMMAND "${CMAKE_COMMAND} " -E touch ${sibgen_outputs} )
533
+
534
+ # macCatalyst zippered outputs
535
+ if (maccatalyst_build_flavor STREQUAL "zippered" )
536
+ set (command_touch_maccatalyst_module_outputs
537
+ COMMAND "${CMAKE_COMMAND} " -E touch ${maccatalyst_module_outputs} )
538
+ endif ()
427
539
endif ()
428
540
429
541
# First generate the obj dirs
@@ -516,6 +628,49 @@ function(_compile_swift_files
516
628
COMMENT "Generating ${module_file} " )
517
629
set ("${dependency_module_target_out_var_name} " "${module_dependency_target} " PARENT_SCOPE )
518
630
631
+ # macCatalyst zippered swiftmodule
632
+ if (maccatalyst_build_flavor STREQUAL "zippered" )
633
+ get_target_triple (ios_like_target_triple ignored_target_variant
634
+ "${SWIFTFILE_SDK} "
635
+ "${SWIFTFILE_ARCHITECTURE} "
636
+ MACCATALYST_BUILD_FLAVOR "ios-like" )
637
+
638
+ # Remove previous -target <triple> and -target-variant flags from
639
+ # the zippered Swift flags and add an ios-like target.
640
+ remove_given_flag (maccatalyst_swift_flags "target" )
641
+ remove_given_flag (maccatalyst_swift_flags "target-variant" )
642
+ list (APPEND maccatalyst_swift_flags
643
+ "-target" "${ios_like_target_triple} " )
644
+
645
+ add_custom_command_target (
646
+ maccatalyst_module_dependency_target
647
+ COMMAND
648
+ "${CMAKE_COMMAND} " "-E" "remove" "-f" ${maccatalyst_module_outputs}
649
+ COMMAND
650
+ "${CMAKE_COMMAND} " "-E" "make_directory" ${maccatalyst_specific_module_dir}
651
+ COMMAND
652
+ "${PYTHON_EXECUTABLE} " "${line_directive_tool} " "@${file_path} " --
653
+ "${swift_compiler_tool} " "-emit-module" "-o" "${maccatalyst_module_file} "
654
+ ${maccatalyst_swift_flags} ${maccatalyst_swift_module_flags} "@${file_path} "
655
+ ${command_touch_maccatalyst_module_outputs}
656
+ OUTPUT
657
+ ${maccatalyst_module_outputs}
658
+ DEPENDS
659
+ ${swift_compiler_tool_dep}
660
+ ${source_files}
661
+ ${SWIFTFILE_DEPENDS}
662
+ ${swift_ide_test_dependency}
663
+ ${obj_dirs_dependency_target}
664
+ COMMENT
665
+ "Generating ${maccatalyst_module_file} " )
666
+
667
+ # Piggy-back on the same out-var as the regular swiftmodule
668
+ set ("${dependency_module_target_out_var_name} "
669
+ "${module_dependency_target} "
670
+ "${maccatalyst_module_dependency_target} "
671
+ PARENT_SCOPE )
672
+ endif ()
673
+
519
674
# This is the target to generate the .sib files. It is not built by default.
520
675
add_custom_command_target (
521
676
sib_dependency_target
0 commit comments