Skip to content

Commit 929a926

Browse files
authored
Merge pull request #1295 from artemcm/NoMoreArcLite
Remove support for linking arclite
2 parents 99fb440 + f4df554 commit 929a926

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
@@ -2804,6 +2804,10 @@ extension Driver {
28042804
diagnosticsEngine.emit(.error_hermetic_seal_requires_lto)
28052805
}
28062806
}
2807+
if parsedOptions.hasArgument(.linkObjcRuntime) ||
2808+
parsedOptions.hasArgument(.noLinkObjcRuntime) {
2809+
diagnosticsEngine.emit(.warning_darwin_link_objc_deprecated())
2810+
}
28072811
}
28082812

28092813
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()
@@ -1773,39 +1782,6 @@ final class SwiftDriverTests: XCTestCase {
17731782
XCTAssertFalse(cmd.contains(.flag("-shared")))
17741783
}
17751784

1776-
do {
1777-
// -fobjc-link-runtime default
1778-
var driver = try Driver(args: commonArgs + ["-emit-library", "-target", "x86_64-apple-macosx10.15"], env: env)
1779-
let plannedJobs = try driver.planBuild()
1780-
XCTAssertEqual(3, plannedJobs.count)
1781-
let linkJob = plannedJobs[2]
1782-
XCTAssertEqual(linkJob.kind, .link)
1783-
let cmd = linkJob.commandLine
1784-
XCTAssertFalse(cmd.contains(.flag("-fobjc-link-runtime")))
1785-
}
1786-
1787-
do {
1788-
// -fobjc-link-runtime enable
1789-
var driver = try Driver(args: commonArgs + ["-emit-library", "-target", "x86_64-apple-macosx10.15", "-link-objc-runtime"], env: env)
1790-
let plannedJobs = try driver.planBuild()
1791-
XCTAssertEqual(3, plannedJobs.count)
1792-
let linkJob = plannedJobs[2]
1793-
XCTAssertEqual(linkJob.kind, .link)
1794-
let cmd = linkJob.commandLine
1795-
XCTAssertTrue(cmd.contains(.flag("-fobjc-link-runtime")))
1796-
}
1797-
1798-
do {
1799-
// -fobjc-link-runtime disable override
1800-
var driver = try Driver(args: commonArgs + ["-emit-library", "-target", "x86_64-apple-macosx10.15", "-link-objc-runtime", "-no-link-objc-runtime"], env: env)
1801-
let plannedJobs = try driver.planBuild()
1802-
XCTAssertEqual(3, plannedJobs.count)
1803-
let linkJob = plannedJobs[2]
1804-
XCTAssertEqual(linkJob.kind, .link)
1805-
let cmd = linkJob.commandLine
1806-
XCTAssertFalse(cmd.contains(.flag("-fobjc-link-runtime")))
1807-
}
1808-
18091785
do {
18101786
// Xlinker flags
18111787
// Ensure that Xlinker flags are passed as such to the clang linker invocation.
@@ -3836,11 +3812,6 @@ final class SwiftDriverTests: XCTestCase {
38363812

38373813
// Ensure arm64_32 is not restricted to back-deployment like other 32-bit archs (armv7k/i386).
38383814
XCTAssertNoThrow(try Driver(args: ["swiftc", "-emit-module", "-c", "-target", "arm64_32-apple-watchos12.0", "foo.swift"]))
3839-
3840-
// On non-darwin hosts, libArcLite won't be found and a warning will be emitted
3841-
#if os(macOS)
3842-
try assertNoDriverDiagnostics(args: "swiftc", "-c", "-target", "x86_64-apple-macosx10.14", "-link-objc-runtime", "foo.swift")
3843-
#endif
38443815
}
38453816

38463817
func testProfileArgValidation() throws {

0 commit comments

Comments
 (0)