Skip to content

Commit 1a3a6e1

Browse files
committed
Propagate sysroot to module loader subinvocation
To fix the Android build issue #79839
1 parent cc14548 commit 1a3a6e1

File tree

7 files changed

+29
-9
lines changed

7 files changed

+29
-9
lines changed

include/swift/AST/ModuleLoader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ struct InterfaceSubContextDelegate {
209209
virtual std::error_code runInSubContext(StringRef moduleName,
210210
StringRef interfacePath,
211211
StringRef sdkPath,
212+
std::optional<StringRef> sysroot,
212213
StringRef outputPath,
213214
SourceLoc diagLoc,
214215
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*,
@@ -217,6 +218,7 @@ struct InterfaceSubContextDelegate {
217218
virtual std::error_code runInSubCompilerInstance(StringRef moduleName,
218219
StringRef interfacePath,
219220
StringRef sdkPath,
221+
std::optional<StringRef> sysroot,
220222
StringRef outputPath,
221223
SourceLoc diagLoc,
222224
bool silenceErrors,

include/swift/Frontend/Frontend.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ class CompilerInvocation {
222222
SearchPathOpts.VFSOverlayFiles = Overlays;
223223
}
224224

225+
void setSysRoot(StringRef SysRoot) {
226+
SearchPathOpts.setSysRoot(SysRoot);
227+
}
228+
225229
void setExtraClangArgs(const std::vector<std::string> &Args) {
226230
ClangImporterOpts.ExtraArgs = Args;
227231
}

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ struct InterfaceSubContextDelegateImpl : InterfaceSubContextDelegate {
702702
std::error_code runInSubContext(StringRef moduleName,
703703
StringRef interfacePath,
704704
StringRef sdkPath,
705+
std::optional<StringRef> sysroot,
705706
StringRef outputPath,
706707
SourceLoc diagLoc,
707708
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*,
@@ -710,6 +711,7 @@ struct InterfaceSubContextDelegateImpl : InterfaceSubContextDelegate {
710711
std::error_code runInSubCompilerInstance(StringRef moduleName,
711712
StringRef interfacePath,
712713
StringRef sdkPath,
714+
std::optional<StringRef> sysroot,
713715
StringRef outputPath,
714716
SourceLoc diagLoc,
715717
bool silenceErrors,

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ bool ImplicitModuleInterfaceBuilder::buildSwiftModuleInternal(
356356
}
357357

358358
SubError = (bool)subASTDelegate.runInSubCompilerInstance(
359-
moduleName, interfacePath, sdkPath, OutPath, diagnosticLoc,
359+
moduleName, interfacePath, sdkPath, sysroot, OutPath, diagnosticLoc,
360360
silenceInterfaceDiagnostics,
361361
[&](SubCompilerInstanceInfo &info) {
362362
auto EBuilder = ExplicitModuleInterfaceBuilder(

lib/Frontend/ModuleInterfaceBuilder.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class ImplicitModuleInterfaceBuilder {
4242
InterfaceSubContextDelegate &subASTDelegate;
4343
const StringRef interfacePath;
4444
const StringRef sdkPath;
45+
const std::optional<StringRef> sysroot;
4546
const StringRef moduleName;
4647
const StringRef moduleCachePath;
4748
const StringRef prebuiltCachePath;
@@ -87,15 +88,17 @@ class ImplicitModuleInterfaceBuilder {
8788
SourceManager &sourceMgr, DiagnosticEngine *diags,
8889
InterfaceSubContextDelegate &subASTDelegate,
8990
StringRef interfacePath, StringRef sdkPath,
90-
StringRef moduleName, StringRef moduleCachePath,
91-
StringRef backupInterfaceDir, StringRef prebuiltCachePath,
92-
StringRef ABIDescriptorPath, bool disableInterfaceFileLock = false,
91+
std::optional<StringRef> sysroot, StringRef moduleName,
92+
StringRef moduleCachePath, StringRef backupInterfaceDir,
93+
StringRef prebuiltCachePath, StringRef ABIDescriptorPath,
94+
bool disableInterfaceFileLock = false,
9395
bool silenceInterfaceDiagnostics = false,
9496
SourceLoc diagnosticLoc = SourceLoc(),
9597
DependencyTracker *tracker = nullptr)
9698
: sourceMgr(sourceMgr), diags(diags), subASTDelegate(subASTDelegate),
97-
interfacePath(interfacePath), sdkPath(sdkPath), moduleName(moduleName),
98-
moduleCachePath(moduleCachePath), prebuiltCachePath(prebuiltCachePath),
99+
interfacePath(interfacePath), sdkPath(sdkPath), sysroot(sysroot),
100+
moduleName(moduleName), moduleCachePath(moduleCachePath),
101+
prebuiltCachePath(prebuiltCachePath),
99102
backupInterfaceDir(backupInterfaceDir),
100103
ABIDescriptorPath(ABIDescriptorPath),
101104
disableInterfaceFileLock(disableInterfaceFileLock),

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,7 @@ class ModuleInterfaceLoaderImpl {
12151215
ctx.SourceMgr, diagsToUse,
12161216
astDelegate, interfacePath,
12171217
ctx.SearchPathOpts.getSDKPath(),
1218+
ctx.SearchPathOpts.getSysRoot(),
12181219
realName.str(), cacheDir,
12191220
prebuiltCacheDir, backupInterfaceDir, StringRef(),
12201221
Opts.disableInterfaceLock,
@@ -1250,6 +1251,7 @@ class ModuleInterfaceLoaderImpl {
12501251
ImplicitModuleInterfaceBuilder fallbackBuilder(
12511252
ctx.SourceMgr, &ctx.Diags, astDelegate, backupPath,
12521253
ctx.SearchPathOpts.getSDKPath(),
1254+
ctx.SearchPathOpts.getSysRoot(),
12531255
moduleName, cacheDir,
12541256
prebuiltCacheDir, backupInterfaceDir, StringRef(),
12551257
Opts.disableInterfaceLock,
@@ -1475,6 +1477,7 @@ bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(
14751477
RequireOSSAModules);
14761478
ImplicitModuleInterfaceBuilder builder(SourceMgr, &Diags, astDelegate, InPath,
14771479
SearchPathOpts.getSDKPath(),
1480+
SearchPathOpts.getSysRoot(),
14781481
ModuleName, CacheDir, PrebuiltCacheDir,
14791482
BackupInterfaceDir, ABIOutputPath,
14801483
LoaderOpts.disableInterfaceLock,
@@ -1495,6 +1498,7 @@ bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(
14951498
assert(!backInPath.empty());
14961499
ImplicitModuleInterfaceBuilder backupBuilder(SourceMgr, &Diags, astDelegate, backInPath,
14971500
SearchPathOpts.getSDKPath(),
1501+
SearchPathOpts.getSysRoot(),
14981502
ModuleName, CacheDir, PrebuiltCacheDir,
14991503
BackupInterfaceDir, ABIOutputPath,
15001504
LoaderOpts.disableInterfaceLock,
@@ -2049,12 +2053,13 @@ std::error_code
20492053
InterfaceSubContextDelegateImpl::runInSubContext(StringRef moduleName,
20502054
StringRef interfacePath,
20512055
StringRef sdkPath,
2056+
std::optional<StringRef> sysroot,
20522057
StringRef outputPath,
20532058
SourceLoc diagLoc,
20542059
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*, ArrayRef<StringRef>,
20552060
StringRef, StringRef)> action) {
2056-
return runInSubCompilerInstance(moduleName, interfacePath, sdkPath, outputPath,
2057-
diagLoc, /*silenceErrors=*/false,
2061+
return runInSubCompilerInstance(moduleName, interfacePath, sdkPath, sysroot,
2062+
outputPath, diagLoc, /*silenceErrors=*/false,
20582063
[&](SubCompilerInstanceInfo &info){
20592064
std::string UserModuleVer = info.Instance->getInvocation().getFrontendOptions()
20602065
.UserModuleVersion.getAsString();
@@ -2070,6 +2075,7 @@ std::error_code
20702075
InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
20712076
StringRef interfacePath,
20722077
StringRef sdkPath,
2078+
std::optional<StringRef> sysroot,
20732079
StringRef outputPath,
20742080
SourceLoc diagLoc,
20752081
bool silenceErrors,
@@ -2101,6 +2107,9 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
21012107
subInvocation.setModuleName(moduleName);
21022108
BuildArgs.push_back("-module-name");
21032109
BuildArgs.push_back(moduleName);
2110+
if (sysroot) {
2111+
subInvocation.setSysRoot(sysroot.value());
2112+
}
21042113

21052114
// FIXME: Hack for Darwin.swiftmodule, which cannot be rebuilt with C++
21062115
// interop enabled by the Swift CI because it uses an old host SDK.

lib/Serialization/ScanningLoaders.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath,
155155
std::optional<ModuleDependencyInfo> Result;
156156
std::error_code code = astDelegate.runInSubContext(
157157
realModuleName.str(), moduleInterfacePath.str(), sdkPath,
158-
StringRef(), SourceLoc(),
158+
Ctx.SearchPathOpts.getSysRoot(), StringRef(), SourceLoc(),
159159
[&](ASTContext &Ctx, ModuleDecl *mainMod, ArrayRef<StringRef> BaseArgs,
160160
StringRef Hash, StringRef UserModVer) {
161161
assert(mainMod);

0 commit comments

Comments
 (0)