Skip to content

Add Embedded Swift and WASM support#17

Merged
colemancda merged 36 commits into
masterfrom
feature/embedded-swift
Jul 14, 2026
Merged

Add Embedded Swift and WASM support#17
colemancda merged 36 commits into
masterfrom
feature/embedded-swift

Conversation

@colemancda

Copy link
Copy Markdown
Member

Summary

  • Make the CoreModel target compile under Embedded Swift, starting with WebAssembly (swift-6.3.2-RELEASE_wasm-embedded SDK). CoreDataModel is untouched.
  • Remove Foundation as a hard dependency: value types (Date, UUID, Data, URL, Decimal) now resolve via a FoundationEssentials → Foundation cascade on platforms that have one, and fall back to minimal Foundation-free storage-layer shims (Sources/CoreModel/FoundationShims/) where neither is available.
  • Gate all Codable/Encoder/Decoder/CodingKey usage behind #if !hasFeature(Embedded), since Swift's Codable machinery is entirely unavailable under Embedded Swift. A shadow CodingKey protocol (Sources/CoreModel/Embedded/EmbeddedCodingKey.swift) keeps enum CodingKeys: String, CodingKey declarations compiling for embedded consumers.
  • Work around a compiler crash: async default protocol-extension methods that call another async protocol requirement through Self segfault SILGen under Embedded Swift (reproduced on both 6.3.2 and 6.3.3). ModelStorage's generic Entity-based convenience methods and ViewContext (@MainActor, also unsupported) are gated off under Embedded; embedded consumers call the ModelStorage protocol requirements directly.
  • Add an embedded job to the WebAssembly CI workflow and document the Embedded Swift constraints/build command in the README.

No public API changes on Foundation platforms — swift test and both wasm SDKs (embedded and non-embedded) build clean.

Test plan

  • swift test (macOS, macros on) — 17/17 tests pass
  • SWIFTPM_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 diff audit confirming Foundation-platform changes are limited to import moves, gated conformances, and new files

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.
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.
@colemancda colemancda changed the title Add Embedded Swift (WASM) support to CoreModel Add Embedded Swift and WASM support Jul 14, 2026
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.
@colemancda colemancda merged commit 2cfe061 into master Jul 14, 2026
28 checks passed
@colemancda colemancda deleted the feature/embedded-swift branch July 14, 2026 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant