Skip to content

Commit 0d8da23

Browse files
Diagnose libarclite not found on darwing toolchain
1 parent c6284f4 commit 0d8da23

File tree

3 files changed

+60
-40
lines changed

3 files changed

+60
-40
lines changed

include/swift/AST/DiagnosticsDriver.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ 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+
ERROR(error_arclite_not_found_when_link_objc_runtime,none,
118+
"unable to find the 'arclite' library", ())
119+
117120
ERROR(error_two_files_same_name,none,
118121
"filename \"%0\" used twice: '%1' and '%2'",
119122
(StringRef, StringRef, StringRef))

lib/Driver/DarwinToolChains.cpp

Lines changed: 53 additions & 31 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,37 +333,19 @@ 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-
}
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);
336338

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");
347349
}
348350

349351
for (const Arg *arg :
@@ -585,6 +587,23 @@ bool toolchains::Darwin::shouldStoreInvocationInDebugInfo() const {
585587
return false;
586588
}
587589

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+
588607
static void validateDeploymentTarget(const toolchains::Darwin &TC,
589608
DiagnosticEngine &diags,
590609
const llvm::opt::ArgList &args) {
@@ -621,6 +640,9 @@ static void validateDeploymentTarget(const toolchains::Darwin &TC,
621640
void
622641
toolchains::Darwin::validateArguments(DiagnosticEngine &diags,
623642
const llvm::opt::ArgList &args) const {
643+
// Validating arclite library path when link-objc-runtime.
644+
validateLinkObjcRuntimeARCLiteLib(*this, diags, args);
645+
624646
// Validating apple platforms deployment targets.
625647
validateDeploymentTarget(*this, diags, args);
626648

test/Driver/options-interpreter.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +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
31-
// CHECK-L2-ENV: # DYLD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/macosx:/sdkroot/usr/lib/swift:/abc/$}}
32-
30+
// RUN: not 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: error: unable to find the 'arclite' library
3332
// RUN: %swift_driver -### -target x86_64-apple-macosx10.9 %s | %FileCheck -check-prefix=CHECK-NO-FRAMEWORKS %s
3433
// RUN: env DYLD_FRAMEWORK_PATH=/abc/ %swift_driver_plain -### -target x86_64-apple-macosx10.9 %s | %FileCheck -check-prefix=CHECK-NO-FRAMEWORKS %s
3534
// CHECK-NO-FRAMEWORKS-NOT: DYLD_FRAMEWORK_PATH
@@ -51,12 +50,8 @@
5150
// CHECK-F2-ENV: #
5251
// CHECK-F2-ENV: DYLD_FRAMEWORK_PATH=/foo/:/bar/:/abc/{{$}}
5352

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-
// CHECK-COMPLEX: -F /foo/
56-
// CHECK-COMPLEX: -F /bar/
57-
// CHECK-COMPLEX: #
58-
// CHECK-COMPLEX-DAG: DYLD_FRAMEWORK_PATH=/foo/:/bar/:/abc/{{$| }}
59-
// CHECK-COMPLEX-DAG: DYLD_LIBRARY_PATH={{/foo2/:/bar2/:[^:]+/lib/swift/macosx:/sdkroot/usr/lib/swift($| )}}
53+
// RUN: not 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
54+
// CHECK-COMPLEX: error: unable to find the 'arclite' library
6055

6156
// RUN: %swift_driver -### -target x86_64-unknown-linux-gnu -L/foo/ %s | %FileCheck -check-prefix=CHECK-L-LINUX${LD_LIBRARY_PATH+_LAX} %s
6257
// CHECK-L-LINUX: # LD_LIBRARY_PATH={{/foo/:[^:]+/lib/swift/linux$}}

0 commit comments

Comments
 (0)