Skip to content

fix(compose): prefer the SwiftUI host over a generated runner (#180) - #181

Merged
arxdeus merged 3 commits into
mainfrom
compose-chooses-a-generated-runner-over-the-exis
Nov 25, 2026
Merged

arxdeus merged 3 commits into
mainfrom
compose-chooses-a-generated-runner-over-the-exis

Conversation

@arxdeus

@arxdeus arxdeus commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Fixes #180.

Problem

When a Compose project had both a SwiftUI @main App in iosApp/ and a Kotlin ComposeUIViewController entry, xcross compose build/run picked the Kotlin entry and generated an Objective-C runner. That skipped the existing Swift app and its launch setup, and failed to link when a dependency needed the Swift runtime libraries.

Changes

  • KmpEntryDiscovery.classifyEntry now prefers the SwiftUI host, then the Kotlin entry, then framework-only.
  • New --entry auto|swift|kotlin option on xcross compose build and xcross compose run (default auto). --entry kotlin restores the generated runner. --entry swift requires the SwiftUI host. Both fail with a clear error when the requested entry is missing.
  • xcross compose doctor now checks Swift imports for such projects too, since the Swift host is what gets built.
  • README and CHANGELOG updated.

Tests

  • kmp_project_test.dart: precedence with both entries, --entry kotlin/swift selection and errors, a non-App Swift file next to a Kotlin entry stays a Kotlin app.
  • compose_pack_operation_test.dart: options.entry reaches detection.
  • compose_command_args_test.dart: --entry parsing for build and run.
  • doctor_command_test.dart: updated for the new precedence.
  • dart analyze clean, dart test in packages/xcross: all 2340 tests pass.

Swift runtime in the generated runner

The generated Objective-C runner (still used with --entry kotlin or without a SwiftUI host) linked with ld64.lld and no Swift search path, so a KMP framework whose dependencies contain Swift code failed with undefined Swift runtime symbols. The link now passes -L <SDK>/usr/lib/swift (runtime stubs) and -L <toolchain>/usr/lib/swift/<platform> (libswiftCompatibility*.a), as swiftc does for the Swift runner.

Verified with a real ld64.lld link of an ObjC main.o against a Swift object (iOS 15.0 and 13.0 targets): without the flags it fails with undefined Swift symbols. With only one of the two paths it still fails. With both it links, and otool -L shows only /usr/lib/swift/*.dylib (no @rpath/libswift*, so nothing extra to embed). A link with no Swift objects is unchanged. runner_builder_test.dart asserts the new arguments.

When a Compose project has both a SwiftUI @main host in iosApp/ and a
Kotlin ComposeUIViewController entry, build the Swift host instead of a
generated Objective-C runner, so its launch setup and Swift dependencies
are kept. Add --entry auto|swift|kotlin to compose build and run to pick
the entry point explicitly.
…180)

A KMP framework whose dependencies contain Swift code autolinks
-lswiftCore and the -lswiftCompatibility* archives. ld64.lld got no
search path for them, so the generated runner failed to link. Pass the
SDK's usr/lib/swift (runtime stubs) and the toolchain's
usr/lib/swift/<platform> (compatibility archives), as swiftc does for
the Swift runner. Verified with a real ld64.lld link: both are required,
and links without Swift objects are unchanged.
@github-actions github-actions Bot deleted a comment from arxdeus Nov 25, 2026
Add a 'Choosing the app entry point' section with the auto/swift/kotlin
table, examples and the build/run option lists. --framework now ignores
--entry, as documented, so a missing entry cannot fail a framework-only
build.
@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Integration simulator report

xcross: d6842da60a85 · xcross_examples: c46344989849

Failed jobs

✅ No failed jobs.

Flutter

Host App Status Screenshot
macos-15 (native) flutter-example ✅ Ready 🖼️ Open image
ubuntu-24.04 flutter-example ✅ Ready 🖼️ Open image
ubuntu-24.04-arm flutter-example ✅ Ready 🖼️ Open image
windows-11-arm flutter-example ✅ Ready 🖼️ Open image
windows-2022 flutter-example ✅ Ready 🖼️ Open image

Compose

Host App Status Screenshot
macos-15 (native) compose ✅ Ready 🖼️ Open image

Screenshots are Actions artifacts of this run. They open in the browser and expire after 30 days.

Full run

@arxdeus

arxdeus commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

@skaldebane, could you please try this branch and tell me if fix your problem

xcross update --ref compose-chooses-a-generated-runner-over-the-exis

@skaldebane

Copy link
Copy Markdown

yep, this seems to work perfectly well now.

thanks for the quick fix!

@arxdeus
arxdeus merged commit 363bd99 into main Nov 25, 2026
22 checks passed
@arxdeus
arxdeus deleted the compose-chooses-a-generated-runner-over-the-exis branch November 25, 2026 17:19
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.

Compose chooses a generated runner over the existing SwiftUI app

2 participants