-
Notifications
You must be signed in to change notification settings - Fork 143
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
Open
cmcgee1024
wants to merge
19
commits into
swiftlang:main
Choose a base branch
from
cmcgee1024:swift_sdks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+805
−90
Open
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0756787
Swift SDK for WASM using the run destination
cmcgee1024 222f639
Restore the emit executable argument in Ld.xcspec
cmcgee1024 0211f9a
Override the rpath argument to the linker in the webassembly ld xcspe…
cmcgee1024 7a136b5
Move the platform registerSDK call to its original position
cmcgee1024 ae50208
Undo use of sdk.canonicalName instead of the provided canonical name
cmcgee1024 07993ad
Fix compile error in tests
cmcgee1024 d6bce25
Formatting
cmcgee1024 87af09f
Base the OTHER_LDFLAGS on the extra swift compiler settings
cmcgee1024 66cfd6c
Fix typo
cmcgee1024 6bdaeef
Introduce a new synthesizedSDK method for SDK registries that special…
cmcgee1024 6b5f572
Formatting and remove active run destination qualifier
cmcgee1024 4237bf4
Make explicit build target in run destination with both Apple and Swi…
cmcgee1024 ba56abd
Move the workaround for the UnixLd removal of the -sdk link argument …
cmcgee1024 2d02364
Rework the SWBBuildTarget API into a struct instead of an enum
cmcgee1024 afa0d52
Add a new platformName capability to PlatformInfoExtension, using tha…
cmcgee1024 95e4f38
Refactor name of appleSDK to toolchainSDK
cmcgee1024 e7cc4ae
Introduce compatibility with encoding/decoding of the build targets
cmcgee1024 f26b36b
Code review feedback
cmcgee1024 b9b7022
Add a test case with an example WASM SDK to test run destination hand…
cmcgee1024 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -997,6 +997,7 @@ public final class SDKRegistry: SDKRegistryLookup, CustomStringConvertible, Send | |
|
|
||
| // Construct the SDK and add it to the registry. | ||
| let sdk = SDK(canonicalName, canonicalNameComponents: try? parseSDKName(canonicalName), aliases, cohortPlatforms, displayName, path, version, productBuildVersion, defaultSettings, overrideSettings, variants, defaultDeploymentTarget, defaultVariant, (headerSearchPaths, frameworkSearchPaths, librarySearchPaths), directoryMacros.elements, isBaseSDK, fallbackSettingConditionValues, toolchains, versionMap, maximumDeploymentTarget) | ||
|
|
||
| if let duplicate = sdksByCanonicalName[canonicalName] { | ||
| delegate.error(path, "SDK '\(canonicalName)' already registered from \(duplicate.path.str)") | ||
| return nil | ||
|
|
@@ -1111,8 +1112,103 @@ public final class SDKRegistry: SDKRegistryLookup, CustomStringConvertible, Send | |
| } | ||
| } | ||
|
|
||
| // Xcode has special logic so that if there's no match here, and we'e *not* looking for a suffixed SDK, but we have an suffixed SDK which would otherwise match, then we use that. c.f. <rdar://problem/11414721> But we haven't needed that logic yet in Swift Build, so maybe we never will. | ||
| // Let's check the active run destination to see if there's an SDK path that we should be using | ||
| if matchedSDK == nil, | ||
| let sdkManifestPath = activeRunDestination?.sdkManiftestPath, | ||
| let triple = activeRunDestination?.triple, | ||
| case let llvmTriple = try LLVMTriple(triple) { | ||
|
|
||
| // TODO choose the platform based on the triple, and fallback to a default one in the default case | ||
| guard let platform = delegate.platformRegistry?.lookup(name: "webassembly") else { | ||
| return nil | ||
| } | ||
|
|
||
| let host = hostOperatingSystem | ||
|
|
||
| // Don't allow re-registering the same SDK | ||
| if let existing = sdksByCanonicalName[sdkManifestPath] { | ||
jakepetroules marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return existing | ||
| } | ||
|
|
||
| if let swiftSDK = try SwiftSDK(identifier: sdkManifestPath, version: "1.0.0", path: Path(sdkManifestPath), fs: localFS) { | ||
| let defaultProperties: [String: PropertyListItem] = [ | ||
| "SDK_STAT_CACHE_ENABLE": "NO", | ||
|
|
||
| "GENERATE_TEXT_BASED_STUBS": "NO", | ||
| "GENERATE_INTERMEDIATE_TEXT_BASED_STUBS": "NO", | ||
|
|
||
| // TODO check how this impacts operation on Windows | ||
| "CHOWN": "/usr/bin/chown", | ||
|
|
||
| // TODO are these going to be appropriate for all kinds of SDK's? | ||
| // SwiftSDK _could_ have tool entries for these, so use them if they are available | ||
| "LIBTOOL": .plString(host.imageFormat.executableName(basename: "llvm-lib")), | ||
| "AR": .plString(host.imageFormat.executableName(basename: "llvm-ar")), | ||
| ] | ||
|
|
||
| for (sdkTriple, tripleProperties) in swiftSDK.targetTriples { | ||
| guard triple == sdkTriple else { | ||
| continue | ||
| } | ||
|
|
||
| let toolsets = try tripleProperties.loadToolsets(sdk: swiftSDK, fs: localFS) | ||
|
|
||
| let sysroot = swiftSDK.path.join(tripleProperties.sdkRootPath) | ||
|
|
||
| // TODO support dynamic resources path | ||
| let swiftResourceDir = swiftSDK.path.join(tripleProperties.swiftStaticResourcesPath) | ||
| let clangResourceDir = swiftSDK.path.join(tripleProperties.clangStaticResourcesPath) | ||
|
|
||
| let tripleSystem = llvmTriple.system + (llvmTriple.systemVersion?.description ?? "") | ||
|
|
||
| // TODO handle tripleProperties.toolSearchPaths | ||
|
|
||
| let extraSwiftCompilerSettings = Array(toolsets.map( { $0.swiftCompiler?.extraCLIOptions ?? [] }).flatMap( { $0 })) | ||
| let headerSearchPaths: [PropertyListItem] = ["$(inherited)"] + (tripleProperties.includeSearchPaths ?? []).map( { PropertyListItem.plString($0) } ) | ||
| let librarySearchPaths: [PropertyListItem] = ["$(inherited)"] + (tripleProperties.librarySearchPaths ?? []).map( { PropertyListItem.plString($0) } ) | ||
|
|
||
| let sdk = registerSDK(sysroot, sysroot, platform, .plDict([ | ||
| "Type": .plString("SDK"), | ||
| "Version": .plString(swiftSDK.version), | ||
| "CanonicalName": .plString(swiftSDK.identifier), | ||
| "Aliases": [], | ||
| "IsBaseSDK": .plBool(true), | ||
| "DefaultProperties": .plDict([ | ||
| "PLATFORM_NAME": .plString(platform.name), | ||
| ].merging(defaultProperties, uniquingKeysWith: { _, new in new })), | ||
| "CustomProperties": .plDict([ | ||
| "LIBRARY_SEARCH_PATHS": .plArray(librarySearchPaths), | ||
| "HEADER_SEARCH_PATHS": .plArray(headerSearchPaths), | ||
| "OTHER_SWIFT_FLAGS": .plArray(["$(inherited)"] + extraSwiftCompilerSettings.map( {.plString($0)} )), | ||
| "SWIFTC_RESOURCE_DIR": .plString(swiftResourceDir.str), // Resource dir for linking Swift | ||
| "SWIFT_RESOURCE_DIR": .plString(swiftResourceDir.str), // Resource dir for compiling Swift | ||
| "CLANG_RESOURCE_DIR": .plString(clangResourceDir.str), // Resource dir for linking C/C++/Obj-C | ||
| "SDKROOT": .plString(sysroot.str), | ||
| "OTHER_LDFLAGS": .plArray(["$(OTHER_SWIFT_FLAGS)"]), // The extra swift compiler settings in JSON are intended to go to the linker driver too | ||
|
||
| ]), | ||
| "SupportedTargets": .plDict([ | ||
| "webassembly": .plDict([ | ||
cmcgee1024 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "Archs": .plArray([.plString(llvmTriple.arch)]), | ||
| "LLVMTargetTripleEnvironment": .plString(llvmTriple.environment ?? ""), | ||
| "LLVMTargetTripleSys": .plString(tripleSystem), | ||
| "LLVMTargetTripleVendor": .plString(llvmTriple.vendor), | ||
| ]) | ||
| ]), | ||
| // TODO: Leave compatible toolchain information in Swift SDKs | ||
| // "Toolchains": .plArray([]) | ||
| ])) | ||
|
|
||
| // FIXME why do we need to do this to avoid initialization errors on the SDK's default properties table? | ||
| if let sdk { | ||
| try sdk.loadExtendedInfo(delegate.namespace) | ||
|
|
||
| return sdk | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Xcode has special logic so that if there's no match here, and we'e *not* looking for a suffixed SDK, but we have an suffixed SDK which would otherwise match, then we use that. c.f. <rdar://problem/11414721> But we haven't needed that logic yet in Swift Build, so maybe we never will. | ||
| return matchedSDK?.sdk | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.