Skip to content

Commit c3b8d1a

Browse files
committed
Driver: introduce -sysroot option for non-Darwin targets
This introduces a secondary flag `-sysroot` for the non-Darwin targets, primarily Unicies. The intention here is to support a split `-sdk`, `-sysroot` model where the `-sdk` parameter provides the Swift "SDK" which augments the native platform's C sysroot which is indicated as `-sysroot`. For the case of Android, this would allow us to provide a path to the NDK sysroot and the Swift SDK allowing us to cross-compile Android binaries from Windows.
1 parent 32cd086 commit c3b8d1a

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

include/swift/AST/SearchPathOptions.h

+7
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ class SearchPathOptions {
368368
std::optional<StringRef> VCToolsRoot = std::nullopt;
369369
std::optional<StringRef> VCToolsVersion = std::nullopt;
370370

371+
std::optional<StringRef> SysRoot = std::nullopt;
372+
371373
public:
372374
StringRef getSDKPath() const { return SDKPath; }
373375

@@ -406,6 +408,11 @@ class SearchPathOptions {
406408
VCToolsVersion = version;
407409
}
408410

411+
std::optional<StringRef> getSysRoot() const { return SysRoot; }
412+
void setSysRoot(StringRef sysroot) {
413+
SysRoot = sysroot;
414+
}
415+
409416
ArrayRef<std::string> getImportSearchPaths() const {
410417
return ImportSearchPaths;
411418
}

include/swift/Option/Options.td

+7
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ def visualc_tools_version : Separate<["-"], "visualc-tools-version">,
258258
SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>,
259259
HelpText<"VisualC++ ToolSet Version">, MetaVarName<"<version>">;
260260

261+
// Android Options
262+
263+
def sysroot : Separate<["-"], "sysroot">,
264+
Flags<[ArgumentIsPath, FrontendOption, SwiftAPIExtractOption,
265+
SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>,
266+
HelpText<"Native Platform sysroot">, MetaVarName<"<sysroot>">;
267+
261268
// Standard Options
262269
def _DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>,
263270
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>;

lib/ClangImporter/ClangIncludePaths.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ createClangArgs(const ASTContext &ctx, clang::driver::Driver &clangDriver) {
175175
auto sdkPath = ctx.SearchPathOpts.getSDKPath();
176176
if (!sdkPath.empty())
177177
clangDriver.SysRoot = sdkPath.str();
178+
if (auto sysroot = ctx.SearchPathOpts.getSysRoot())
179+
clangDriver.SysRoot = sysroot->str();
178180
return clangDriverArgs;
179181
}
180182

lib/Driver/ToolChains.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
243243
arguments.push_back(inputArgs.MakeArgString(A->getValue()));
244244
}
245245

246+
if (const Arg *A = inputArgs.getLastArg(options::OPT_sysroot)) {
247+
arguments.push_back("-sysroot");
248+
arguments.push_back(inputArgs.MakeArgString(A->getValue()));
249+
}
246250

247251
if (llvm::sys::Process::StandardErrHasColors()) {
248252
arguments.push_back("-color-diagnostics");

lib/Frontend/CompilerInvocation.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1919,6 +1919,9 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts,
19191919
if (const Arg *A = Args.getLastArg(OPT_visualc_tools_version))
19201920
Opts.setVCToolsVersion(A->getValue());
19211921

1922+
if (const Arg *A = Args.getLastArg(OPT_sysroot))
1923+
Opts.setSysRoot(A->getValue());
1924+
19221925
if (const Arg *A = Args.getLastArg(OPT_resource_dir))
19231926
Opts.RuntimeResourcePath = A->getValue();
19241927

0 commit comments

Comments
 (0)