Skip to content

Commit ae753e6

Browse files
[Driver][Frontend] Add a -nostdlibimport argument
Add a -nostdlibimport (analagous to clang's -nostdlibinc) to remove the SDK paths from the import search paths, but leave the toolchain paths. rdar://139322299
1 parent 55189ba commit ae753e6

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

include/swift/AST/SearchPathOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ class SearchPathOptions {
507507
/// Don't look in for compiler-provided modules.
508508
bool SkipRuntimeLibraryImportPaths = false;
509509

510+
/// Don't include SDK paths in the RuntimeLibraryImportPaths
511+
bool ExcludeSDKPathsFromRuntimeLibraryImportPaths = false;
512+
510513
/// Scanner Prefix Mapper.
511514
std::vector<std::string> ScannerPrefixMapper;
512515

include/swift/Option/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ def incremental : Flag<["-"], "incremental">,
359359
HelpText<"Perform an incremental build if possible">;
360360

361361
def nostdimport : Flag<["-"], "nostdimport">, Flags<[FrontendOption]>,
362+
HelpText<"Don't search the standard library or toolchain import paths for modules">;
363+
def nostdlibimport : Flag<["-"], "nostdlibimport">, Flags<[FrontendOption]>,
362364
HelpText<"Don't search the standard library import path for modules">;
363365

364366
def output_file_map : Separate<["-"], "output-file-map">,

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
296296
inputArgs.AddLastArg(arguments, options::OPT_package_name);
297297
inputArgs.AddLastArg(arguments, options::OPT_export_as);
298298
inputArgs.AddLastArg(arguments, options::OPT_nostdimport);
299+
inputArgs.AddLastArg(arguments, options::OPT_nostdlibimport);
299300
inputArgs.AddLastArg(arguments, options::OPT_parse_stdlib);
300301
inputArgs.AddLastArg(arguments, options::OPT_resource_dir);
301302
inputArgs.AddLastArg(arguments, options::OPT_solver_memory_threshold);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
283283
RuntimeLibraryImportPaths.push_back(std::string(LibPath.str()));
284284
}
285285

286-
if (!SearchPathOpts.getSDKPath().empty()) {
286+
if (!SearchPathOpts.ExcludeSDKPathsFromRuntimeLibraryImportPaths && !SearchPathOpts.getSDKPath().empty()) {
287287
const char *swiftDir = FrontendOpts.UseSharedResourceFolder
288288
? "swift" : "swift_static";
289289

@@ -2261,6 +2261,7 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
22612261
Opts.RuntimeResourcePath = A->getValue();
22622262

22632263
Opts.SkipRuntimeLibraryImportPaths |= Args.hasArg(OPT_nostdimport);
2264+
Opts.ExcludeSDKPathsFromRuntimeLibraryImportPaths |= Args.hasArg(OPT_nostdlibimport);
22642265

22652266
Opts.DisableModulesValidateSystemDependencies |=
22662267
Args.hasArg(OPT_disable_modules_validate_system_headers);

0 commit comments

Comments
 (0)