Hive
SwiftSyntax is being built for macos
GitHub issue · Open
What happened?
If I include both TCA and Codable, I get this error when compiling:
Showing All Issues ~/Downloads/tuist-main/examples/xcode/generated_app_with_composable_architecture/Tuist/.build/checkouts/codable-macro/Sources/CodableMacros/Codable/CodableIgnoredMacro.swift:4:8: Module 'SwiftSyntax' was created for incompatible target arm64-apple-macos10.15: ~/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/SwiftSyntax-2GLIZLN6X7IL8.swiftmodule
How do we reproduce it?
Take the example “generated_app_with_composable_architecture”, and add Codable to the Package.swift:
let package = Package( name: "App", dependencies: [ .package(url: "https://github.com/pointfreeco/swift-composable-architecture", .upToNextMinor(from: "1.22.3")), .package(url: "https://github.com/schibsted/codable-macro.git", exact: "1.1.0"), ] )
And include it as a dependency of the project:
.external(name: "Codable"),
Error log
Running “tuist cache”
…
[IssueReporting] Compiling SwiftTesting.swift
[IssueReporting] Compiling UncheckedSendable.swift
[IssueReporting] Compiling WithExpectedIssue.swift
[IssueReporting] Compiling WithIssueContext.swift
[IssueReporting] Compiling WithExpectedIssue.swift
[IssueReporting] Compiling WithIssueContext.swift
[IssueReporting] Compiling IsTesting.swift
[IssueReporting] Compiling IssueReporter.swift
[IssueReporting] Compiling RuntimeWarningReporter.swift
[IssueReporting] Compiling ReportIssue.swift
[CodableMacros] Compiling CodableMacro.swift
[CodableMacros] Compiling CodableMacroError.swift
[CodableMacros] Compiling EncodableMacro.swift
[CodableMacros] Compiling PropertyDefinition.swift
[CodableMacros] Compiling MemberwiseInitializableMacro.swift
❌ ~/Downloads/tuist-main/examples/xcode/generated_app_with_composable_architecture/Tuist/.build/checkouts/codable-macro/Sources/CodableMacros/Codable/CodableIgnoredMacro.swift:4:8: module 'SwiftSyntax' was created for incompatible target arm64-apple-macos10.15: /v
[CodableMacros] Compiling SwiftSyntax+Extensions.swift
❌ ~/Downloads/tuist-main/examples/xcode/generated_app_with_composable_architecture/Tuist/.build/checkouts/codable-macro/Sources/CodableMacros/Codable/CodableIgnoredMacro.swift:4:8: module 'SwiftSyntax' was created for incompatible target arm64-apple-macos10.15: /var/folders/w6/00_brj417kq44cf8p2k1pmnr0000gn/T/TemporaryDirectory.Lopf0o/derived-data/ModuleCache.noindex/SwiftSyntax-4SJHY3IM3085.swiftmodule
[CodableMacros] Compiling TypeDefinition.swift
[CodableMacros] Compiling EncodableMacro.swift
❌ ~/Downloads/tuist-main/examples/xcode/generated_app_with_composable_architecture/Tuist/.build/checkouts/codable-macro/Sources/CodableMacros/Codable/CodableIgnoredMacro.swift:4:8: module 'SwiftSyntax' was created for incompatible target arm64-apple-macos10.15: /var/folders/w6/00_brj417kq44cf8p2k1pmnr0000gn/T/TemporaryDirectory.Lopf0o/derived-data/ModuleCache.noindex/SwiftSyntax-4SJHY3IM3085.swiftmodule
[CodableMacros] Compiling PropertyDefinition.swift
❌ ~/Downloads/tuist-main/examples/xcode/generated_app_with_composable_architecture/Tuist/.build/checkouts/codable-macro/Sources/CodableMacros/Codable/CodableIgnoredMacro.swift:4:8: module 'SwiftSyntax' was created for incompatible target arm64-apple-macos10.15: /var/folders/w6/00_brj417kq44cf8p2k1pmnr0000gn/T/TemporaryDirectory.Lopf0o/derived-data/ModuleCache.noindex/SwiftSyntax-4SJHY3IM3085.swiftmodule
…
macOS version
15.6.1
Tuist version
4.129.0
Xcode version
16.4
Investigate, reproduce, or fix this item in an isolated repository. Each Flight preserves its outcome and agent session.
Start a Flight and preserve its objective, outcome, and session here.
Hi @buscarini! I’m Dosu and I’m helping the tuist team.
This error happens because Swift macros (like those in codable-macro) are always built as macOS executables, even if your main target is iOS. If macro/plugin dependencies (such as SwiftSyntax or SwiftSyntaxMacros) are not explicitly limited to macOS in your Tuist manifests or Package.swift, Tuist tries to build them for all platforms, which leads to the “SwiftSyntax was created for incompatible target” error when the architectures or SDKs don’t match up (discussion, another example).
To fix this:
-
In your Tuist manifest (e.g., Project.swift), constrain macro/plugin dependencies to only macOS. For example:
.external(name: "Codable", condition: .when(platforms: [.macOS]))Or, if using Package.swift directly, set product destinations:
let packageSettings = PackageSettings(productDestinations: ["CodableMacros": .macOS]) -
Clean up any stale build artifacts: run
tuist clean, delete the.buildfolder, and clear Derived Data. -
Re-run
tuist installandtuist generate. -
If you use custom xcodebuild scripts, avoid passing the
-sdkflag when building projects with macros—let Xcode select the SDK per target (see details).
If you need to cache for multiple architectures, run tuist cache separately for each one; Tuist doesn’t currently support universal xcframework caching for SwiftSyntax (reference).
Recent Tuist releases (see PR #9115) have improved macro and resource handling, so make sure you’re on the latest version.
If you still see issues, double-check that all dependencies use a SwiftSyntax version compatible with your Xcode/Swift toolchain.
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
The “No such module ‘Codable’” error happens because constraining the macro dependency to macOS only also removes the main library from your iOS build. For macro-based Swift packages, you need to include the macro product only for macOS, but the main library for all platforms. If you only add a platform condition to the whole dependency, you lose the main library on iOS.
The fix is to declare both products separately in your manifest. For example, if the package exposes both a library (e.g., “Codable”) and a macro (e.g., “CodableMacros”), your dependencies should look like this:
// In your target dependencies:
.external(name: "Codable"), // available on all platforms
.external(name: "CodableMacros", condition: .when(platforms: [.macOS])) // macro only on macOS
Or, in Package.swift (if using Tuist’s package integration):
let packageSettings = PackageSettings(
productDestinations: [
"CodableMacros": .macOS
]
)
Make sure you include the main library product for all platforms, and only restrict the macro product to macOS. If you’re unsure of the exact product names, check the Package.swift of the codable-macro package.
After updating, run tuist clean, remove the .build folder, and regenerate your project. This pattern is also shown in Tuist’s macro/plugin example.
If you share your current manifest, I can help tailor the configuration.
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
That error means the codable-macro package does not declare a product named CodableMacros in its Package.swift, so Tuist can’t find it as a dependency. In Tuist, you can only reference products that are actually declared in the package’s manifest—if the macro isn’t exposed as a separate product, you can’t reference it independently or apply platform constraints to it separately from the main library.
You should check the codable-macro Package.swift (on GitHub or locally) to confirm the exact product names. Most likely, you should only use .external(name: "Codable") in your manifest. If you need to restrict macro usage to macOS but the macro isn’t a separate product, that’s not possible without forking the package or asking the maintainer to expose the macro as its own product.
For more details, see the Tuist docs on external dependencies and discussion of this error.
To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.