Skip to content

Commit f4df554

Browse files
committed
Remove support for linking arclite
Darwin no longer uses arclite and it's no longer distributed in the macOS SDKs. This leaves the options '-link-objc-runtime' and '-no-link-objc-runtime' in place, but strips out all the logic that actually used them. Part of: rdar://105406972
1 parent 738a6a3 commit f4df554

File tree

6 files changed

+17
-132
lines changed

6 files changed

+17
-132
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2831,6 +2831,10 @@ extension Driver {
28312831
diagnosticsEngine.emit(.error_hermetic_seal_requires_lto)
28322832
}
28332833
}
2834+
if parsedOptions.hasArgument(.linkObjcRuntime) ||
2835+
parsedOptions.hasArgument(.noLinkObjcRuntime) {
2836+
diagnosticsEngine.emit(.warning_darwin_link_objc_deprecated())
2837+
}
28342838
}
28352839

28362840
private static func validateSanitizerAddressUseOdrIndicatorFlag(

Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,6 @@ import struct TSCBasic.AbsolutePath
1616
import struct TSCBasic.RelativePath
1717

1818
extension DarwinToolchain {
19-
internal func findXcodeClangPath() throws -> AbsolutePath? {
20-
let result = try executor.checkNonZeroExit(
21-
args: "xcrun", "-toolchain", "default", "-f", "clang",
22-
environment: env
23-
).trimmingCharacters(in: .whitespacesAndNewlines)
24-
25-
return result.isEmpty ? nil : try AbsolutePath(validating: result)
26-
}
27-
28-
internal func findXcodeClangLibPath(_ additionalPath: String) throws -> AbsolutePath? {
29-
let path = try getToolPath(.swiftCompiler)
30-
.parentDirectory // 'swift'
31-
.parentDirectory // 'bin'
32-
.appending(components: "lib", additionalPath)
33-
34-
if fileSystem.exists(path) { return path }
35-
36-
// If we don't have a 'lib/arc/' directory, find the "arclite" library
37-
// relative to the Clang in the active Xcode.
38-
if let clangPath = try? findXcodeClangPath() {
39-
return clangPath
40-
.parentDirectory // 'clang'
41-
.parentDirectory // 'bin'
42-
.appending(components: "lib", additionalPath)
43-
}
44-
return nil
45-
}
46-
47-
internal func findARCLiteLibPath() throws -> AbsolutePath? {
48-
return try findXcodeClangLibPath("arc")
49-
}
50-
5119
/// Adds the arguments necessary to link the files from the given set of
5220
/// options for a Darwin platform.
5321
public func addPlatformSpecificLinkerArgs(
@@ -219,13 +187,6 @@ extension DarwinToolchain {
219187
commandLine.appendPath(VirtualPath.lookup(sdkPath))
220188
}
221189

222-
// -link-objc-runtime also implies -fobjc-link-runtime
223-
if parsedOptions.hasFlag(positive: .linkObjcRuntime,
224-
negative: .noLinkObjcRuntime,
225-
default: false) {
226-
commandLine.appendFlag("-fobjc-link-runtime")
227-
}
228-
229190
let targetTriple = targetInfo.target.triple
230191
commandLine.appendFlag("--target=\(targetTriple.triple)")
231192
if let variantTriple = targetInfo.targetVariant?.triple {

Sources/SwiftDriver/Toolchains/DarwinToolchain.swift

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,6 @@ public final class DarwinToolchain: Toolchain {
188188
targetVariantTriple: Triple?,
189189
compilerOutputType: FileType?,
190190
diagnosticsEngine: DiagnosticsEngine) throws {
191-
// On non-darwin hosts, libArcLite won't be found and a warning will be emitted
192-
// Guard for the sake of tests running on all platforms
193-
#if canImport(Darwin)
194-
// Validating arclite library path when link-objc-runtime.
195-
validateLinkObjcRuntimeARCLiteLib(&parsedOptions,
196-
targetTriple: targetTriple,
197-
diagnosticsEngine: diagnosticsEngine)
198-
#endif
199191
// Validating apple platforms deployment targets.
200192
try validateDeploymentTarget(&parsedOptions, targetTriple: targetTriple,
201193
compilerOutputType: compilerOutputType)
@@ -247,22 +239,6 @@ public final class DarwinToolchain: Toolchain {
247239
}
248240
}
249241
}
250-
251-
func validateLinkObjcRuntimeARCLiteLib(_ parsedOptions: inout ParsedOptions,
252-
targetTriple: Triple,
253-
diagnosticsEngine: DiagnosticsEngine) {
254-
guard parsedOptions.hasFlag(positive: .linkObjcRuntime,
255-
negative: .noLinkObjcRuntime,
256-
default: !targetTriple.supports(.nativeARC))
257-
else {
258-
return
259-
}
260-
261-
guard let _ = try? findARCLiteLibPath() else {
262-
diagnosticsEngine.emit(.warn_arclite_not_found_when_link_objc_runtime)
263-
return
264-
}
265-
}
266242

267243
struct DarwinSDKInfo: Decodable {
268244
private enum CodingKeys: String, CodingKey {
@@ -404,15 +380,6 @@ public final class DarwinToolchain: Toolchain {
404380
}
405381
}
406382

407-
extension Diagnostic.Message {
408-
static var warn_arclite_not_found_when_link_objc_runtime: Diagnostic.Message {
409-
.warning(
410-
"unable to find Objective-C runtime support library 'arclite'; " +
411-
"pass '-no-link-objc-runtime' to silence this warning"
412-
)
413-
}
414-
}
415-
416383
private extension Version {
417384
var sdkVersionString: String {
418385
if patch == 0 && prerelease.isEmpty && metadata.isEmpty {

Sources/SwiftDriver/Utilities/Diagnostics.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ extension Diagnostic.Message {
5151
.warning("inferring simulator environment for target '\(originalTriple.triple)'; use '-target \(inferredTriple.triple)' instead")
5252
}
5353

54+
static func warning_darwin_link_objc_deprecated() -> Diagnostic.Message {
55+
.warning("-link-objc-runtime is no longer supported on Apple platforms")
56+
}
57+
5458
static func error_argument_not_allowed_with(arg: String, other: String) -> Diagnostic.Message {
5559
.error("argument '\(arg)' is not allowed with '\(other)'")
5660
}

Sources/SwiftDriver/Utilities/Triple+Platforms.swift

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -398,25 +398,3 @@ extension Triple {
398398
}
399399
}
400400
}
401-
402-
extension Triple.FeatureAvailability {
403-
/// Linking `libarclite` is unnecessary for triples supporting this feature.
404-
///
405-
/// This impacts the `-link-objc-runtime` flag in Swift, which is akin to the
406-
/// `-fobjc-link-runtime` build setting in clang. When set, these flags
407-
/// automatically link libobjc, and any compatibility libraries that don't
408-
/// ship with the OS. The versions here are the first OSes that support
409-
/// ARC natively in their respective copies of the Objective-C runtime,
410-
/// and therefore do not require additional support libraries.
411-
static let nativeARC = Self(
412-
macOS: .available(since: Triple.Version(10, 11, 0)),
413-
iOS: .available(since: Triple.Version(9, 0, 0)),
414-
tvOS: .available(since: Triple.Version(9, 0, 0)),
415-
watchOS: .availableInAllVersions
416-
)
417-
// When updating the versions listed here, please record the most recent
418-
// feature being depended on and when it was introduced:
419-
//
420-
// - Make assigning 'nil' to an NSMutableDictionary subscript delete the
421-
// entry, like it does for Swift.Dictionary, rather than trap.
422-
}

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,15 @@ final class SwiftDriverTests: XCTestCase {
601601
}
602602
}
603603

604+
func testLinkObjCFlagWarning() throws {
605+
try assertDriverDiagnostics(args: "swiftc", "foo.swift", "-link-objc-runtime") {
606+
$1.expect(.warning("-link-objc-runtime is no longer supported on Apple platforms"))
607+
}
608+
try assertDriverDiagnostics(args: "swiftc", "foo.swift", "-no-link-objc-runtime") {
609+
$1.expect(.warning("-link-objc-runtime is no longer supported on Apple platforms"))
610+
}
611+
}
612+
604613
func testHermeticSealAtLink() throws {
605614
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-experimental-hermetic-seal-at-link", "-lto=llvm-full") { driver in
606615
let jobs = try driver.planBuild()
@@ -1761,39 +1770,6 @@ final class SwiftDriverTests: XCTestCase {
17611770
XCTAssertFalse(cmd.contains(.flag("-shared")))
17621771
}
17631772

1764-
do {
1765-
// -fobjc-link-runtime default
1766-
var driver = try Driver(args: commonArgs + ["-emit-library", "-target", "x86_64-apple-macosx10.15"], env: env)
1767-
let plannedJobs = try driver.planBuild()
1768-
XCTAssertEqual(3, plannedJobs.count)
1769-
let linkJob = plannedJobs[2]
1770-
XCTAssertEqual(linkJob.kind, .link)
1771-
let cmd = linkJob.commandLine
1772-
XCTAssertFalse(cmd.contains(.flag("-fobjc-link-runtime")))
1773-
}
1774-
1775-
do {
1776-
// -fobjc-link-runtime enable
1777-
var driver = try Driver(args: commonArgs + ["-emit-library", "-target", "x86_64-apple-macosx10.15", "-link-objc-runtime"], env: env)
1778-
let plannedJobs = try driver.planBuild()
1779-
XCTAssertEqual(3, plannedJobs.count)
1780-
let linkJob = plannedJobs[2]
1781-
XCTAssertEqual(linkJob.kind, .link)
1782-
let cmd = linkJob.commandLine
1783-
XCTAssertTrue(cmd.contains(.flag("-fobjc-link-runtime")))
1784-
}
1785-
1786-
do {
1787-
// -fobjc-link-runtime disable override
1788-
var driver = try Driver(args: commonArgs + ["-emit-library", "-target", "x86_64-apple-macosx10.15", "-link-objc-runtime", "-no-link-objc-runtime"], env: env)
1789-
let plannedJobs = try driver.planBuild()
1790-
XCTAssertEqual(3, plannedJobs.count)
1791-
let linkJob = plannedJobs[2]
1792-
XCTAssertEqual(linkJob.kind, .link)
1793-
let cmd = linkJob.commandLine
1794-
XCTAssertFalse(cmd.contains(.flag("-fobjc-link-runtime")))
1795-
}
1796-
17971773
do {
17981774
// Xlinker flags
17991775
// Ensure that Xlinker flags are passed as such to the clang linker invocation.
@@ -3824,11 +3800,6 @@ final class SwiftDriverTests: XCTestCase {
38243800

38253801
// Ensure arm64_32 is not restricted to back-deployment like other 32-bit archs (armv7k/i386).
38263802
XCTAssertNoThrow(try Driver(args: ["swiftc", "-emit-module", "-c", "-target", "arm64_32-apple-watchos12.0", "foo.swift"]))
3827-
3828-
// On non-darwin hosts, libArcLite won't be found and a warning will be emitted
3829-
#if os(macOS)
3830-
try assertNoDriverDiagnostics(args: "swiftc", "-c", "-target", "x86_64-apple-macosx10.14", "-link-objc-runtime", "foo.swift")
3831-
#endif
38323803
}
38333804

38343805
func testProfileArgValidation() throws {

0 commit comments

Comments
 (0)