Skip to content

Commit af1bea6

Browse files
authored
Fix compatibility with Swift 6.1 for Linux Swift SDKs (#218)
Resolves #217. While Swift SDKs for WASI require absolute file paths due to #212. We should roll back this change for Linux, since there are no Embedded Swift SDKs for Linux yet, and we need to support Swift 6.1. Additionally, removed unused and outdated Swift SDK metadata model types.
1 parent f4b0261 commit af1bea6

File tree

4 files changed

+45
-88
lines changed

4 files changed

+45
-88
lines changed

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Entrypoint.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension Triple.Arch {
3434
}
3535

3636
extension SwiftSDKGenerator {
37-
package func run(recipe: SwiftSDKRecipe) async throws {
37+
package func run(recipe: some SwiftSDKRecipe) async throws {
3838
try await withQueryEngine(OSFileSystem(), self.logger, cacheLocation: self.engineCachePath) {
3939
engine in
4040
let httpClientType: HTTPClientProtocol.Type
@@ -79,7 +79,8 @@ extension SwiftSDKGenerator {
7979

8080
try await generateArtifactBundleManifest(
8181
hostTriples: swiftSDKProduct.hostTriples,
82-
artifacts: artifacts
82+
artifacts: artifacts,
83+
shouldUseFullPaths: recipe.shouldSupportEmbeddedSwift
8384
)
8485

8586
// Extra spaces added for readability for the user

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Metadata.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ extension SwiftSDKGenerator {
4949
return toolsetJSONPath
5050
}
5151

52+
/// Generates `swift-sdk.json` metadata file.
5253
func generateSwiftSDKMetadata(
5354
toolsetPath: FilePath,
5455
sdkDirPath: FilePath,
@@ -57,7 +58,7 @@ extension SwiftSDKGenerator {
5758
) throws -> FilePath {
5859
logger.info("Generating Swift SDK metadata JSON file...")
5960

60-
let destinationJSONPath = pathsConfiguration.swiftSDKRootPath.appending(
61+
let swiftSDKMetadataPath = pathsConfiguration.swiftSDKRootPath.appending(
6162
"\(isForEmbeddedSwift ? "embedded-" : "")swift-sdk.json"
6263
)
6364

@@ -95,14 +96,18 @@ extension SwiftSDKGenerator {
9596
)
9697

9798
try writeFile(
98-
at: destinationJSONPath,
99+
at: swiftSDKMetadataPath,
99100
encoder.encode(metadata)
100101
)
101102

102-
return destinationJSONPath
103+
return swiftSDKMetadataPath
103104
}
104105

105-
func generateArtifactBundleManifest(hostTriples: [Triple]?, artifacts: [String: FilePath]) throws {
106+
func generateArtifactBundleManifest(
107+
hostTriples: [Triple]?,
108+
artifacts: [String: FilePath],
109+
shouldUseFullPaths: Bool
110+
) throws {
106111
logger.info("Generating .artifactbundle info JSON file...")
107112

108113
let artifactBundleManifestPath = pathsConfiguration.artifactBundlePath.appending("info.json")
@@ -116,6 +121,9 @@ extension SwiftSDKGenerator {
116121
var relativePath = $0
117122
let prefixRemoved = relativePath.removePrefix(pathsConfiguration.artifactBundlePath)
118123
assert(prefixRemoved)
124+
if !shouldUseFullPaths {
125+
relativePath.removeLastComponent()
126+
}
119127

120128
return .init(
121129
type: .swiftSDK,

Sources/SwiftSDKGenerator/Serialization/SwiftSDKMetadata.swift

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,68 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
struct DestinationV1: Encodable {
14-
enum CodingKeys: String, CodingKey {
15-
case version
16-
case sdk
17-
case toolchainBinDir = "toolchain-bin-dir"
18-
case target
19-
case extraCCFlags = "extra-cc-flags"
20-
case extraSwiftCFlags = "extra-swiftc-flags"
21-
case extraCPPFlags = "extra-cpp-flags"
22-
}
23-
24-
let version = 1
25-
let sdk: String
26-
let toolchainBinDir: String
27-
let target: String
28-
let extraCCFlags: [String]
29-
let extraSwiftCFlags: [String]
30-
let extraCPPFlags: [String]
31-
}
32-
33-
struct DestinationV2: Encodable {
34-
let version = 2
35-
36-
let sdkRootDir: String
37-
let toolchainBinDir: String
38-
let hostTriples: [String]
39-
let targetTriples: [String]
40-
let extraCCFlags: [String]
41-
let extraSwiftCFlags: [String]
42-
let extraCXXFlags: [String]
43-
let extraLinkerFlags: [String]
44-
}
45-
46-
/// Represents v3 schema of `destination.json` files used for cross-compilation.
47-
struct DestinationV3: Encodable {
48-
struct TripleProperties: Encodable {
49-
/// Path relative to `destination.json` containing SDK root.
50-
let sdkRootPath: String
51-
52-
/// Path relative to `destination.json` containing Swift resources for dynamic linking.
53-
var swiftResourcesPath: String?
54-
55-
/// Path relative to `destination.json` containing Swift resources for static linking.
56-
var swiftStaticResourcesPath: String?
57-
58-
/// Array of paths relative to `destination.json` containing headers.
59-
var includeSearchPaths: [String]?
60-
61-
/// Array of paths relative to `destination.json` containing libraries.
62-
var librarySearchPaths: [String]?
63-
64-
/// Array of paths relative to `destination.json` containing toolset files.
65-
let toolsetPaths: [String]?
66-
}
67-
68-
/// Version of the schema used when serializing the destination file.
69-
let schemaVersion = "3.0"
70-
71-
/// Mapping of triple strings to corresponding properties of such target triple.
72-
let runTimeTriples: [String: TripleProperties]
73-
}
74-
7513
/// Represents v4 schema of `swift-sdk.json` (previously `destination.json`) files used for cross-compilation.
7614
package struct SwiftSDKMetadataV4: Encodable {
7715
package struct TripleProperties: Encodable {
@@ -94,7 +32,7 @@ package struct SwiftSDKMetadataV4: Encodable {
9432
var toolsetPaths: [String]?
9533
}
9634

97-
/// Version of the schema used when serializing the destination file.
35+
/// Version of the schema used when serializing the Swift SDK metadata file.
9836
let schemaVersion = "4.0"
9937

10038
/// Mapping of triple strings to corresponding properties of such target triple.

Tests/SwiftSDKGeneratorTests/Generator/SwiftSDKGenerator+MetadataTests.swift

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,38 @@ final class SwiftSDKGeneratorMetadataTests: XCTestCase {
7676

7777
try await sdk.createDirectoryIfNeeded(at: sdk.pathsConfiguration.artifactBundlePath)
7878

79-
// Generate bundle metadata
80-
try await sdk.generateArtifactBundleManifest(
81-
hostTriples: [sdk.targetTriple],
82-
artifacts: ["foo": sdk.pathsConfiguration.artifactBundlePath.appending("bar.json")]
83-
)
79+
for shouldUseFullPaths in [true, false] {
80+
// Generate bundle metadata
81+
try await sdk.generateArtifactBundleManifest(
82+
hostTriples: [sdk.targetTriple],
83+
artifacts: ["foo": sdk.pathsConfiguration.artifactBundlePath.appending("foo").appending("bar.json")],
84+
shouldUseFullPaths: shouldUseFullPaths
85+
)
8486

85-
// Make sure the file exists
86-
let archiveMetadataFile = await sdk.pathsConfiguration.artifactBundlePath.appending("info.json")
87-
fileExists = await sdk.doesFileExist(at: archiveMetadataFile)
88-
XCTAssertTrue(fileExists)
87+
// Make sure the file exists
88+
let archiveMetadataFile = await sdk.pathsConfiguration.artifactBundlePath.appending("info.json")
89+
fileExists = await sdk.doesFileExist(at: archiveMetadataFile)
90+
XCTAssertTrue(fileExists)
8991

90-
// Read back file, make sure it contains the expected data
91-
let data = try await sdk.readFile(at: archiveMetadataFile)
92-
let decodedMetadata = try JSONDecoder().decode(ArtifactsArchiveMetadata.self, from: data)
93-
XCTAssertEqual(decodedMetadata.artifacts.count, 1)
94-
for (id, artifact) in decodedMetadata.artifacts {
95-
XCTAssertEqual(id, "foo")
96-
XCTAssertEqual(artifact.variants, [.init(path: "bar.json", supportedTriples: [testCase.targetTriple.triple])])
97-
}
92+
// Read back file, make sure it contains the expected data
93+
let data = try await sdk.readFile(at: archiveMetadataFile)
94+
let decodedMetadata = try JSONDecoder().decode(ArtifactsArchiveMetadata.self, from: data)
95+
XCTAssertEqual(decodedMetadata.artifacts.count, 1)
96+
let variant: ArtifactsArchiveMetadata.Variant
97+
if shouldUseFullPaths {
98+
variant = .init(path: "foo/bar.json", supportedTriples: [testCase.targetTriple.triple])
99+
} else {
100+
variant = .init(path: "foo", supportedTriples: [testCase.targetTriple.triple])
101+
}
98102

99-
// Cleanup
100-
try await sdk.removeFile(at: archiveMetadataFile)
103+
for (id, artifact) in decodedMetadata.artifacts {
104+
XCTAssertEqual(id, "foo")
105+
XCTAssertEqual(artifact.variants, [variant])
106+
}
107+
108+
// Cleanup
109+
try await sdk.removeFile(at: archiveMetadataFile)
110+
}
101111
}
102112
}
103113
}

0 commit comments

Comments
 (0)