Skip to content

Adjust to simulator compiler-rt change #188

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

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 2 additions & 5 deletions Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,12 @@ extension DarwinToolchain {
// FIXME: If we used Clang as a linker instead of going straight to ld,
// we wouldn't have to replicate a bunch of Clang's logic here.

// Always link the regular compiler_rt if it's present. Note that the
// regular libclang_rt.a uses a fat binary for device and simulator; this is
// not true for all compiler_rt build products.
// Always link the regular compiler_rt if it's present.
//
// Note: Normally we'd just add this unconditionally, but it's valid to build
// Swift and use it as a linker without building compiler_rt.
let targetTriple = targetInfo.target.triple
let darwinPlatformSuffix =
targetTriple.darwinPlatform!.with(.device)!.libraryNameSuffix
let darwinPlatformSuffix = targetTriple.darwinPlatform!.libraryNameSuffix
let compilerRTPath =
try clangLibraryPath(
for: targetTriple,
Expand Down
9 changes: 9 additions & 0 deletions Sources/SwiftDriver/Jobs/Job.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public struct Job: Codable, Equatable, Hashable {

/// Represents a virtual path on disk.
case path(VirtualPath)

public func hasSuffix(_ suffix: String) -> Bool {
switch self {
case .flag(let string):
return string.hasSuffix(suffix)
case .path(let virtualPath):
return virtualPath.basename == suffix
}
}
}

/// The Swift module this job involves.
Expand Down
29 changes: 29 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertTrue(cmd.contains(.flag("x86_64")))
XCTAssertTrue(cmd.contains(.flag("-macosx_version_min")))
XCTAssertTrue(cmd.contains(.flag("10.15.0")))
XCTAssertTrue(cmd.contains(where: { $0.hasSuffix("libclang_rt.osx.a") }))
XCTAssertEqual(linkJob.outputs[0].file, try VirtualPath(path: "libTest.dylib"))

XCTAssertFalse(cmd.contains(.flag("-static")))
Expand All @@ -734,6 +735,32 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertTrue(cmd.contains(.flag("arm64")))
XCTAssertTrue(cmd.contains(.flag("-iphoneos_version_min")))
XCTAssertTrue(cmd.contains(.flag("10.0.0")))
XCTAssertTrue(cmd.contains(where: { $0.hasSuffix("libclang_rt.ios.a") }))
XCTAssertEqual(linkJob.outputs[0].file, try VirtualPath(path: "libTest.dylib"))

XCTAssertFalse(cmd.contains(.flag("-static")))
XCTAssertFalse(cmd.contains(.flag("-shared")))
}

do {
// iOS simulator target
var driver = try Driver(args: commonArgs + ["-emit-library", "-target", "arm64-apple-ios14.0-simulator"], env: env)
let plannedJobs = try driver.planBuild()

XCTAssertEqual(3, plannedJobs.count)
XCTAssertFalse(plannedJobs.contains { $0.kind == .autolinkExtract })

let linkJob = plannedJobs[2]
XCTAssertEqual(linkJob.kind, .link)

let cmd = linkJob.commandLine
XCTAssertTrue(cmd.contains(.flag("-dylib")))
XCTAssertTrue(cmd.contains(.flag("-arch")))
XCTAssertTrue(cmd.contains(.flag("arm64")))
XCTAssertTrue(cmd.contains(.flag("-ios_simulator_version_min")))
XCTAssertTrue(cmd.contains(.flag("14.0.0")))
XCTAssertTrue(cmd.contains(where: { $0.hasSuffix("libclang_rt.iossim.a") }))
XCTAssertFalse(cmd.contains(where: { $0.hasSuffix("libclang_rt.ios.a") }))
XCTAssertEqual(linkJob.outputs[0].file, try VirtualPath(path: "libTest.dylib"))

XCTAssertFalse(cmd.contains(.flag("-static")))
Expand All @@ -757,6 +784,7 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertTrue(cmd.contains(.flag("x86_64")))
XCTAssertTrue(cmd.contains(.flag("-maccatalyst_version_min")))
XCTAssertTrue(cmd.contains(.flag("13.0.0")))
XCTAssertTrue(cmd.contains(where: { $0.hasSuffix("libclang_rt.osx.a") }))
XCTAssertEqual(linkJob.outputs[0].file, try VirtualPath(path: "libTest.dylib"))

XCTAssertFalse(cmd.contains(.flag("-static")))
Expand Down Expand Up @@ -859,6 +887,7 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertTrue(cmd.contains(.flag("-shared")))
XCTAssertTrue(cmd.contains(.path(.temporary(RelativePath("foo.o")))))
XCTAssertTrue(cmd.contains(.path(.temporary(RelativePath("bar.o")))))
XCTAssertFalse(cmd.contains(where: { $0.hasSuffix("libclang_rt.osx.a") }))
XCTAssertEqual(linkJob.outputs[0].file, try VirtualPath(path: "libTest.so"))

XCTAssertFalse(cmd.contains(.flag("-dylib")))
Expand Down