-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Optional xcframework support for Linux #7239
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
Changes from 17 commits
427bc40
4c83efc
9034d5f
5f16e18
a8750a1
33f6cee
e063924
56d3ddd
28a78b1
a303a0f
cd9bcd3
774a84f
233feab
bf4ceac
688b872
f92fdb0
fce61bc
325bbab
f88a984
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // swift-tools-version:6.0 | ||
|
|
||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "SwiftFramework", | ||
| products: [ | ||
| .library(name: "SwiftFramework", type: .dynamic, targets: ["SwiftFramework"]), | ||
| ], | ||
| targets: [ | ||
| .target( | ||
| name: "SwiftFramework", | ||
| swiftSettings: [.unsafeFlags(["-enable-library-evolution"])] | ||
| ), | ||
| ] | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| public enum SwiftFrameworkWithEvolution | ||
| { | ||
| case v1 | ||
| case v2 | ||
|
|
||
| public | ||
| static var latest:Self { .v2 } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // swift-tools-version:6.0 | ||
|
|
||
| import PackageDescription | ||
|
|
||
| let package = Package(name: "TestBinary", | ||
| products: [ | ||
| .executable(name: "TestBinary", targets: ["TestBinary"]), | ||
| ], | ||
| targets: [ | ||
| .binaryTarget(name: "SwiftFramework", path: "SwiftFramework.xcframework"), | ||
| .executableTarget(name: "TestBinary", | ||
| dependencies: [ | ||
| .target(name: "SwiftFramework"), | ||
| ] | ||
| ), | ||
| ] | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import SwiftFramework | ||
|
|
||
| print("Latest Framework with LibraryEvolution version: \(SwiftFrameworkWithEvolution.latest)") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6807,6 +6807,114 @@ class BuildPlanTestCase: BuildSystemProviderTestCase { | |
| XCTAssertMatch(dynamicLibraryPathExtension, "dylib") | ||
| } | ||
|
|
||
| func testXCFrameworkBinaryTargetsLinux(platform: String = "linux", arch: String, targetTriple: Basics.Triple) async throws { | ||
| let Pkg: AbsolutePath = "/Pkg" | ||
|
|
||
| let fs = InMemoryFileSystem( | ||
| emptyFiles: | ||
| Pkg.appending(components: "Sources", "exe", "main.swift").pathString, | ||
| Pkg.appending(components: "Sources", "Library", "Library.swift").pathString | ||
| ) | ||
|
|
||
| try! fs.createDirectory("/Pkg/Framework.xcframework", recursive: true) | ||
|
||
| try! fs.writeFileContents( | ||
|
||
| "/Pkg/Framework.xcframework/Info.plist", | ||
| string: """ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>AvailableLibraries</key> | ||
| <array> | ||
| <dict> | ||
| <key>LibraryIdentifier</key> | ||
| <string>\(platform)-\(arch)</string> | ||
| <key>LibraryPath</key> | ||
| <string>Framework.framework</string> | ||
| <key>SupportedArchitectures</key> | ||
| <array> | ||
| <string>\(arch)</string> | ||
| </array> | ||
| <key>SupportedPlatform</key> | ||
| <string>\(platform)</string> | ||
| </dict> | ||
| </array> | ||
| <key>CFBundlePackageType</key> | ||
| <string>XFWK</string> | ||
| <key>XCFrameworkFormatVersion</key> | ||
| <string>1.0</string> | ||
| </dict> | ||
| </plist> | ||
| """ | ||
| ) | ||
|
|
||
| let observability = ObservabilitySystem.makeForTesting() | ||
|
|
||
| let graph = try loadModulesGraph( | ||
| fileSystem: fs, | ||
| manifests: [ | ||
| Manifest.createRootManifest( | ||
| displayName: "Pkg", | ||
| path: .init(validating: Pkg.pathString), | ||
| products: [ | ||
| ProductDescription(name: "exe", type: .executable, targets: ["exe"]), | ||
| ProductDescription(name: "Library", type: .library(.dynamic), targets: ["Library"]), | ||
| ], | ||
| targets: [ | ||
| TargetDescription(name: "exe", dependencies: ["Library"]), | ||
| TargetDescription(name: "Library", dependencies: ["Framework"]), | ||
| TargetDescription(name: "Framework", path: "Framework.xcframework", type: .binary), | ||
| ] | ||
| ), | ||
| ], | ||
| binaryArtifacts: [ | ||
| .plain("pkg"): [ | ||
| "Framework": .init(kind: .xcframework, originURL: nil, path: "/Pkg/Framework.xcframework"), | ||
| ], | ||
| ], | ||
| observabilityScope: observability.topScope | ||
| ) | ||
| XCTAssertNoDiagnostics(observability.diagnostics) | ||
|
|
||
| let result = try await BuildPlanResult(plan: mockBuildPlan( | ||
| triple: targetTriple, | ||
| graph: graph, | ||
| enableXCFrameworksOnLinux: true, | ||
| fileSystem: fs, | ||
| observabilityScope: observability.topScope | ||
| )) | ||
| XCTAssertNoDiagnostics(observability.diagnostics) | ||
|
|
||
| result.checkProductsCount(2) | ||
| result.checkTargetsCount(2) | ||
|
|
||
| let buildPath = result.plan.productsBuildPath | ||
|
|
||
| let libraryBasicArguments = try result.moduleBuildDescription(for: "Library").swift().compileArguments() | ||
| XCTAssertMatch( | ||
| libraryBasicArguments, | ||
| [.anySequence, "-I", "\(Pkg.appending(components: "Framework.xcframework", "\(platform)-\(arch)"))", .anySequence] | ||
| ) | ||
|
|
||
| let libraryLinkArguments = try result.buildProduct(for: "Library").linkArguments() | ||
| XCTAssertMatch(libraryLinkArguments, [.anySequence, "-L", "\(buildPath)", .anySequence]) | ||
|
|
||
| let exeCompileArguments = try result.moduleBuildDescription(for: "exe").swift().compileArguments() | ||
| XCTAssertMatch( | ||
| exeCompileArguments, | ||
| [.anySequence, "-I", "\(Pkg.appending(components: "Framework.xcframework", "\(platform)-\(arch)"))", .anySequence] | ||
| ) | ||
|
|
||
| let exeLinkArguments = try result.buildProduct(for: "exe").linkArguments() | ||
| XCTAssertMatch(exeLinkArguments, [.anySequence, "-L", "\(buildPath)", .anySequence]) | ||
|
|
||
| let executablePathExtension = try result.buildProduct(for: "exe").binaryPath.extension ?? "" | ||
| XCTAssertMatch(executablePathExtension, "") | ||
|
|
||
| let dynamicLibraryPathExtension = try result.buildProduct(for: "Library").binaryPath.extension | ||
| XCTAssertMatch(dynamicLibraryPathExtension, "so") | ||
| } | ||
|
|
||
| func testXCFrameworkBinaryTargets() async throws { | ||
| try await self.testXCFrameworkBinaryTargets(platform: "macos", arch: "x86_64", targetTriple: .x86_64MacOS) | ||
|
|
||
|
|
@@ -6815,6 +6923,12 @@ class BuildPlanTestCase: BuildSystemProviderTestCase { | |
|
|
||
| let arm64eTriple = try Basics.Triple("arm64e-apple-macosx") | ||
| try await self.testXCFrameworkBinaryTargets(platform: "macos", arch: "arm64e", targetTriple: arm64eTriple) | ||
|
|
||
| let x86_64Linux = try Basics.Triple("x86_64-unknown-linux-gnu") | ||
| try await self.testXCFrameworkBinaryTargetsLinux(arch: "x86_64", targetTriple: x86_64Linux) | ||
|
|
||
| let aarch64Linux = try Basics.Triple("aarch64-unknown-linux-gnu") | ||
| try await self.testXCFrameworkBinaryTargetsLinux(arch: "aarch64", targetTriple: aarch64Linux) | ||
| } | ||
|
|
||
| func testArtifactsArchiveBinaryTargets( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would need to return nil for Android triples. We should move the extension from
Triple.OStoTripleand check both the os and environment fields; ensuring the environment field is gnu or musl, or at least not android/androideabi.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jakepetroules ,
Moved and added an android check