Skip to content

[ClangImporter] Look for platform modulemaps in the resource dir first #76036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 52 additions & 30 deletions lib/ClangImporter/ClangIncludePaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,64 @@ static std::optional<Path> getActualModuleMapPath(
StringRef platform = swift::getPlatformNameForTriple(triple);
StringRef arch = swift::getMajorArchitectureName(triple);

Path result;

StringRef SDKPath = Opts.getSDKPath();
if (!SDKPath.empty()) {
result.append(SDKPath.begin(), SDKPath.end());
llvm::sys::path::append(result, "usr", "lib", "swift");
llvm::sys::path::append(result, platform);
if (isArchSpecific) {
llvm::sys::path::append(result, arch);
auto checkRuntimeResourcesPath = [&]() -> std::optional<Path> {
Path result;
if (!Opts.RuntimeResourcePath.empty()) {
result.append(Opts.RuntimeResourcePath.begin(),
Opts.RuntimeResourcePath.end());
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
// -emit-ir` is invoked using a Swift compiler not built for Linux
// targets.
if (vfs->exists(result))
return result;
}
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
// -emit-ir` is invoked using a Swift compiler not built for Linux targets.
if (vfs->exists(result))
return result;
}
return std::nullopt;
};

if (!Opts.RuntimeResourcePath.empty()) {
result.clear();
result.append(Opts.RuntimeResourcePath.begin(),
Opts.RuntimeResourcePath.end());
llvm::sys::path::append(result, platform);
if (isArchSpecific) {
llvm::sys::path::append(result, arch);
auto checkSDKPath = [&]() -> std::optional<Path> {
Path result;
StringRef SDKPath = Opts.getSDKPath();
if (!SDKPath.empty()) {
result.append(SDKPath.begin(), SDKPath.end());
llvm::sys::path::append(result, "usr", "lib", "swift");
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
// -emit-ir` is invoked using a Swift compiler not built for Linux
// targets.
if (vfs->exists(result))
return result;
}
llvm::sys::path::append(result, name);
return std::nullopt;
};

// 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
// -emit-ir` is invoked using a Swift compiler not built for Linux targets.
if (vfs->exists(result))
return result;
// FIXME: This is a workaround to keep the Android SDK build working.
// See https://github.com/swiftlang/swift/pull/74814.
if (triple.isAndroid()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this Android block inside a #if defined(_WIN32) || defined(_WIN64), as only The Browser Company's upcoming Android SDK that is only used on Windows and uses a new experimental SDK layout fails with this pull.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if that's the best approach, I'm curious what @compnerd @hyp think is the best solution here.

if (auto path = checkSDKPath())
return path;
if (auto path = checkRuntimeResourcesPath())
return path;
return std::nullopt;
}

if (auto path = checkRuntimeResourcesPath())
return path;
if (auto path = checkSDKPath())
return path;

return std::nullopt;
}

Expand Down