Skip to content

Commit e73c08c

Browse files
Merge pull request #78378 from ian-twilightcoder/nostdlibimport
[Driver][Frontend] Add a -nostdlibimport argument
2 parents 2dbffa2 + ae753e6 commit e73c08c

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
@@ -504,6 +504,9 @@ class SearchPathOptions {
504504
/// Don't look in for compiler-provided modules.
505505
bool SkipRuntimeLibraryImportPaths = false;
506506

507+
/// Don't include SDK paths in the RuntimeLibraryImportPaths
508+
bool ExcludeSDKPathsFromRuntimeLibraryImportPaths = false;
509+
507510
/// Scanner Prefix Mapper.
508511
std::vector<std::string> ScannerPrefixMapper;
509512

include/swift/Option/Options.td

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

366366
def nostdimport : Flag<["-"], "nostdimport">, Flags<[FrontendOption]>,
367+
HelpText<"Don't search the standard library or toolchain import paths for modules">;
368+
def nostdlibimport : Flag<["-"], "nostdlibimport">, Flags<[FrontendOption]>,
367369
HelpText<"Don't search the standard library import path for modules">;
368370

369371
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

@@ -2264,6 +2264,7 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
22642264
Opts.RuntimeResourcePath = A->getValue();
22652265

22662266
Opts.SkipRuntimeLibraryImportPaths |= Args.hasArg(OPT_nostdimport);
2267+
Opts.ExcludeSDKPathsFromRuntimeLibraryImportPaths |= Args.hasArg(OPT_nostdlibimport);
22672268

22682269
Opts.DisableModulesValidateSystemDependencies |=
22692270
Args.hasArg(OPT_disable_modules_validate_system_headers);

0 commit comments

Comments
 (0)