Xcode tells me
Previewing in executable targets now requires a new build layout for unoptimized builds. Either set
ENABLE_DEBUG_DYLIBtoYESfor this target, or break out your preview code into a separate framework with its own scheme.
How do enable that in Package.swift. swiftSettings don't work (.define and unsafeFlags with -D ...).
Creating a library product that the executable then depends on doesn't help either.
I have two targets, one is an executable target. The #Preview macro is in the non-executable target.
Unfortunately, SwiftPM does not inherit Xcode's build settings at all from a containing project. And there is no way to specify any Xcode build setting in a package manifest.
Specifying an executable target with SwiftUI in a package is an interesting case. If I were in your shoes, I'd just pull everything out into another module target in the package and have the executable depend on it. Previewing in that module will work just fine. All the executable needs is the @main entry point. It doesn't need the views or previews to be in that target.