|
22 | 22 | #include "swift/Driver/Compilation.h" |
23 | 23 | #include "swift/Driver/Driver.h" |
24 | 24 | #include "swift/Driver/Job.h" |
| 25 | +#include "swift/Frontend/Frontend.h" |
25 | 26 | #include "swift/Option/Options.h" |
26 | 27 | #include "clang/Basic/Version.h" |
27 | 28 | #include "clang/Driver/Util.h" |
@@ -523,6 +524,13 @@ ToolChain::constructInvocation(const CompileJobAction &job, |
523 | 524 | Arguments.push_back("-track-system-dependencies"); |
524 | 525 | } |
525 | 526 |
|
| 527 | + if (context.Args.hasFlag(options::OPT_static_executable, |
| 528 | + options::OPT_no_static_executable, false) || |
| 529 | + context.Args.hasFlag(options::OPT_static_stdlib, |
| 530 | + options::OPT_no_static_stdlib, false)) { |
| 531 | + Arguments.push_back("-use-static-resource-dir"); |
| 532 | + } |
| 533 | + |
526 | 534 | context.Args.AddLastArg( |
527 | 535 | Arguments, |
528 | 536 | options:: |
@@ -1256,25 +1264,19 @@ void ToolChain::getClangLibraryPath(const ArgList &Args, |
1256 | 1264 | void ToolChain::getResourceDirPath(SmallVectorImpl<char> &resourceDirPath, |
1257 | 1265 | const llvm::opt::ArgList &args, |
1258 | 1266 | bool shared) const { |
1259 | | - // FIXME: Duplicated from CompilerInvocation, but in theory the runtime |
1260 | | - // library link path and the standard library module import path don't |
1261 | | - // need to be the same. |
1262 | 1267 | if (const Arg *A = args.getLastArg(options::OPT_resource_dir)) { |
1263 | 1268 | StringRef value = A->getValue(); |
1264 | 1269 | resourceDirPath.append(value.begin(), value.end()); |
1265 | 1270 | } else if (!getTriple().isOSDarwin() && !getTriple().isOSWASI() && args.hasArg(options::OPT_sdk)) { |
1266 | 1271 | // for WASI, sdk option points to wasi-sysroot which doesn't have Swift toolchain |
1267 | 1272 | StringRef value = args.getLastArg(options::OPT_sdk)->getValue(); |
1268 | 1273 | resourceDirPath.append(value.begin(), value.end()); |
1269 | | - llvm::sys::path::append(resourceDirPath, "usr", "lib", |
1270 | | - shared ? "swift" : "swift_static"); |
| 1274 | + llvm::sys::path::append(resourceDirPath, "usr"); |
| 1275 | + CompilerInvocation::appendSwiftLibDir(resourceDirPath, shared); |
1271 | 1276 | } else { |
1272 | 1277 | auto programPath = getDriver().getSwiftProgramPath(); |
1273 | | - resourceDirPath.append(programPath.begin(), programPath.end()); |
1274 | | - llvm::sys::path::remove_filename(resourceDirPath); // remove /swift |
1275 | | - llvm::sys::path::remove_filename(resourceDirPath); // remove /bin |
1276 | | - llvm::sys::path::append(resourceDirPath, "lib", |
1277 | | - shared ? "swift" : "swift_static"); |
| 1278 | + CompilerInvocation::computeRuntimeResourcePathFromExecutablePath( |
| 1279 | + programPath, shared, resourceDirPath); |
1278 | 1280 | } |
1279 | 1281 |
|
1280 | 1282 | StringRef libSubDir = getPlatformNameForTriple(getTriple()); |
|
0 commit comments