@@ -832,6 +832,28 @@ static void getRuntimeLibraryPath(SmallVectorImpl<char> &runtimeLibPath,
832
832
getPlatformNameForTriple (TC.getTriple ()));
833
833
}
834
834
835
+ // / Get the runtime library link path for static linking,
836
+ // / which is platform-specific and found relative to the compiler.
837
+ static void getRuntimeStaticLibraryPath (SmallVectorImpl<char > &runtimeLibPath,
838
+ const llvm::opt::ArgList &args,
839
+ const ToolChain &TC) {
840
+ // FIXME: Duplicated from CompilerInvocation, but in theory the runtime
841
+ // library link path and the standard library module import path don't
842
+ // need to be the same.
843
+ if (const Arg *A = args.getLastArg (options::OPT_resource_dir)) {
844
+ StringRef value = A->getValue ();
845
+ runtimeLibPath.append (value.begin (), value.end ());
846
+ } else {
847
+ auto programPath = TC.getDriver ().getSwiftProgramPath ();
848
+ runtimeLibPath.append (programPath.begin (), programPath.end ());
849
+ llvm::sys::path::remove_filename (runtimeLibPath); // remove /swift
850
+ llvm::sys::path::remove_filename (runtimeLibPath); // remove /bin
851
+ llvm::sys::path::append (runtimeLibPath, " lib" , " swift_static" );
852
+ }
853
+ llvm::sys::path::append (runtimeLibPath,
854
+ getPlatformNameForTriple (TC.getTriple ()));
855
+ }
856
+
835
857
ToolChain::InvocationInfo
836
858
toolchains::Darwin::constructInvocation (const InterpretJobAction &job,
837
859
const JobContext &context) const {
@@ -1054,8 +1076,22 @@ toolchains::Darwin::constructInvocation(const LinkJobAction &job,
1054
1076
// relative to the compiler.
1055
1077
SmallString<128 > RuntimeLibPath;
1056
1078
getRuntimeLibraryPath (RuntimeLibPath, context.Args , *this );
1079
+
1080
+ // Link the standard library.
1057
1081
Arguments.push_back (" -L" );
1058
- Arguments.push_back (context.Args .MakeArgString (RuntimeLibPath));
1082
+ if (context.Args .hasFlag (options::OPT_static_stdlib,
1083
+ options::OPT_no_static_stdlib,
1084
+ false )) {
1085
+ SmallString<128 > StaticRuntimeLibPath;
1086
+ getRuntimeStaticLibraryPath (StaticRuntimeLibPath, context.Args , *this );
1087
+ Arguments.push_back (context.Args .MakeArgString (StaticRuntimeLibPath));
1088
+ Arguments.push_back (" -lc++" );
1089
+ Arguments.push_back (" -framework" );
1090
+ Arguments.push_back (" Foundation" );
1091
+ Arguments.push_back (" -force_load_swift_libs" );
1092
+ } else {
1093
+ Arguments.push_back (context.Args .MakeArgString (RuntimeLibPath));
1094
+ }
1059
1095
1060
1096
if (context.Args .hasArg (options::OPT_profile_generate)) {
1061
1097
SmallString<128 > LibProfile (RuntimeLibPath);
0 commit comments