diff --git a/lib/ClangImporter/ClangIncludePaths.cpp b/lib/ClangImporter/ClangIncludePaths.cpp index 59afe4fbb3332..7fe8c626f8b64 100644 --- a/lib/ClangImporter/ClangIncludePaths.cpp +++ b/lib/ClangImporter/ClangIncludePaths.cpp @@ -27,6 +27,7 @@ using Path = SmallString<128>; static Optional getActualModuleMapPath( StringRef name, SearchPathOptions &Opts, const llvm::Triple &triple, + bool isArchSpecific, const llvm::IntrusiveRefCntPtr &vfs) { StringRef platform = swift::getPlatformNameForTriple(triple); StringRef arch = swift::getMajorArchitectureName(triple); @@ -37,7 +38,11 @@ static Optional getActualModuleMapPath( if (!SDKPath.empty()) { result.append(SDKPath.begin(), SDKPath.end()); llvm::sys::path::append(result, "usr", "lib", "swift"); - llvm::sys::path::append(result, platform, arch, name); + llvm::sys::path::append(result, platform, arch); + if (isArchSpecific) { + llvm::sys::path::append(result, arch); + } + llvm::sys::path::append(result, name); // Only specify the module map if that file actually exists. It may not; // for example in the case that `swiftc -target x86_64-unknown-linux-gnu @@ -50,7 +55,11 @@ static Optional getActualModuleMapPath( result.clear(); result.append(Opts.RuntimeResourcePath.begin(), Opts.RuntimeResourcePath.end()); - llvm::sys::path::append(result, platform, arch, name); + llvm::sys::path::append(result, platform); + if (isArchSpecific) { + llvm::sys::path::append(result, arch); + } + llvm::sys::path::append(result, name); // Only specify the module map if that file actually exists. It may not; // for example in the case that `swiftc -target x86_64-unknown-linux-gnu @@ -88,19 +97,22 @@ static llvm::Optional getInjectedModuleMapPath( static Optional getGlibcModuleMapPath( SearchPathOptions &Opts, const llvm::Triple &triple, const llvm::IntrusiveRefCntPtr &vfs) { - return getActualModuleMapPath("glibc.modulemap", Opts, triple, vfs); + return getActualModuleMapPath("glibc.modulemap", Opts, triple, + /*isArchSpecific*/ true, vfs); } static Optional getLibStdCxxModuleMapPath( SearchPathOptions &opts, const llvm::Triple &triple, const llvm::IntrusiveRefCntPtr &vfs) { - return getActualModuleMapPath("libstdcxx.modulemap", opts, triple, vfs); + return getActualModuleMapPath("libstdcxx.modulemap", opts, triple, + /*isArchSpecific*/ true, vfs); } Optional> swift::getCxxShimModuleMapPath(SearchPathOptions &opts, const llvm::Triple &triple) { return getActualModuleMapPath("libcxxshim.modulemap", opts, triple, + /*isArchSpecific*/ false, llvm::vfs::getRealFileSystem()); } diff --git a/stdlib/public/Cxx/cxxshim/CMakeLists.txt b/stdlib/public/Cxx/cxxshim/CMakeLists.txt index 1e7e7cff07bfb..961993ab4917e 100644 --- a/stdlib/public/Cxx/cxxshim/CMakeLists.txt +++ b/stdlib/public/Cxx/cxxshim/CMakeLists.txt @@ -1,55 +1,50 @@ set(libcxxshim_modulemap_target_list) foreach(sdk ${SWIFT_SDKS}) - foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES} ${SWIFT_SDK_${sdk}_MODULE_ARCHITECTURES}) - set(arch_suffix "${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}") - set(arch_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}") + set(module_dir "${SWIFTLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}") + set(module_dir_static "${SWIFTSTATICLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}") + + add_custom_command(OUTPUT ${module_dir} + COMMAND ${CMAKE_COMMAND} "-E" "make_directory" "${module_dir}") + if(SWIFT_BUILD_STATIC_STDLIB) + add_custom_command(OUTPUT ${module_dir_static} + COMMAND ${CMAKE_COMMAND} "-E" "make_directory" "${module_dir_static}") + endif() + + set(outputs) + foreach(source libcxxshim.modulemap libcxxshim.h libcxxstdlibshim.h) + add_custom_command(OUTPUT ${module_dir}/${source} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${source} + COMMAND ${CMAKE_COMMAND} "-E" "copy_if_different" "${CMAKE_CURRENT_SOURCE_DIR}/${source}" "${module_dir}/${source}" + COMMENT "Copying ${source} to ${module_dir}") + list(APPEND outputs "${module_dir}/${source}") - set(module_dir "${SWIFTLIB_DIR}/${arch_subdir}") - set(module_dir_static "${SWIFTSTATICLIB_DIR}/${arch_subdir}") - - add_custom_command(OUTPUT ${module_dir} - COMMAND ${CMAKE_COMMAND} "-E" "make_directory" "${module_dir}") if(SWIFT_BUILD_STATIC_STDLIB) - add_custom_command(OUTPUT ${module_dir_static} - COMMAND ${CMAKE_COMMAND} "-E" "make_directory" "${module_dir_static}") - endif() - - set(outputs) - foreach(source libcxxshim.modulemap libcxxshim.h libcxxstdlibshim.h) - add_custom_command(OUTPUT ${module_dir}/${source} + add_custom_command(OUTPUT ${module_dir_static}/${source} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${source} - COMMAND ${CMAKE_COMMAND} "-E" "copy_if_different" "${CMAKE_CURRENT_SOURCE_DIR}/${source}" "${module_dir}/${source}" - COMMENT "Copying ${source} to ${module_dir}") - list(APPEND outputs "${module_dir}/${source}") - - if(SWIFT_BUILD_STATIC_STDLIB) - add_custom_command(OUTPUT ${module_dir_static}/${source} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${source} - COMMAND ${CMAKE_COMMAND} "-E" "copy_if_different" "${CMAKE_CURRENT_SOURCE_DIR}/${source}" "${module_dir_static}/${source}" - COMMENT "Copying ${source} to ${module_dir_static}") - list(APPEND outputs "${module_dir_static}/${source}") - endif() - endforeach() - list(APPEND outputs ${module_dir}) - if(SWIFT_BUILD_STATIC_STDLIB) - list(APPEND outputs ${module_dir_static}) + COMMAND ${CMAKE_COMMAND} "-E" "copy_if_different" "${CMAKE_CURRENT_SOURCE_DIR}/${source}" "${module_dir_static}/${source}" + COMMENT "Copying ${source} to ${module_dir_static}") + list(APPEND outputs "${module_dir_static}/${source}") endif() + endforeach() + list(APPEND outputs ${module_dir}) + if(SWIFT_BUILD_STATIC_STDLIB) + list(APPEND outputs ${module_dir_static}) + endif() - add_custom_target(cxxshim-${sdk}-${arch} ALL - DEPENDS ${outputs} - COMMENT "Copying cxxshims to ${module_dir}") - list(APPEND libcxxshim_modulemap_target_list cxxshim-${sdk}-${arch}) + add_custom_target(cxxshim-${sdk} ALL + DEPENDS ${outputs} + COMMENT "Copying cxxshims to ${module_dir}") + list(APPEND libcxxshim_modulemap_target_list cxxshim-${sdk}) + swift_install_in_component(FILES libcxxshim.modulemap libcxxshim.h libcxxstdlibshim.h + DESTINATION "lib/swift/${SWIFT_SDK_${sdk}_LIB_SUBDIR}" + COMPONENT compiler) + if(SWIFT_BUILD_STATIC_STDLIB) swift_install_in_component(FILES libcxxshim.modulemap libcxxshim.h libcxxstdlibshim.h - DESTINATION "lib/swift/${arch_subdir}" + DESTINATION "lib/swift_static/${SWIFT_SDK_${sdk}_LIB_SUBDIR}" COMPONENT compiler) - if(SWIFT_BUILD_STATIC_STDLIB) - swift_install_in_component(FILES libcxxshim.modulemap libcxxshim.h libcxxstdlibshim.h - DESTINATION "lib/swift_static/${arch_subdir}" - COMPONENT compiler) - endif() - endforeach() + endif() endforeach() add_custom_target(libcxxshim_modulemap DEPENDS ${libcxxshim_modulemap_target_list})