Skip to content

Commit fbf15ae

Browse files
authored
Merge pull request #66765 from apple/egorzhdan/arch-independent-cxxshim
[cxx-interop] Make CxxShim header and modulemap arch-independent
2 parents 84a2f33 + 4ce4527 commit fbf15ae

File tree

2 files changed

+52
-45
lines changed

2 files changed

+52
-45
lines changed

lib/ClangImporter/ClangIncludePaths.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ using Path = SmallString<128>;
2727

2828
static Optional<Path> getActualModuleMapPath(
2929
StringRef name, SearchPathOptions &Opts, const llvm::Triple &triple,
30+
bool isArchSpecific,
3031
const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs) {
3132
StringRef platform = swift::getPlatformNameForTriple(triple);
3233
StringRef arch = swift::getMajorArchitectureName(triple);
@@ -37,7 +38,11 @@ static Optional<Path> getActualModuleMapPath(
3738
if (!SDKPath.empty()) {
3839
result.append(SDKPath.begin(), SDKPath.end());
3940
llvm::sys::path::append(result, "usr", "lib", "swift");
40-
llvm::sys::path::append(result, platform, arch, name);
41+
llvm::sys::path::append(result, platform, arch);
42+
if (isArchSpecific) {
43+
llvm::sys::path::append(result, arch);
44+
}
45+
llvm::sys::path::append(result, name);
4146

4247
// Only specify the module map if that file actually exists. It may not;
4348
// for example in the case that `swiftc -target x86_64-unknown-linux-gnu
@@ -50,7 +55,11 @@ static Optional<Path> getActualModuleMapPath(
5055
result.clear();
5156
result.append(Opts.RuntimeResourcePath.begin(),
5257
Opts.RuntimeResourcePath.end());
53-
llvm::sys::path::append(result, platform, arch, name);
58+
llvm::sys::path::append(result, platform);
59+
if (isArchSpecific) {
60+
llvm::sys::path::append(result, arch);
61+
}
62+
llvm::sys::path::append(result, name);
5463

5564
// Only specify the module map if that file actually exists. It may not;
5665
// for example in the case that `swiftc -target x86_64-unknown-linux-gnu
@@ -88,19 +97,22 @@ static llvm::Optional<Path> getInjectedModuleMapPath(
8897
static Optional<Path> getGlibcModuleMapPath(
8998
SearchPathOptions &Opts, const llvm::Triple &triple,
9099
const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs) {
91-
return getActualModuleMapPath("glibc.modulemap", Opts, triple, vfs);
100+
return getActualModuleMapPath("glibc.modulemap", Opts, triple,
101+
/*isArchSpecific*/ true, vfs);
92102
}
93103

94104
static Optional<Path> getLibStdCxxModuleMapPath(
95105
SearchPathOptions &opts, const llvm::Triple &triple,
96106
const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs) {
97-
return getActualModuleMapPath("libstdcxx.modulemap", opts, triple, vfs);
107+
return getActualModuleMapPath("libstdcxx.modulemap", opts, triple,
108+
/*isArchSpecific*/ true, vfs);
98109
}
99110

100111
Optional<SmallString<128>>
101112
swift::getCxxShimModuleMapPath(SearchPathOptions &opts,
102113
const llvm::Triple &triple) {
103114
return getActualModuleMapPath("libcxxshim.modulemap", opts, triple,
115+
/*isArchSpecific*/ false,
104116
llvm::vfs::getRealFileSystem());
105117
}
106118

stdlib/public/Cxx/cxxshim/CMakeLists.txt

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,50 @@
11
set(libcxxshim_modulemap_target_list)
22
foreach(sdk ${SWIFT_SDKS})
3-
foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES} ${SWIFT_SDK_${sdk}_MODULE_ARCHITECTURES})
4-
set(arch_suffix "${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")
5-
set(arch_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}")
3+
set(module_dir "${SWIFTLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}")
4+
set(module_dir_static "${SWIFTSTATICLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}")
5+
6+
add_custom_command(OUTPUT ${module_dir}
7+
COMMAND ${CMAKE_COMMAND} "-E" "make_directory" "${module_dir}")
8+
if(SWIFT_BUILD_STATIC_STDLIB)
9+
add_custom_command(OUTPUT ${module_dir_static}
10+
COMMAND ${CMAKE_COMMAND} "-E" "make_directory" "${module_dir_static}")
11+
endif()
12+
13+
set(outputs)
14+
foreach(source libcxxshim.modulemap libcxxshim.h libcxxstdlibshim.h)
15+
add_custom_command(OUTPUT ${module_dir}/${source}
16+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${source}
17+
COMMAND ${CMAKE_COMMAND} "-E" "copy_if_different" "${CMAKE_CURRENT_SOURCE_DIR}/${source}" "${module_dir}/${source}"
18+
COMMENT "Copying ${source} to ${module_dir}")
19+
list(APPEND outputs "${module_dir}/${source}")
620

7-
set(module_dir "${SWIFTLIB_DIR}/${arch_subdir}")
8-
set(module_dir_static "${SWIFTSTATICLIB_DIR}/${arch_subdir}")
9-
10-
add_custom_command(OUTPUT ${module_dir}
11-
COMMAND ${CMAKE_COMMAND} "-E" "make_directory" "${module_dir}")
1221
if(SWIFT_BUILD_STATIC_STDLIB)
13-
add_custom_command(OUTPUT ${module_dir_static}
14-
COMMAND ${CMAKE_COMMAND} "-E" "make_directory" "${module_dir_static}")
15-
endif()
16-
17-
set(outputs)
18-
foreach(source libcxxshim.modulemap libcxxshim.h libcxxstdlibshim.h)
19-
add_custom_command(OUTPUT ${module_dir}/${source}
22+
add_custom_command(OUTPUT ${module_dir_static}/${source}
2023
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${source}
21-
COMMAND ${CMAKE_COMMAND} "-E" "copy_if_different" "${CMAKE_CURRENT_SOURCE_DIR}/${source}" "${module_dir}/${source}"
22-
COMMENT "Copying ${source} to ${module_dir}")
23-
list(APPEND outputs "${module_dir}/${source}")
24-
25-
if(SWIFT_BUILD_STATIC_STDLIB)
26-
add_custom_command(OUTPUT ${module_dir_static}/${source}
27-
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${source}
28-
COMMAND ${CMAKE_COMMAND} "-E" "copy_if_different" "${CMAKE_CURRENT_SOURCE_DIR}/${source}" "${module_dir_static}/${source}"
29-
COMMENT "Copying ${source} to ${module_dir_static}")
30-
list(APPEND outputs "${module_dir_static}/${source}")
31-
endif()
32-
endforeach()
33-
list(APPEND outputs ${module_dir})
34-
if(SWIFT_BUILD_STATIC_STDLIB)
35-
list(APPEND outputs ${module_dir_static})
24+
COMMAND ${CMAKE_COMMAND} "-E" "copy_if_different" "${CMAKE_CURRENT_SOURCE_DIR}/${source}" "${module_dir_static}/${source}"
25+
COMMENT "Copying ${source} to ${module_dir_static}")
26+
list(APPEND outputs "${module_dir_static}/${source}")
3627
endif()
28+
endforeach()
29+
list(APPEND outputs ${module_dir})
30+
if(SWIFT_BUILD_STATIC_STDLIB)
31+
list(APPEND outputs ${module_dir_static})
32+
endif()
3733

38-
add_custom_target(cxxshim-${sdk}-${arch} ALL
39-
DEPENDS ${outputs}
40-
COMMENT "Copying cxxshims to ${module_dir}")
41-
list(APPEND libcxxshim_modulemap_target_list cxxshim-${sdk}-${arch})
34+
add_custom_target(cxxshim-${sdk} ALL
35+
DEPENDS ${outputs}
36+
COMMENT "Copying cxxshims to ${module_dir}")
37+
list(APPEND libcxxshim_modulemap_target_list cxxshim-${sdk})
4238

4339

40+
swift_install_in_component(FILES libcxxshim.modulemap libcxxshim.h libcxxstdlibshim.h
41+
DESTINATION "lib/swift/${SWIFT_SDK_${sdk}_LIB_SUBDIR}"
42+
COMPONENT compiler)
43+
if(SWIFT_BUILD_STATIC_STDLIB)
4444
swift_install_in_component(FILES libcxxshim.modulemap libcxxshim.h libcxxstdlibshim.h
45-
DESTINATION "lib/swift/${arch_subdir}"
45+
DESTINATION "lib/swift_static/${SWIFT_SDK_${sdk}_LIB_SUBDIR}"
4646
COMPONENT compiler)
47-
if(SWIFT_BUILD_STATIC_STDLIB)
48-
swift_install_in_component(FILES libcxxshim.modulemap libcxxshim.h libcxxstdlibshim.h
49-
DESTINATION "lib/swift_static/${arch_subdir}"
50-
COMPONENT compiler)
51-
endif()
52-
endforeach()
47+
endif()
5348
endforeach()
5449

5550
add_custom_target(libcxxshim_modulemap DEPENDS ${libcxxshim_modulemap_target_list})

0 commit comments

Comments
 (0)