@@ -224,6 +224,27 @@ static bool wantsObjCRuntime(const llvm::Triple &triple) {
224
224
llvm_unreachable (" unknown Darwin OS" );
225
225
}
226
226
227
+ static void findARCLiteLibPath (const toolchains::Darwin &TC,
228
+ llvm::SmallVectorImpl<char > &ARCLiteLib) {
229
+ auto & D = TC.getDriver ();
230
+ llvm::sys::path::append (ARCLiteLib, D.getSwiftProgramPath ());
231
+
232
+ llvm::sys::path::remove_filename (ARCLiteLib); // 'swift'
233
+ llvm::sys::path::remove_filename (ARCLiteLib); // 'bin'
234
+ llvm::sys::path::append (ARCLiteLib, " lib" , " arc" );
235
+
236
+ if (!llvm::sys::fs::is_directory (ARCLiteLib)) {
237
+ // If we don't have a 'lib/arc/' directory, find the "arclite" library
238
+ // relative to the Clang in the active Xcode.
239
+ ARCLiteLib.clear ();
240
+ if (findXcodeClangPath (ARCLiteLib)) {
241
+ llvm::sys::path::remove_filename (ARCLiteLib); // 'clang'
242
+ llvm::sys::path::remove_filename (ARCLiteLib); // 'bin'
243
+ llvm::sys::path::append (ARCLiteLib, " lib" , " arc" );
244
+ }
245
+ }
246
+ }
247
+
227
248
ToolChain::InvocationInfo
228
249
toolchains::Darwin::constructInvocation (const DynamicLinkJobAction &job,
229
250
const JobContext &context) const {
@@ -235,7 +256,6 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
235
256
llvm::report_fatal_error (" -static-executable is not supported on Darwin" );
236
257
}
237
258
238
- const Driver &D = getDriver ();
239
259
const llvm::Triple &Triple = getTriple ();
240
260
241
261
// Configure the toolchain.
@@ -313,37 +333,19 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
313
333
if (context.Args .hasFlag (options::OPT_link_objc_runtime,
314
334
options::OPT_no_link_objc_runtime,
315
335
/* Default=*/ wantsObjCRuntime (Triple))) {
316
- llvm::SmallString<128 > ARCLiteLib (D.getSwiftProgramPath ());
317
- llvm::sys::path::remove_filename (ARCLiteLib); // 'swift'
318
- llvm::sys::path::remove_filename (ARCLiteLib); // 'bin'
319
- llvm::sys::path::append (ARCLiteLib, " lib" , " arc" );
320
-
321
- if (!llvm::sys::fs::is_directory (ARCLiteLib)) {
322
- // If we don't have a 'lib/arc/' directory, find the "arclite" library
323
- // relative to the Clang in the active Xcode.
324
- ARCLiteLib.clear ();
325
- if (findXcodeClangPath (ARCLiteLib)) {
326
- llvm::sys::path::remove_filename (ARCLiteLib); // 'clang'
327
- llvm::sys::path::remove_filename (ARCLiteLib); // 'bin'
328
- llvm::sys::path::append (ARCLiteLib, " lib" , " arc" );
329
- }
330
- }
331
-
332
- if (!ARCLiteLib.empty ()) {
333
- llvm::sys::path::append (ARCLiteLib, " libarclite_" );
334
- ARCLiteLib += getPlatformNameForTriple (Triple);
335
- ARCLiteLib += " .a" ;
336
+ llvm::SmallString<128 > ARCLiteLib;
337
+ findARCLiteLibPath (*this , ARCLiteLib);
336
338
337
- Arguments. push_back ( " -force_load " );
338
- Arguments. push_back (context. Args . MakeArgString (ARCLiteLib) );
339
-
340
- // Arclite depends on CoreFoundation.
341
- Arguments.push_back (" -framework " );
342
- Arguments.push_back (" CoreFoundation " );
343
- } else {
344
- // FIXME: We should probably diagnose this, but this is not a place where
345
- // we can emit diagnostics. Silently ignore it for now.
346
- }
339
+ llvm::sys::path::append (ARCLiteLib, " libarclite_ " );
340
+ ARCLiteLib += getPlatformNameForTriple (Triple );
341
+ ARCLiteLib += " .a " ;
342
+
343
+ Arguments.push_back (" -force_load " );
344
+ Arguments.push_back (context. Args . MakeArgString (ARCLiteLib) );
345
+
346
+ // Arclite depends on CoreFoundation.
347
+ Arguments. push_back ( " -framework " );
348
+ Arguments. push_back ( " CoreFoundation " );
347
349
}
348
350
349
351
for (const Arg *arg :
@@ -585,6 +587,23 @@ bool toolchains::Darwin::shouldStoreInvocationInDebugInfo() const {
585
587
return false ;
586
588
}
587
589
590
+ static void validateLinkObjcRuntimeARCLiteLib (const toolchains::Darwin &TC,
591
+ DiagnosticEngine &diags,
592
+ const llvm::opt::ArgList &args) {
593
+ auto Triple = TC.getTriple ();
594
+ if (args.hasFlag (options::OPT_link_objc_runtime,
595
+ options::OPT_no_link_objc_runtime,
596
+ /* Default=*/ wantsObjCRuntime (Triple))) {
597
+ llvm::SmallString<128 > ARCLiteLib;
598
+ findARCLiteLibPath (TC, ARCLiteLib);
599
+
600
+ if (ARCLiteLib.empty ()) {
601
+ diags.diagnose (SourceLoc (),
602
+ diag::error_arclite_not_found_when_link_objc_runtime);
603
+ }
604
+ }
605
+ }
606
+
588
607
static void validateDeploymentTarget (const toolchains::Darwin &TC,
589
608
DiagnosticEngine &diags,
590
609
const llvm::opt::ArgList &args) {
@@ -621,6 +640,9 @@ static void validateDeploymentTarget(const toolchains::Darwin &TC,
621
640
void
622
641
toolchains::Darwin::validateArguments (DiagnosticEngine &diags,
623
642
const llvm::opt::ArgList &args) const {
643
+ // Validating arclite library path when link-objc-runtime.
644
+ validateLinkObjcRuntimeARCLiteLib (*this , diags, args);
645
+
624
646
// Validating apple platforms deployment targets.
625
647
validateDeploymentTarget (*this , diags, args);
626
648
0 commit comments