-
Notifications
You must be signed in to change notification settings - Fork 134
Swift SDK for WASM using the run destination #966
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
base: main
Are you sure you want to change the base?
Changes from all commits
0756787
222f639
0211f9a
7a136b5
ae50208
07993ad
d6bce25
87af09f
66cfd6c
6bdaeef
6b5f572
4237bf4
ba56abd
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 |
|---|---|---|
|
|
@@ -1803,11 +1803,24 @@ private class SettingsBuilder: ProjectMatchLookup { | |
| } | ||
|
|
||
| do { | ||
| sdk = try project.map { try sdkRegistry.lookup(nameOrPath: sdkroot, basePath: $0.sourceRoot, activeRunDestination: parameters.activeRunDestination) } ?? nil | ||
| sdk = try project.map { | ||
| switch parameters.activeRunDestination?.buildTarget { | ||
| case let .swiftSDK(sdkManifestPath: sdkManifestPath, triple: triple): | ||
| // FIXME platform should be decided by the triple | ||
| guard let platform = core.platformRegistry.lookup(name: "webassembly") else { | ||
| errors.append("unable to find platform 'webassembly'") | ||
| return nil | ||
| } | ||
| return try sdkRegistry.synthesizedSDK(platform: platform, sdkManifestPath: sdkManifestPath, triple: triple) | ||
| default: | ||
| return try sdkRegistry.lookup(nameOrPath: sdkroot, basePath: $0.sourceRoot, activeRunDestination: parameters.activeRunDestination) | ||
| } | ||
| } ?? nil | ||
| } catch { | ||
| sdk = nil | ||
| sdkLookupErrors.append(error) | ||
| } | ||
|
|
||
| if let s = sdk { | ||
| // Evaluate the SDK variant, if there is one. | ||
| let sdkVariantName: String | ||
|
|
@@ -3512,23 +3525,46 @@ private class SettingsBuilder: ProjectMatchLookup { | |
|
|
||
| // Destination info: since runDestination.{platform,sdk} were set by the IDE, we expect them to resolve in Swift Build correctly | ||
| guard let runDestination = self.parameters.activeRunDestination else { return } | ||
| guard let destinationPlatform: Platform = self.core.platformRegistry.lookup(name: runDestination.platform) else { | ||
| self.errors.append("unable to resolve run destination platform: '\(runDestination.platform)'") | ||
| return | ||
| } | ||
|
|
||
| let destinationPlatform: Platform | ||
| let destinationSDK: SDK | ||
| do { | ||
| guard let sdk = try sdkRegistry.lookup(runDestination.sdk, activeRunDestination: runDestination) else { | ||
| self.errors.append("unable to resolve run destination SDK: '\(runDestination.sdk)'") | ||
| switch runDestination.buildTarget { | ||
| case let .swiftSDK(sdkManifestPath: sdkManifestPath, triple: triple): | ||
| // FIXME: the platform should be determined using the triple | ||
| guard let platform = self.core.platformRegistry.lookup(name: "webassembly") else { | ||
| self.errors.append("unable to resolve run destination platform: 'webassembly'") | ||
| return | ||
| } | ||
|
|
||
| destinationPlatform = platform | ||
|
|
||
| guard let sdk = try? sdkRegistry.synthesizedSDK(platform: platform, sdkManifestPath: sdkManifestPath, triple: triple) else { | ||
| self.errors.append("unable to synthesize SDK for Swift SDK build target: '\(runDestination.buildTarget)'") | ||
| return | ||
| } | ||
| destinationSDK = sdk | ||
| } catch let error as AmbiguousSDKLookupError { | ||
| self.diagnostics.append(error.diagnostic) | ||
| return | ||
| } catch { | ||
| self.errors.append("\(error)") | ||
| return | ||
| default: | ||
| guard let platform = self.core.platformRegistry.lookup(name: runDestination.platform) else { | ||
| self.errors.append("unable to resolve run destination platform: '\(runDestination.platform)'") | ||
| return | ||
| } | ||
|
|
||
| destinationPlatform = platform | ||
|
|
||
| do { | ||
| if let sdk = try sdkRegistry.lookup(runDestination.sdk, activeRunDestination: runDestination) { | ||
| destinationSDK = sdk | ||
| } else { | ||
| self.errors.append("unable to resolve run destination SDK: '\(runDestination.sdk)'") | ||
| return | ||
| } | ||
| } catch let error as AmbiguousSDKLookupError { | ||
| self.diagnostics.append(error.diagnostic) | ||
| return | ||
| } catch { | ||
| self.errors.append("\(error)") | ||
| return | ||
| } | ||
| } | ||
|
|
||
| let destinationPlatformIsMacOS = destinationPlatform.name == "macosx" | ||
|
|
@@ -3639,9 +3675,23 @@ private class SettingsBuilder: ProjectMatchLookup { | |
|
|
||
| // Destination info: since runDestination.{platform,sdk} were set by the IDE, we expect them to resolve in Swift Build correctly | ||
| guard let runDestination = self.parameters.activeRunDestination else { return } | ||
| guard let destinationPlatform: Platform = self.core.platformRegistry.lookup(name: runDestination.platform) else { | ||
| self.errors.append("unable to resolve run destination platform: '\(runDestination.platform)'") | ||
| return | ||
|
|
||
| let destinationPlatform: Platform | ||
|
|
||
| switch runDestination.buildTarget { | ||
| case .swiftSDK: | ||
| // TODO use the triple to decide the platform, or use a fallback | ||
| guard let platform: Platform = self.core.platformRegistry.lookup(name: "webassembly") else { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's fix this hardcoded webassembly reference before landing the initial change. Paraphrasing what I mentioned in another comment, a good way to do this would be to additional method on Then, in each of the implementations:
Here in Settings.swift, you enumerate the extension point conformances, add them to a Set, and if you have exactly one match, use it, else emit an error. If you get no matches at all, fall back to the "none" platform. -- Also make sure to factor this logic into a dedicated function; I see the hardcoded webassembly lookup is currently in 3 different places. |
||
| self.errors.append("unable to resolve run destination platform: '\(runDestination.platform)'") | ||
| return | ||
| } | ||
| destinationPlatform = platform | ||
| default: | ||
| guard let platform: Platform = self.core.platformRegistry.lookup(name: runDestination.platform) else { | ||
| self.errors.append("unable to resolve run destination platform: '\(runDestination.platform)'") | ||
| return | ||
| } | ||
| destinationPlatform = platform | ||
| } | ||
|
|
||
| // Target info | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -318,13 +318,16 @@ public struct BuildParametersMessagePayload: SerializableCodable, Equatable, Sen | |
| } | ||
|
|
||
| public struct RunDestinationInfo: SerializableCodable, Hashable, Sendable { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not part of public API and there is no need to maintain backwards compatibility, so this should eliminate the dedicated properties and go straight to having a BuildTarget enum with the two cases (swiftSDK for swiftSdkPath + triple, and appleSDK for platform + sdk + sdkVariant). |
||
| public var disableOnlyActiveArch: Bool | ||
| public var hostTargetedPlatform: String? | ||
|
|
||
| public var buildTarget: BuildTarget? | ||
|
|
||
| public var platform: String | ||
| public var sdk: String | ||
| public var sdkVariant: String? | ||
| public var targetArchitecture: String | ||
| public var supportedArchitectures: OrderedSet<String> | ||
| public var disableOnlyActiveArch: Bool | ||
| public var hostTargetedPlatform: String? | ||
|
|
||
| public init(platform: String, sdk: String, sdkVariant: String?, targetArchitecture: String, supportedArchitectures: OrderedSet<String>, disableOnlyActiveArch: Bool, hostTargetedPlatform: String?) { | ||
| self.platform = platform | ||
|
|
@@ -334,7 +337,23 @@ public struct RunDestinationInfo: SerializableCodable, Hashable, Sendable { | |
| self.supportedArchitectures = supportedArchitectures | ||
| self.disableOnlyActiveArch = disableOnlyActiveArch | ||
| self.hostTargetedPlatform = hostTargetedPlatform | ||
| self.buildTarget = nil | ||
| } | ||
|
|
||
| public init(buildTarget: BuildTarget, disableOnlyActiveArch: Bool, hostTargetedPlatform: String? = nil) { | ||
| self.platform = "" | ||
| self.sdk = "" | ||
| self.sdkVariant = nil | ||
| self.targetArchitecture = "" | ||
| self.supportedArchitectures = [] | ||
| self.buildTarget = buildTarget | ||
| self.disableOnlyActiveArch = disableOnlyActiveArch | ||
| self.hostTargetedPlatform = hostTargetedPlatform | ||
| } | ||
| } | ||
|
|
||
| public enum BuildTarget: SerializableCodable, Hashable, Sendable { | ||
| case swiftSDK(sdkManifestPath: String, triple: String) | ||
| } | ||
|
|
||
| /// The arena info being sent in a Message. | ||
|
|
||
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.
No such concept of CHOWN, so shouldn't matter.
addSpecificChangePermissionTasksbails out early for Windows targets.