Skip to content

Commit c6745e6

Browse files
authored
Fix Swift Compiler Modules support in Debug mode (swiftlang#73506)
The new `swift-driver` seems to enqueue a `wrapmodule` job which uses the given `module-name` to form the output file name when not doing optmizations (seems to happen only for `-Onone` in my testing). Since the CMake functions macros are using the module name also as the explicit output name, this clashes and ends up in an unhelpful error message from the driver. ``` SwiftDriverExecution/MultiJobExecutor.swift:207: Fatal error: multiple producers for output ... SwiftCompilerSources/Basic.o: Wrapping Swift module Basic & Compiling Basic SourceLoc.swift ``` This was reported in https://forums.swift.org/t/debug-swift-build-fails/71380 The changes use a different output object name (by using `.object.o` suffix) which does not clash with what the `swift-driver` does automatically. The code around the output objects and the static libraries have to change slightly to handle this case. Additionally, the resulting library when in `Debug` is now declaring its dependency on `swiftSwiftOnoneSupport`, to avoid linking errors when the libraries are used in the final binaries. Debug mode seems to enable PURE_BRIDGING_MODE, which seems to skip transitively including some C headers that files like `Utilities/Test.swift` depend on. To avoid errors building, add the missing include in a new `#else` branch. I think CI will not test the `Debug` mode, so the only thing that it can prove is that these changes do not break the `Release` mode.
1 parent 39886be commit c6745e6

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

SwiftCompilerSources/CMakeLists.txt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,20 @@ function(add_swift_compiler_modules_library name)
204204
endforeach()
205205
endif()
206206

207-
set(module_obj_file "${build_dir}/${module}.o")
207+
if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
208+
# swift-driver when non-optimizing in not Mach-O platforms adds an extra
209+
# job wrapmodule that uses the {module-name}.o as output, which clashes
210+
# with the name chosen here. Use a different name in those cases.
211+
set(module_obj_file "${build_dir}/${module}.object.o")
212+
set(output_obj_files "${module_obj_file}" "${build_dir}/${module}.o")
213+
else()
214+
set(module_obj_file "${build_dir}/${module}.o")
215+
set(output_obj_files "${module_obj_file}")
216+
endif()
208217
set(module_file "${build_dir}/${module}.swiftmodule")
209218
list(APPEND all_module_files ${module_file})
210219

211-
set(all_obj_files ${all_obj_files} ${module_obj_file})
220+
list(APPEND all_obj_files ${output_obj_files})
212221
set(c_include_paths
213222
# LLVM modules and headers.
214223
"${LLVM_MAIN_INCLUDE_DIR}"
@@ -237,7 +246,7 @@ function(add_swift_compiler_modules_library name)
237246
${c_include_paths_args}
238247
# Generated swift modules.
239248
"-I" "${build_dir}"
240-
OUTPUT ${module_obj_file}
249+
OUTPUT ${output_obj_files}
241250
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
242251
DEPENDS ${sources} ${deps} ${ALS_DEPENDS}
243252
importedHeaderDependencies
@@ -260,6 +269,9 @@ function(add_swift_compiler_modules_library name)
260269
add_library(${name} STATIC ${all_obj_files})
261270
add_dependencies(${name} ${all_module_targets})
262271
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE CXX)
272+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
273+
target_link_libraries(${name} PUBLIC swiftSwiftOnoneSupport)
274+
endif()
263275

264276
# Downstream linking should include the swiftmodule in debug builds to allow lldb to
265277
# work correctly. Only do this on Darwin since neither gold (currently used by default

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ void SILCombine_registerInstructionPass(BridgedStringRef instClassName,
388388
#ifndef PURE_BRIDGING_MODE
389389
// In _not_ PURE_BRIDGING_MODE, briding functions are inlined and therefore inluded in the header file.
390390
#include "OptimizerBridgingImpl.h"
391+
#else
392+
// For fflush and stdout
393+
#include <stdio.h>
391394
#endif
392395

393396
SWIFT_END_NULLABILITY_ANNOTATIONS

0 commit comments

Comments
 (0)