Skip to content

[ClangImporter] Add the sysroot directly to the clang Driver used to find the libc header path #60804

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

Merged
merged 1 commit into from
Aug 31, 2022
Merged
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
15 changes: 2 additions & 13 deletions lib/ClangImporter/ClangIncludePaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,8 @@ createClangArgs(const ASTContext &ctx, clang::driver::Driver &clangDriver) {
// If an SDK path was explicitly passed to Swift, make sure to pass it to
// Clang driver as well. It affects the resulting include paths.
auto sdkPath = ctx.SearchPathOpts.getSDKPath();
if (!sdkPath.empty()) {
unsigned argIndex = clangDriverArgs.MakeIndex("--sysroot", sdkPath);
clangDriverArgs.append(new llvm::opt::Arg(
clangDriver.getOpts().getOption(clang::driver::options::OPT__sysroot),
sdkPath, argIndex));
}
if (!sdkPath.empty())
clangDriver.SysRoot = sdkPath.str();
return clangDriverArgs;
}

Expand Down Expand Up @@ -212,13 +208,6 @@ getGlibcFileMapping(ASTContext &ctx) {
// FIXME: Emit a warning of some kind.
return {};

// Only inject the module map if it actually exists. It may not, for example
// if `swiftc -target x86_64-unknown-linux-gnu -emit-ir` is invoked using
// a Swift compiler not built for Linux targets.
if (!llvm::sys::fs::exists(actualModuleMapPath))
// FIXME: emit a warning of some kind.
return {};

// TODO: remove the SwiftGlibc.h header and reference all Glibc headers
// directly from the modulemap.
Path actualHeaderPath = actualModuleMapPath;
Expand Down