Skip to content

[Diagnostics][Darwin] Diagnose libarclite not found on darwin toolchain #26261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/swift/AST/DiagnosticsDriver.def
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ ERROR(error_sdk_too_old,none,
ERROR(error_ios_maximum_deployment_32,none,
"iOS %0 does not support 32-bit programs", (unsigned))

WARNING(warn_arclite_not_found_when_link_objc_runtime,none,
"unable to find Objective-C runtime support library 'arclite'; "
"pass '-no-link-objc-runtime' to silence this warning", ())

ERROR(error_two_files_same_name,none,
"filename \"%0\" used twice: '%1' and '%2'",
(StringRef, StringRef, StringRef))
Expand Down
62 changes: 43 additions & 19 deletions lib/Driver/DarwinToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,27 @@ static bool wantsObjCRuntime(const llvm::Triple &triple) {
llvm_unreachable("unknown Darwin OS");
}

static void findARCLiteLibPath(const toolchains::Darwin &TC,
llvm::SmallVectorImpl<char> &ARCLiteLib) {
auto& D = TC.getDriver();
llvm::sys::path::append(ARCLiteLib, D.getSwiftProgramPath());

llvm::sys::path::remove_filename(ARCLiteLib); // 'swift'
llvm::sys::path::remove_filename(ARCLiteLib); // 'bin'
llvm::sys::path::append(ARCLiteLib, "lib", "arc");

if (!llvm::sys::fs::is_directory(ARCLiteLib)) {
// If we don't have a 'lib/arc/' directory, find the "arclite" library
// relative to the Clang in the active Xcode.
ARCLiteLib.clear();
if (findXcodeClangPath(ARCLiteLib)) {
llvm::sys::path::remove_filename(ARCLiteLib); // 'clang'
llvm::sys::path::remove_filename(ARCLiteLib); // 'bin'
llvm::sys::path::append(ARCLiteLib, "lib", "arc");
}
}
}

ToolChain::InvocationInfo
toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
const JobContext &context) const {
Expand All @@ -235,7 +256,6 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
llvm::report_fatal_error("-static-executable is not supported on Darwin");
}

const Driver &D = getDriver();
const llvm::Triple &Triple = getTriple();

// Configure the toolchain.
Expand Down Expand Up @@ -313,21 +333,8 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
if (context.Args.hasFlag(options::OPT_link_objc_runtime,
options::OPT_no_link_objc_runtime,
/*Default=*/wantsObjCRuntime(Triple))) {
llvm::SmallString<128> ARCLiteLib(D.getSwiftProgramPath());
llvm::sys::path::remove_filename(ARCLiteLib); // 'swift'
llvm::sys::path::remove_filename(ARCLiteLib); // 'bin'
llvm::sys::path::append(ARCLiteLib, "lib", "arc");

if (!llvm::sys::fs::is_directory(ARCLiteLib)) {
// If we don't have a 'lib/arc/' directory, find the "arclite" library
// relative to the Clang in the active Xcode.
ARCLiteLib.clear();
if (findXcodeClangPath(ARCLiteLib)) {
llvm::sys::path::remove_filename(ARCLiteLib); // 'clang'
llvm::sys::path::remove_filename(ARCLiteLib); // 'bin'
llvm::sys::path::append(ARCLiteLib, "lib", "arc");
}
}
llvm::SmallString<128> ARCLiteLib;
findARCLiteLibPath(*this, ARCLiteLib);

if (!ARCLiteLib.empty()) {
llvm::sys::path::append(ARCLiteLib, "libarclite_");
Expand All @@ -340,9 +347,6 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
// Arclite depends on CoreFoundation.
Arguments.push_back("-framework");
Arguments.push_back("CoreFoundation");
} else {
// FIXME: We should probably diagnose this, but this is not a place where
// we can emit diagnostics. Silently ignore it for now.
}
}

Expand Down Expand Up @@ -585,6 +589,23 @@ bool toolchains::Darwin::shouldStoreInvocationInDebugInfo() const {
return false;
}

static void validateLinkObjcRuntimeARCLiteLib(const toolchains::Darwin &TC,
DiagnosticEngine &diags,
const llvm::opt::ArgList &args) {
auto Triple = TC.getTriple();
if (args.hasFlag(options::OPT_link_objc_runtime,
options::OPT_no_link_objc_runtime,
/*Default=*/wantsObjCRuntime(Triple))) {
llvm::SmallString<128> ARCLiteLib;
findARCLiteLibPath(TC, ARCLiteLib);

if (ARCLiteLib.empty()) {
diags.diagnose(SourceLoc(),
diag::warn_arclite_not_found_when_link_objc_runtime);
}
}
}

static void validateDeploymentTarget(const toolchains::Darwin &TC,
DiagnosticEngine &diags,
const llvm::opt::ArgList &args) {
Expand Down Expand Up @@ -621,6 +642,9 @@ static void validateDeploymentTarget(const toolchains::Darwin &TC,
void
toolchains::Darwin::validateArguments(DiagnosticEngine &diags,
const llvm::opt::ArgList &args) const {
// Validating arclite library path when link-objc-runtime.
validateLinkObjcRuntimeARCLiteLib(*this, diags, args);

// Validating apple platforms deployment targets.
validateDeploymentTarget(*this, diags, args);

Expand Down
6 changes: 4 additions & 2 deletions test/Driver/options-interpreter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
// RUN: %swift_driver -### -target x86_64-apple-macosx10.9 -L/foo/ -L/bar/ %s | %FileCheck -check-prefix=CHECK-L2 %s
// CHECK-L2: # DYLD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/macosx$}}

// 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
// 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
// CHECK-L2-ENV: warning: unable to find Objective-C runtime support library 'arclite'; pass '-no-link-objc-runtime' to silence this warning
// CHECK-L2-ENV: # DYLD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/macosx:/sdkroot/usr/lib/swift:/abc/$}}

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

// 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
// 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
// CHECK-COMPLEX: warning: unable to find Objective-C runtime support library 'arclite'; pass '-no-link-objc-runtime' to silence this warning
// CHECK-COMPLEX: -F /foo/
// CHECK-COMPLEX: -F /bar/
// CHECK-COMPLEX: #
Expand Down