Skip to content

Commit 7ad4f83

Browse files
authored
Optional xcframework support for Linux (swiftlang#9375)
Re-apply swiftlang#9374 which reverts swiftlang#7239. Fix Linux arm build; replacing arm64 -> aarch64; Ubuntu test passes. Fixes swiftlang#9372 Prior it was failing with: ``` swift-package-manager/.build/aarch64-unknown-linux-gnu/debug/swift-run --package-path /tmp/Miscellaneous_LibraryEvolutionLinuxXCF.07p2Rv/TestBinary --configuration debug --build-system native --scratch-path /tmp/Miscellaneous_LibraryEvolutionLinuxXCF.07p2Rv/TestBinary/.build-test --experimental-xcframeworks-on-linux TestBinary output: Building for debugging... [0/5] Write sources [1/5] Write swift-version--1B491C3C2A126B95.txt error: emit-module command failed with exit code 1 (use -v to see invocation) [3/7] Emitting module TestBinary /tmp/Miscellaneous_LibraryEvolutionLinuxXCF.07p2Rv/TestBinary/Sources/TestBinary/Main.swift:1:8: error: no such module 'SwiftFramework' 1 | import SwiftFramework | `- error: no such module 'SwiftFramework' 2 | 3 | print("Latest Framework with LibraryEvolution version: \(SwiftFrameworkWithEvolution.latest)") [4/7] Compiling TestBinary Main.swift /tmp/Miscellaneous_LibraryEvolutionLinuxXCF.07p2Rv/TestBinary/Sources/TestBinary/Main.swift:1:8: error: no such module 'SwiftFramework' 1 | import SwiftFramework | `- error: no such module 'SwiftFramework' 2 | 3 | print("Latest Framework with LibraryEvolution version: \(SwiftFrameworkWithEvolution.latest)") ✘ Test libraryEvolutionLinuxXCFramework() failed after 2.350 seconds with 1 issue. ```
1 parent 497944d commit 7ad4f83

File tree

16 files changed

+312
-12
lines changed

16 files changed

+312
-12
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// swift-tools-version:6.0
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "SwiftFramework",
7+
products: [
8+
.library(name: "SwiftFramework", type: .dynamic, targets: ["SwiftFramework"]),
9+
],
10+
targets: [
11+
.target(
12+
name: "SwiftFramework",
13+
swiftSettings: [.unsafeFlags(["-enable-library-evolution"])]
14+
),
15+
]
16+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public enum SwiftFrameworkWithEvolution
2+
{
3+
case v1
4+
case v2
5+
6+
public
7+
static var latest:Self { .v2 }
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// swift-tools-version:6.0
2+
3+
import PackageDescription
4+
5+
let package = Package(name: "TestBinary",
6+
products: [
7+
.executable(name: "TestBinary", targets: ["TestBinary"]),
8+
],
9+
targets: [
10+
.binaryTarget(name: "SwiftFramework", path: "SwiftFramework.xcframework"),
11+
.executableTarget(name: "TestBinary",
12+
dependencies: [
13+
.target(name: "SwiftFramework"),
14+
]
15+
),
16+
]
17+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import SwiftFramework
2+
3+
print("Latest Framework with LibraryEvolution version: \(SwiftFrameworkWithEvolution.latest)")

Sources/Build/BuildPlan/BuildPlan+Clang.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ extension BuildPlan {
6565
clangTarget.libraryBinaryPaths.insert(library.libraryPath)
6666
}
6767
case .xcframework:
68-
let libraries = try self.parseXCFramework(for: target, triple: clangTarget.buildParameters.triple)
68+
let libraries = try self.parseXCFramework(
69+
for: target,
70+
triple: clangTarget.buildParameters.triple,
71+
enableXCFrameworksOnLinux: clangTarget.buildParameters.enableXCFrameworksOnLinux
72+
)
6973
for library in libraries {
7074
library.headersPaths.forEach {
7175
clangTarget.additionalFlags += ["-I", $0.pathString]

Sources/Build/BuildPlan/BuildPlan+Product.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ extension BuildPlan {
298298
case .xcframework:
299299
let libraries = try self.parseXCFramework(
300300
for: binaryTarget,
301-
triple: productDescription.buildParameters.triple
301+
triple: productDescription.buildParameters.triple,
302+
enableXCFrameworksOnLinux: productDescription.buildParameters.enableXCFrameworksOnLinux
302303
)
303304
for library in libraries {
304305
libraryBinaryPaths.insert(library.libraryPath)

Sources/Build/BuildPlan/BuildPlan+Swift.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ extension BuildPlan {
6161
swiftTarget.libraryBinaryPaths.insert(library.libraryPath)
6262
}
6363
case .xcframework:
64-
let libraries = try self.parseXCFramework(for: target, triple: swiftTarget.buildParameters.triple)
64+
let libraries = try self.parseXCFramework(
65+
for: target,
66+
triple: swiftTarget.buildParameters.triple,
67+
enableXCFrameworksOnLinux: swiftTarget.buildParameters.enableXCFrameworksOnLinux
68+
)
6569
for library in libraries {
6670
library.headersPaths.forEach {
6771
swiftTarget.additionalFlags += ["-I", $0.pathString, "-Xcc", "-I", "-Xcc", $0.pathString]

Sources/Build/BuildPlan/BuildPlan.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,12 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
653653
}
654654

655655
/// Extracts the library information from an XCFramework.
656-
func parseXCFramework(for binaryTarget: BinaryModule, triple: Basics.Triple) throws -> [LibraryInfo] {
656+
func parseXCFramework(for binaryTarget: BinaryModule, triple: Basics.Triple, enableXCFrameworksOnLinux: Bool) throws -> [LibraryInfo] {
657657
try self.externalLibrariesCache.memoize(key: binaryTarget) {
658-
try binaryTarget.parseXCFrameworks(for: triple, fileSystem: self.fileSystem)
658+
if !enableXCFrameworksOnLinux && triple.os == .linux {
659+
return []
660+
}
661+
return try binaryTarget.parseXCFrameworks(for: triple, fileSystem: self.fileSystem)
659662
}
660663
}
661664

Sources/CoreCommands/Options.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,13 @@ public struct BuildOptions: ParsableArguments {
515515
@Flag(name: .customLong("experimental-prepare-for-indexing-no-lazy"), help: .hidden)
516516
var prepareForIndexingNoLazy: Bool = false
517517

518+
/// Hidden option to allow XCFrameworks on Linux
519+
@Flag(
520+
name: .customLong("experimental-xcframeworks-on-linux"),
521+
help: .hidden
522+
)
523+
public var enableXCFrameworksOnLinux: Bool = false
524+
518525
/// Whether to enable generation of `.swiftinterface`s alongside `.swiftmodule`s.
519526
@Flag(name: .customLong("enable-parseable-module-interfaces"))
520527
public var shouldEnableParseableModuleInterfaces: Bool = false

Sources/CoreCommands/SwiftCommandState.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,7 @@ public final class SwiftCommandState {
941941
sanitizers: options.build.enabledSanitizers,
942942
indexStoreMode: options.build.indexStoreMode.buildParameter,
943943
prepareForIndexing: prepareForIndexingMode,
944+
enableXCFrameworksOnLinux: options.build.enableXCFrameworksOnLinux,
944945
debuggingParameters: .init(
945946
debugInfoFormat: self.options.build.debugInfoFormat.buildParameter,
946947
triple: triple,

0 commit comments

Comments
 (0)