Skip to content

@Observable macro fails on Linux: 'shouldNotifyObservers' not covered by macro (Swift 6.2.3) #197

Open

Description

@guitaripod

Description

Building any project using @Observable on Linux with Swift 6.2.3 fails with macro expansion errors.

Environment

  • OS: Arch Linux (kernel 6.18.3-arch1-1)
  • xtool: 1.16.1
  • Swift: 6.2.3 (swift-6.2.3-RELEASE)
  • iOS SDK: darwin (iOS 18.5 from Xcode)

Error

macro expansion @Observable:16:26: error: declaration name 'shouldNotifyObservers' is not covered by macro 'Observable'

The generated code shows mangled unique names:

private nonisolated func shouldNotifyObservers<$s6A_LIST22JourneysContentManager10ObservablefMm_6MemberfMu1_>(...)

Root Cause Analysis

The @Observable macro uses context.makeUniqueName("Member") for generic parameters. On Linux, these generate names starting with $ that look like Swift symbol manglings, which the compiler then rejects.

The macro declaration in Swift properly declares shouldNotifyObservers in its names: parameter:

@attached(member, names: named(_$observationRegistrar), named(access), named(withMutation), named(shouldNotifyObservers))

But the generated code uses unique mangled names that aren't being accepted.

Related Issues

Question

Is this a known limitation? Is there a workaround like using a different Swift version or toolchain configuration?

Activity

  1. kabiroberai commented on Jan 25, 2026

    @kabiroberai
    Member

    Can you try the iOS 26 SDK? Macros for system libraries tend to be tightly coupled between the compiler version and the SDK. The iOS 18 SDK probably expects Swift 6.1, and iOS 26 expects 6.2.

  2. guitaripod commented on Jan 26, 2026

    @guitaripod
    Author

    Update: Found workaround - Swift 6.1 works

    After testing, I can confirm that Swift 6.1 does not have this issue. The @Observable macro works correctly with Swift 6.1 on Linux.

    This appears to be a regression in Swift 6.2.x.

    However, after getting past this issue with Swift 6.1, I hit another blocker: the Sentry xcframework causes a signing error:

    Invalid arch file in fat mach-o file!
    

    This is tracked in #130. So even with the @observable fix, xtool builds fail if the project uses Sentry.

    For now, projects using:

    I've also filed the underlying Swift bug: swiftlang/swift#86778

  3. amgdev9 commented on Mar 1, 2026

    @amgdev9

    @guitaripod I tested on swift 6.2.4 and Observable macros work

  4. guitaripod commented on Mar 2, 2026

    @guitaripod
    Author

    Tested this extensively with a real-world app (~250 source files, 11 dependencies including Firebase, Supabase, Sentry, WebRTC).

    Swift 6.2.4 does NOT fix @Observable with the iOS 18.5 SDK. The issue is the SDK, not the compiler version.

    Root cause

    The iOS 18.5 SDK's Observation.swiftmodule swiftinterface was compiled with Swift 6.1.2. The @Observable macro declaration allows these member names:

    names: named(_$observationRegistrar), named(access), named(withMutation)
    

    Swift 6.2.x's ObservationMacros plugin generates an additional shouldNotifyObservers member, which the SDK's declaration doesn't permit → compile error.

    Even after patching the swiftinterface to add named(shouldNotifyObservers) (which fixes compilation), linking fails with:

    ld64.lld: error: undefined symbol: swift_coroFrameAlloc
    

    swift_coroFrameAlloc is a new Swift 6.2 runtime function that doesn't exist in the iOS 18.5 SDK's runtime libraries.

    What actually works

    Swift 6.1.2 matches the iOS 18.5 SDK perfectly — both compilation and linking succeed. The SDK was built with Swift 6.1.2, so the compiler/SDK pair is fully compatible.

    To use Swift 6.2.x

    You'd need an iOS 26 SDK (from Xcode 26) which includes:

    • Updated @Observable macro declaration with shouldNotifyObservers
    • Swift 6.2 runtime with swift_coroFrameAlloc

    Other notes for anyone trying to build a real app with xtool

    • #Preview macros fail on Linux (PreviewsMacros plugin not available) — wrap with conditional compilation
    • swift-tools-version: 6.0 enables strict concurrency by default — use .swiftLanguageMode(.v5) in target settings unless your codebase is Swift 6 ready
    • Swift regex literals (/.../) may fail to parse during cross-compilation — use NSRegularExpression as fallback
    • -ObjC linker flag is not supported by ld64.lld on Linux
  5. guitaripod commented on Mar 2, 2026

    @guitaripod
    Author

    Update: iOS 26.2 SDK (from Xcode 26.2) + Swift 6.2.4 works cleanly.

    Followed up on my earlier comment — switching from iOS 18.5 SDK to iOS 26.2 SDK eliminates nearly every workaround:

    Issue iOS 18.5 SDK iOS 26.2 SDK
    @Observable / shouldNotifyObservers Broken (SDK swiftinterface missing member) Works natively
    swift_coroFrameAlloc linker error Broken (runtime symbol missing) Works natively
    .allowBluetoothHFP Missing from SDK Present in SDK
    #Preview macros Broken (no PreviewsMacros plugin on Linux) Still broken — platform limitation
    Swift regex literals (/.../) Broken during cross-compilation Still broken — compiler bug

    Only 2 source-level changes needed with iOS 26.2 SDK:

    1. #Preview blocks → wrap with #if !XTOOL_BUILD (113 files in our case, scriptable)
    2. Regex literals → use Regex(#"pattern"#) string constructor instead of /.../ literals (2 files). Same modern Swift Regex API, just avoids the literal parser bug. NSRegularExpression also works but is unnecessary — the bug is only in the literal syntax, not the Regex type.

    Note on Xcode versions: Xcode 26.3's SDK ships swiftlang-6.2.3.3.2 which uses ~Copyable suppression syntax not yet in open-source Swift 6.2.4 — use Xcode 26.2 instead.

    Build: xtool dev build completes in ~220s for a ~250-file app with 11 dependencies (Firebase, Supabase, Sentry, WebRTC, etc).

  6. guitaripod commented on Mar 2, 2026

    @guitaripod
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions