Skip to content

Commit c4c240d

Browse files
authored
Merge pull request #26261 from LucianoPAlmeida/fixme-diagnose-darwin-toolchain-arclib
2 parents 749d4b0 + 49efa57 commit c4c240d

File tree

3 files changed

+51
-21
lines changed

3 files changed

+51
-21
lines changed

include/swift/AST/DiagnosticsDriver.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ ERROR(error_sdk_too_old,none,
114114
ERROR(error_ios_maximum_deployment_32,none,
115115
"iOS %0 does not support 32-bit programs", (unsigned))
116116

117+
WARNING(warn_arclite_not_found_when_link_objc_runtime,none,
118+
"unable to find Objective-C runtime support library 'arclite'; "
119+
"pass '-no-link-objc-runtime' to silence this warning", ())
120+
117121
ERROR(error_two_files_same_name,none,
118122
"filename \"%0\" used twice: '%1' and '%2'",
119123
(StringRef, StringRef, StringRef))

lib/Driver/DarwinToolChains.cpp

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,27 @@ static bool wantsObjCRuntime(const llvm::Triple &triple) {
224224
llvm_unreachable("unknown Darwin OS");
225225
}
226226

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+
227248
ToolChain::InvocationInfo
228249
toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
229250
const JobContext &context) const {
@@ -235,7 +256,6 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
235256
llvm::report_fatal_error("-static-executable is not supported on Darwin");
236257
}
237258

238-
const Driver &D = getDriver();
239259
const llvm::Triple &Triple = getTriple();
240260

241261
// Configure the toolchain.
@@ -313,21 +333,8 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
313333
if (context.Args.hasFlag(options::OPT_link_objc_runtime,
314334
options::OPT_no_link_objc_runtime,
315335
/*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-
}
336+
llvm::SmallString<128> ARCLiteLib;
337+
findARCLiteLibPath(*this, ARCLiteLib);
331338

332339
if (!ARCLiteLib.empty()) {
333340
llvm::sys::path::append(ARCLiteLib, "libarclite_");
@@ -340,9 +347,6 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
340347
// Arclite depends on CoreFoundation.
341348
Arguments.push_back("-framework");
342349
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.
346350
}
347351
}
348352

@@ -585,6 +589,23 @@ bool toolchains::Darwin::shouldStoreInvocationInDebugInfo() const {
585589
return false;
586590
}
587591

592+
static void validateLinkObjcRuntimeARCLiteLib(const toolchains::Darwin &TC,
593+
DiagnosticEngine &diags,
594+
const llvm::opt::ArgList &args) {
595+
auto Triple = TC.getTriple();
596+
if (args.hasFlag(options::OPT_link_objc_runtime,
597+
options::OPT_no_link_objc_runtime,
598+
/*Default=*/wantsObjCRuntime(Triple))) {
599+
llvm::SmallString<128> ARCLiteLib;
600+
findARCLiteLibPath(TC, ARCLiteLib);
601+
602+
if (ARCLiteLib.empty()) {
603+
diags.diagnose(SourceLoc(),
604+
diag::warn_arclite_not_found_when_link_objc_runtime);
605+
}
606+
}
607+
}
608+
588609
static void validateDeploymentTarget(const toolchains::Darwin &TC,
589610
DiagnosticEngine &diags,
590611
const llvm::opt::ArgList &args) {
@@ -621,6 +642,9 @@ static void validateDeploymentTarget(const toolchains::Darwin &TC,
621642
void
622643
toolchains::Darwin::validateArguments(DiagnosticEngine &diags,
623644
const llvm::opt::ArgList &args) const {
645+
// Validating arclite library path when link-objc-runtime.
646+
validateLinkObjcRuntimeARCLiteLib(*this, diags, args);
647+
624648
// Validating apple platforms deployment targets.
625649
validateDeploymentTarget(*this, diags, args);
626650

test/Driver/options-interpreter.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
// RUN: %swift_driver -### -target x86_64-apple-macosx10.9 -L/foo/ -L/bar/ %s | %FileCheck -check-prefix=CHECK-L2 %s
2828
// CHECK-L2: # DYLD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/macosx$}}
2929

30-
// RUN: env DYLD_LIBRARY_PATH=/abc/ SDKROOT=/sdkroot %swift_driver_plain -### -target x86_64-apple-macosx10.9 -L/foo/ -L/bar/ %s | %FileCheck -check-prefix=CHECK-L2-ENV %s
30+
// RUN: env DYLD_LIBRARY_PATH=/abc/ SDKROOT=/sdkroot %swift_driver_plain -### -target x86_64-apple-macosx10.9 -L/foo/ -L/bar/ %s 2>&1 | %FileCheck -check-prefix=CHECK-L2-ENV %s
31+
// CHECK-L2-ENV: warning: unable to find Objective-C runtime support library 'arclite'; pass '-no-link-objc-runtime' to silence this warning
3132
// CHECK-L2-ENV: # DYLD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/macosx:/sdkroot/usr/lib/swift:/abc/$}}
3233

3334
// RUN: %swift_driver -### -target x86_64-apple-macosx10.9 %s | %FileCheck -check-prefix=CHECK-NO-FRAMEWORKS %s
@@ -51,7 +52,8 @@
5152
// CHECK-F2-ENV: #
5253
// CHECK-F2-ENV: DYLD_FRAMEWORK_PATH=/foo/:/bar/:/abc/{{$}}
5354

54-
// RUN: env DYLD_FRAMEWORK_PATH=/abc/ SDKROOT=/sdkroot %swift_driver_plain -### -target x86_64-apple-macosx10.9 -F/foo/ -F/bar/ -L/foo2/ -L/bar2/ %s | %FileCheck -check-prefix=CHECK-COMPLEX %s
55+
// RUN: env DYLD_FRAMEWORK_PATH=/abc/ SDKROOT=/sdkroot %swift_driver_plain -### -target x86_64-apple-macosx10.9 -F/foo/ -F/bar/ -L/foo2/ -L/bar2/ %s 2>&1 | %FileCheck -check-prefix=CHECK-COMPLEX %s
56+
// CHECK-COMPLEX: warning: unable to find Objective-C runtime support library 'arclite'; pass '-no-link-objc-runtime' to silence this warning
5557
// CHECK-COMPLEX: -F /foo/
5658
// CHECK-COMPLEX: -F /bar/
5759
// CHECK-COMPLEX: #

0 commit comments

Comments
 (0)