Skip to content

[6.0] Add swift-corelibs-foundation Linux/Android workaround #7641

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 5 commits 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
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,18 @@ public final class ClangTargetBuildDescription {
args += ["-I", includeSearchPath.pathString]
}

// FIXME: Remove this once it becomes possible to express this dependency in a package manifest.
//
// On Linux/Android swift-corelibs-foundation depends on dispatch library which is
// currently shipped with the Swift toolchain.
if (triple.isLinux() || triple.isAndroid()) && self.package.id == .plain("swift-corelibs-foundation") {
let swiftCompilerPath = self.buildParameters.toolchain.swiftCompilerPath
let toolchainResourcesPath = swiftCompilerPath.parentDirectory
.parentDirectory
.appending(components: ["lib", "swift"])
args += ["-I", toolchainResourcesPath.pathString]
}

// suppress warnings if the package is remote
if self.package.isRemote {
args += ["-w"]
Expand Down
26 changes: 14 additions & 12 deletions Sources/SPMTestSupport/MockBuildTestHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ import SPMBuildCore
import TSCUtility
import XCTest

public struct MockToolchain: PackageModel.Toolchain {
package struct MockToolchain: PackageModel.Toolchain {
#if os(Windows)
public let librarianPath = AbsolutePath("/fake/path/to/link.exe")
#elseif os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
public let librarianPath = AbsolutePath("/fake/path/to/libtool")
#else
public let librarianPath = AbsolutePath("/fake/path/to/llvm-ar")
#endif
public let swiftCompilerPath = AbsolutePath("/fake/path/to/swiftc")
public let includeSearchPaths = [AbsolutePath]()
public let librarySearchPaths = [AbsolutePath]()
public let swiftResourcesPath: AbsolutePath? = nil
public let swiftStaticResourcesPath: AbsolutePath? = nil
public let sdkRootPath: AbsolutePath? = nil
public let extraFlags = PackageModel.BuildFlags()
public let installedSwiftPMConfiguration = InstalledSwiftPMConfiguration.default
public let providedLibraries = [LibraryMetadata]()
package let swiftCompilerPath = AbsolutePath("/fake/path/to/swiftc")
package let includeSearchPaths = [AbsolutePath]()
package let librarySearchPaths = [AbsolutePath]()
package let swiftResourcesPath: AbsolutePath?
package let swiftStaticResourcesPath: AbsolutePath? = nil
package let sdkRootPath: AbsolutePath? = nil
package let extraFlags = PackageModel.BuildFlags()
package let installedSwiftPMConfiguration = InstalledSwiftPMConfiguration.default
package let providedLibraries = [LibraryMetadata]()

public func getClangCompiler() throws -> AbsolutePath {
"/fake/path/to/clang"
Expand All @@ -50,7 +50,9 @@ public struct MockToolchain: PackageModel.Toolchain {
#endif
}

public init() {}
package init(swiftResourcesPath: AbsolutePath? = nil) {
self.swiftResourcesPath = swiftResourcesPath
}
}

extension Basics.Triple {
Expand All @@ -70,7 +72,7 @@ public let defaultTargetTriple: String = hostTriple.tripleString(forPlatformVers
public let defaultTargetTriple: String = hostTriple.tripleString
#endif

public func mockBuildParameters(
package func mockBuildParameters(
buildPath: AbsolutePath = "/path/to/build",
config: BuildConfiguration = .debug,
toolchain: PackageModel.Toolchain = MockToolchain(),
Expand Down
21 changes: 21 additions & 0 deletions Tests/BuildTests/ClangTargetBuildDescriptionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ final class ClangTargetBuildDescriptionTests: XCTestCase {
XCTAssertTrue(try targetDescription.basicArguments().contains("-w"))
}

func testSwiftCorelibsFoundationIncludeWorkaround() throws {
let toolchain = MockToolchain(swiftResourcesPath: AbsolutePath("/fake/path/lib/swift"))

let macosParameters = mockBuildParameters(toolchain: toolchain, targetTriple: .macOS)
let linuxParameters = mockBuildParameters(toolchain: toolchain, targetTriple: .arm64Linux)
let androidParameters = mockBuildParameters(toolchain: toolchain, targetTriple: .arm64Android)

let macDescription = try makeTargetBuildDescription("swift-corelibs-foundation",
buildParameters: macosParameters)
XCTAssertFalse(try macDescription.basicArguments().contains("\(macosParameters.toolchain.swiftResourcesPath!)"))

let linuxDescription = try makeTargetBuildDescription("swift-corelibs-foundation",
buildParameters: linuxParameters)
print(try linuxDescription.basicArguments())
XCTAssertTrue(try linuxDescription.basicArguments().contains("\(linuxParameters.toolchain.swiftResourcesPath!)"))

let androidDescription = try makeTargetBuildDescription("swift-corelibs-foundation",
buildParameters: androidParameters)
XCTAssertTrue(try androidDescription.basicArguments().contains("\(androidParameters.toolchain.swiftResourcesPath!)"))
}

private func makeClangTarget() throws -> ClangTarget {
try ClangTarget(
name: "dummy",
Expand Down