Propagate sysroot to module loader subinvocation

To fix the Android build issue https://github.com/swiftlang/swift/issues/79839
This commit is contained in:
Hiroshi Yamauchi
2025-03-13 16:25:44 -07:00
parent cc145482de
commit 1a3a6e1c66
7 changed files with 29 additions and 9 deletions

View File

@@ -1215,6 +1215,7 @@ class ModuleInterfaceLoaderImpl {
ctx.SourceMgr, diagsToUse,
astDelegate, interfacePath,
ctx.SearchPathOpts.getSDKPath(),
ctx.SearchPathOpts.getSysRoot(),
realName.str(), cacheDir,
prebuiltCacheDir, backupInterfaceDir, StringRef(),
Opts.disableInterfaceLock,
@@ -1250,6 +1251,7 @@ class ModuleInterfaceLoaderImpl {
ImplicitModuleInterfaceBuilder fallbackBuilder(
ctx.SourceMgr, &ctx.Diags, astDelegate, backupPath,
ctx.SearchPathOpts.getSDKPath(),
ctx.SearchPathOpts.getSysRoot(),
moduleName, cacheDir,
prebuiltCacheDir, backupInterfaceDir, StringRef(),
Opts.disableInterfaceLock,
@@ -1475,6 +1477,7 @@ bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(
RequireOSSAModules);
ImplicitModuleInterfaceBuilder builder(SourceMgr, &Diags, astDelegate, InPath,
SearchPathOpts.getSDKPath(),
SearchPathOpts.getSysRoot(),
ModuleName, CacheDir, PrebuiltCacheDir,
BackupInterfaceDir, ABIOutputPath,
LoaderOpts.disableInterfaceLock,
@@ -1495,6 +1498,7 @@ bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(
assert(!backInPath.empty());
ImplicitModuleInterfaceBuilder backupBuilder(SourceMgr, &Diags, astDelegate, backInPath,
SearchPathOpts.getSDKPath(),
SearchPathOpts.getSysRoot(),
ModuleName, CacheDir, PrebuiltCacheDir,
BackupInterfaceDir, ABIOutputPath,
LoaderOpts.disableInterfaceLock,
@@ -2049,12 +2053,13 @@ std::error_code
InterfaceSubContextDelegateImpl::runInSubContext(StringRef moduleName,
StringRef interfacePath,
StringRef sdkPath,
std::optional<StringRef> sysroot,
StringRef outputPath,
SourceLoc diagLoc,
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*, ArrayRef<StringRef>,
StringRef, StringRef)> action) {
return runInSubCompilerInstance(moduleName, interfacePath, sdkPath, outputPath,
diagLoc, /*silenceErrors=*/false,
return runInSubCompilerInstance(moduleName, interfacePath, sdkPath, sysroot,
outputPath, diagLoc, /*silenceErrors=*/false,
[&](SubCompilerInstanceInfo &info){
std::string UserModuleVer = info.Instance->getInvocation().getFrontendOptions()
.UserModuleVersion.getAsString();
@@ -2070,6 +2075,7 @@ std::error_code
InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
StringRef interfacePath,
StringRef sdkPath,
std::optional<StringRef> sysroot,
StringRef outputPath,
SourceLoc diagLoc,
bool silenceErrors,
@@ -2101,6 +2107,9 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
subInvocation.setModuleName(moduleName);
BuildArgs.push_back("-module-name");
BuildArgs.push_back(moduleName);
if (sysroot) {
subInvocation.setSysRoot(sysroot.value());
}
// FIXME: Hack for Darwin.swiftmodule, which cannot be rebuilt with C++
// interop enabled by the Swift CI because it uses an old host SDK.