Add Embedded Swift and WASM support#17
Merged
Merged
Conversation
entityName's default (String(describing:)) needs runtime metadata, and Model.init(entities: any Entity.Type...) calls a generic initializer through an existential metatype of a protocol with an associated type. Neither is supported under Embedded Swift.
Swift.DecodingError and any Error existentials are unavailable under Embedded Swift. Add embedded-gated CoreModelError cases and factory functions that produce identical DecodingError values on platforms where Codable is available.
…sFeature(Embedded)
ViewContext is @mainactor, which is unavailable under Embedded Swift. The generic Entity-based convenience methods on ModelStorage and ViewContext, and ModelStorage's default count(_:)/insert(_:) implementations, trigger a SILGen crash under Embedded Swift when an async default protocol-extension method calls another async protocol requirement through Self. Gate these behind hasFeature(Embedded); embedded consumers call the ModelStorage requirements directly.
…dded) Swift.Encoder and its containers are entirely unavailable under Embedded Swift.
…dded) Swift.Decoder and its containers are entirely unavailable under Embedded Swift.
These rely on Locale/String.CompareOptions, which are not part of FoundationEssentials and are unavailable under Embedded Swift.
Swift.CodingKey is unavailable under Embedded Swift. This drop-in replacement, visible only under hasFeature(Embedded), lets consumer enum CodingKeys: String, CodingKey declarations keep compiling unchanged.
Minimal storage-layer UUID (16-byte tuple storage, string parse/ format via UInt128, RFC 4122 v4 random init) for platforms without Foundation or FoundationEssentials. Modeled on PureSwift/Bluetooth's embedded UUID.
Minimal storage-layer Date (timeIntervalSinceReferenceDate-backed) for platforms without Foundation or FoundationEssentials.
Minimal [UInt8]-backed Data for platforms without Foundation or FoundationEssentials.
Minimal string-backed URL for platforms without Foundation or FoundationEssentials. No real parsing/resolution.
Normalized decimal-string storage for platforms without Foundation or FoundationEssentials. Storage-layer only, no arithmetic.
The embedded SDK identifier (swift-6.3.2-RELEASE_wasm-embedded) ships inside the same artifact bundle as the regular WASM SDK (swift-6.3.2-RELEASE_wasm.artifactbundle.tar.gz); there is no separate _wasm-embedded download, so the previous URL 404'd.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
CoreModeltarget compile under Embedded Swift, starting with WebAssembly (swift-6.3.2-RELEASE_wasm-embeddedSDK).CoreDataModelis untouched.Date,UUID,Data,URL,Decimal) now resolve via aFoundationEssentials → Foundationcascade on platforms that have one, and fall back to minimal Foundation-free storage-layer shims (Sources/CoreModel/FoundationShims/) where neither is available.Codable/Encoder/Decoder/CodingKeyusage behind#if !hasFeature(Embedded), since Swift's Codable machinery is entirely unavailable under Embedded Swift. A shadowCodingKeyprotocol (Sources/CoreModel/Embedded/EmbeddedCodingKey.swift) keepsenum CodingKeys: String, CodingKeydeclarations compiling for embedded consumers.asyncdefault protocol-extension methods that call anotherasyncprotocol requirement throughSelfsegfault SILGen under Embedded Swift (reproduced on both 6.3.2 and 6.3.3).ModelStorage's genericEntity-based convenience methods andViewContext(@MainActor, also unsupported) are gated off under Embedded; embedded consumers call theModelStorageprotocol requirements directly.embeddedjob to the WebAssembly CI workflow and document the Embedded Swift constraints/build command in the README.No public API changes on Foundation platforms —
swift testand both wasm SDKs (embedded and non-embedded) build clean.Test plan
swift test(macOS, macros on) — 17/17 tests passSWIFTPM_ENABLE_MACROS=0 swift build -c release --swift-sdk swift-6.3.2-RELEASE_wasm(debug + release)SWIFTPM_ENABLE_MACROS=0 swift build -c release --swift-sdk swift-6.3.2-RELEASE_wasm-embedded(debug + release)git diffaudit confirming Foundation-platform changes are limited to import moves, gated conformances, and new files