Skip to content

Commit 26d8a9f

Browse files
authored
[CMake] Don't pass -embed-bitcode to module generation commands. (#6109)
These are the commands Pete added in 5834df3, doing slightly more work by compiling Swift sources twice in order to start building downstream libraries sooner. Really, we should diagnose when -embed-bitcode is passed here, instead of generating nonsense commands and then falling over. I filed https://bugs.swift.org/browse/SR-3352 for that. rdar://problem/29537164
1 parent 54e8527 commit 26d8a9f

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,11 +599,12 @@ function(_add_swift_library_single target name)
599599
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_LIB_SUBDIR}/${SWIFTLIB_SINGLE_ARCHITECTURE}")
600600

601601
# Include LLVM Bitcode slices for iOS, Watch OS, and Apple TV OS device libraries.
602-
if(SWIFT_EMBED_BITCODE_SECTION AND NOT SWIFTLIB_DONT_EMBED_BITCODE)
602+
set(embed_bitcode_arg)
603+
if(SWIFT_EMBED_BITCODE_SECTION AND NOT SWIFTLIB_SINGLE_DONT_EMBED_BITCODE)
603604
if("${SWIFTLIB_SINGLE_SDK}" STREQUAL "IOS" OR "${SWIFTLIB_SINGLE_SDK}" STREQUAL "TVOS" OR "${SWIFTLIB_SINGLE_SDK}" STREQUAL "WATCHOS")
604605
list(APPEND SWIFTLIB_SINGLE_C_COMPILE_FLAGS "-fembed-bitcode")
605-
list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS "-embed-bitcode")
606606
list(APPEND SWIFTLIB_SINGLE_LINK_FLAGS "-Xlinker" "-bitcode_bundle" "-Xlinker" "-bitcode_hide_symbols" "-Xlinker" "-lto_library" "-Xlinker" "${LLVM_LIBRARY_DIR}/libLTO.dylib")
607+
set(embed_bitcode_arg EMBED_BITCODE)
607608
endif()
608609
endif()
609610

@@ -722,6 +723,7 @@ function(_add_swift_library_single target name)
722723
${SWIFTLIB_SINGLE_IS_STDLIB_keyword}
723724
${SWIFTLIB_SINGLE_IS_STDLIB_CORE_keyword}
724725
${SWIFTLIB_SINGLE_IS_SDK_OVERLAY_keyword}
726+
${embed_bitcode_arg}
725727
INSTALL_IN_COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}")
726728
add_swift_source_group("${SWIFTLIB_SINGLE_EXTERNAL_SOURCES}")
727729

cmake/modules/SwiftSource.cmake

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function(handle_swift_sources
1010
dependency_module_target_out_var_name
1111
sourcesvar externalvar name)
1212
cmake_parse_arguments(SWIFTSOURCES
13-
"IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY"
13+
"IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMBED_BITCODE"
1414
"SDK;ARCHITECTURE;INSTALL_IN_COMPONENT"
1515
"DEPENDS;API_NOTES;COMPILE_FLAGS;MODULE_NAME"
1616
${ARGN})
@@ -20,6 +20,8 @@ function(handle_swift_sources
2020
IS_STDLIB_CORE_arg)
2121
translate_flag(${SWIFTSOURCES_IS_SDK_OVERLAY} "IS_SDK_OVERLAY"
2222
IS_SDK_OVERLAY_arg)
23+
translate_flag(${SWIFTSOURCES_EMBED_BITCODE} "EMBED_BITCODE"
24+
EMBED_BITCODE_arg)
2325

2426
if(SWIFTSOURCES_IS_MAIN)
2527
set(SWIFTSOURCES_INSTALL_IN_COMPONENT never_install)
@@ -94,6 +96,7 @@ function(handle_swift_sources
9496
${IS_STDLIB_arg}
9597
${IS_STDLIB_CORE_arg}
9698
${IS_SDK_OVERLAY_arg}
99+
${EMBED_BITCODE_arg}
97100
${STATIC_arg}
98101
INSTALL_IN_COMPONENT "${SWIFTSOURCES_INSTALL_IN_COMPONENT}")
99102
set("${dependency_target_out_var_name}" "${dependency_target}" PARENT_SCOPE)
@@ -138,11 +141,12 @@ endfunction()
138141
# [MODULE_NAME] # The module name.
139142
# [IS_STDLIB] # Install produced files.
140143
# [EMIT_SIB] # Emit the file as a sib file instead of a .o
144+
# [EMBED_BITCODE] # Embed LLVM bitcode into the .o files
141145
# )
142146
function(_compile_swift_files
143147
dependency_target_out_var_name dependency_module_target_out_var_name)
144148
cmake_parse_arguments(SWIFTFILE
145-
"IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMIT_SIB"
149+
"IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMIT_SIB;EMBED_BITCODE"
146150
"OUTPUT;MODULE_NAME;INSTALL_IN_COMPONENT"
147151
"SOURCES;FLAGS;DEPENDS;SDK;ARCHITECTURE;API_NOTES;OPT_FLAGS;MODULE_DIR"
148152
${ARGN})
@@ -362,6 +366,11 @@ function(_compile_swift_files
362366
set(output_option "-o" ${first_output})
363367
endif()
364368

369+
set(embed_bitcode_option)
370+
if (SWIFTFILE_EMBED_BITCODE)
371+
set(embed_bitcode_option "-embed-bitcode")
372+
endif()
373+
365374
set(main_command "-c")
366375
if (SWIFTFILE_EMIT_SIB)
367376
# Change the command to emit-sib if we are asked to emit sib
@@ -429,7 +438,7 @@ function(_compile_swift_files
429438
COMMAND
430439
"${line_directive_tool}" "${source_files}" --
431440
"${swift_compiler_tool}" "${main_command}" ${swift_flags}
432-
${output_option} "${source_files}"
441+
${output_option} ${embed_bitcode_option} "${source_files}"
433442
${command_touch_standard_outputs}
434443
OUTPUT ${standard_outputs}
435444
DEPENDS

0 commit comments

Comments
 (0)