Skip to content

Commit a02586f

Browse files
committed
[embedded] Include and use cxxshims in the embedded/ resource dir
1 parent 0c860f8 commit a02586f

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ void importer::getNormalInvocationArguments(
574574
}
575575

576576
if (LangOpts.EnableCXXInterop) {
577-
if (auto path = getCxxShimModuleMapPath(searchPathOpts, triple)) {
577+
if (auto path = getCxxShimModuleMapPath(searchPathOpts, LangOpts, triple)) {
578578
invocationArgStrs.push_back((Twine("-fmodule-map-file=") + *path).str());
579579
}
580580
}

lib/ClangImporter/ClangIncludePaths.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@ using namespace swift;
2727
using Path = SmallString<128>;
2828

2929
static std::optional<Path> getActualModuleMapPath(
30-
StringRef name, SearchPathOptions &Opts, const llvm::Triple &triple,
31-
bool isArchSpecific,
30+
StringRef name, SearchPathOptions &Opts, const LangOptions &LangOpts,
31+
const llvm::Triple &triple, bool isArchSpecific,
3232
const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs) {
3333
StringRef platform;
3434
if (swift::tripleIsMacCatalystEnvironment(triple))
3535
platform = "macosx";
3636
else
3737
platform = swift::getPlatformNameForTriple(triple);
38+
39+
if (LangOpts.hasFeature(Feature::Embedded))
40+
platform = "embedded";
41+
3842
StringRef arch = swift::getMajorArchitectureName(triple);
3943

4044
Path result;
@@ -95,16 +99,18 @@ static std::optional<Path> getInjectedModuleMapPath(
9599
}
96100

97101
static std::optional<Path> getLibStdCxxModuleMapPath(
98-
SearchPathOptions &opts, const llvm::Triple &triple,
102+
SearchPathOptions &opts, const LangOptions &langOpts,
103+
const llvm::Triple &triple,
99104
const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs) {
100-
return getActualModuleMapPath("libstdcxx.modulemap", opts, triple,
105+
return getActualModuleMapPath("libstdcxx.modulemap", opts, langOpts, triple,
101106
/*isArchSpecific*/ false, vfs);
102107
}
103108

104109
std::optional<SmallString<128>>
105110
swift::getCxxShimModuleMapPath(SearchPathOptions &opts,
111+
const LangOptions &langOpts,
106112
const llvm::Triple &triple) {
107-
return getActualModuleMapPath("libcxxshim.modulemap", opts, triple,
113+
return getActualModuleMapPath("libcxxshim.modulemap", opts, langOpts, triple,
108114
/*isArchSpecific*/ false,
109115
llvm::vfs::getRealFileSystem());
110116
}
@@ -225,7 +231,8 @@ getLibcFileMapping(ASTContext &ctx, StringRef modulemapFileName,
225231

226232
Path actualModuleMapPath;
227233
if (auto path = getActualModuleMapPath(modulemapFileName, ctx.SearchPathOpts,
228-
triple, /*isArchSpecific*/ true, vfs))
234+
ctx.LangOpts, triple,
235+
/*isArchSpecific*/ true, vfs))
229236
actualModuleMapPath = path.value();
230237
else
231238
// FIXME: Emit a warning of some kind.
@@ -305,7 +312,8 @@ static void getLibStdCxxFileMapping(
305312
}
306313

307314
Path actualModuleMapPath;
308-
if (auto path = getLibStdCxxModuleMapPath(ctx.SearchPathOpts, triple, vfs))
315+
if (auto path = getLibStdCxxModuleMapPath(ctx.SearchPathOpts, ctx.LangOpts,
316+
triple, vfs))
309317
actualModuleMapPath = path.value();
310318
else
311319
return;

lib/ClangImporter/ClangIncludePaths.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
namespace swift {
1919

2020
std::optional<SmallString<128>>
21-
getCxxShimModuleMapPath(SearchPathOptions &opts, const llvm::Triple &triple);
21+
getCxxShimModuleMapPath(SearchPathOptions &opts, const LangOptions &langOpts,
22+
const llvm::Triple &triple);
2223

2324
} // namespace swift
2425

stdlib/public/Cxx/cxxshim/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,27 @@ foreach(sdk ${SWIFT_SDKS})
6767
endif()
6868
endforeach()
6969

70+
if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB)
71+
set(module_dir "${SWIFTLIB_DIR}/embedded")
72+
add_custom_command(OUTPUT ${module_dir}
73+
COMMAND ${CMAKE_COMMAND} "-E" "make_directory" "${module_dir}")
74+
set(outputs)
75+
foreach(source libcxxshim.modulemap libcxxshim.h libcxxstdlibshim.h)
76+
add_custom_command(OUTPUT ${module_dir}/${source}
77+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${source}
78+
COMMAND ${CMAKE_COMMAND} "-E" "copy_if_different" "${CMAKE_CURRENT_SOURCE_DIR}/${source}" "${module_dir}/${source}"
79+
COMMENT "Copying ${source} to ${module_dir}")
80+
list(APPEND outputs "${module_dir}/${source}")
81+
endforeach()
82+
add_custom_target(cxxshim-embedded ALL
83+
DEPENDS ${outputs}
84+
COMMENT "Copying cxxshims to ${module_dir}")
85+
list(APPEND libcxxshim_modulemap_target_list cxxshim-embedded)
86+
swift_install_in_component(FILES libcxxshim.modulemap libcxxshim.h libcxxstdlibshim.h
87+
DESTINATION "lib/swift/embedded"
88+
COMPONENT compiler)
89+
endif()
90+
7091
add_custom_target(libcxxshim_modulemap DEPENDS ${libcxxshim_modulemap_target_list})
7192
set_property(TARGET libcxxshim_modulemap PROPERTY FOLDER "Miscellaneous")
7293
add_dependencies(sdk-overlay libcxxshim_modulemap)

0 commit comments

Comments
 (0)