Hive
SPM .embedInCode resource rule causes decoding error when generating project
GitHub issue · Open
What happened?
When a local SPM package declares a target with the .embedInCode(_:) resource rule (available since PackageDescription 5.9), Tuist fails to decode the package descriptor produced by swift package dump-package and the project generation fails.
The root cause is that PackageInfo.Target.Resource.Rule only handles process and copy. The embedInCode rule is entirely missing from the enum and its init(from:) decoder.
SPM 6.1+ serializes the rule in swift package dump-package output as a JSON object:
{
"rule": {
"embedInCode": {}
}
}
Neither the Xcode14 enum format decoder nor the single-string fallback matches this format, so the decoder throws a DecodingError.dataCorrupted with the message "Invalid content for Resource decoder".
Expected behavior: Tuist should recognize .embedInCode as a valid resource rule and map it appropriately (e.g. to .embedInCode in the generated Xcode target, or at minimum treat it as a known rule to avoid crashing).
How do we reproduce it?
- Create a local SPM package (
LocalSwiftPackage/Package.swift) with a target using.embedInCode:
// swift-tools-version: 6.1
import PackageDescription
let package = Package(
name: "LocalSwiftPackage",
products: [
.library(name: "LocalSwiftPackage", targets: ["LocalSwiftPackage"]),
],
targets: [
.target(
name: "LocalSwiftPackage",
dependencies: [],
resources: [.embedInCode("Resources")]
),
]
)
- Reference it in
Tuist/Package.swift:
// swift-tools-version: 6.0
@preconcurrency import PackageDescription
#if TUIST
import struct ProjectDescription.PackageSettings
let packageSettings = PackageSettings(productTypes: [:])
#endif
let package = Package(
name: "App",
dependencies: [
.package(path: "../LocalSwiftPackage"),
]
)
- Reference the product in
Project.swift:
import ProjectDescription
let project = Project(
name: "App",
targets: [
.target(
name: "App",
destinations: .iOS,
product: .app,
bundleId: "dev.tuist.App",
sources: ["App/Sources/**"],
dependencies: [
.external(name: "LocalSwiftPackage"),
]
),
]
)
- Run
tuist generate - Observe the decoding error
A fixture reproducing the issue has been added at examples/xcode/generated_ios_app_with_spm_embed_in_code_resources (see linked PR).
Error log
error: dataCorrupted(Swift.DecodingError.Context(
codingPath: [..., CodingKeys(stringValue: "resources"), Index 0, CodingKeys(stringValue: "rule")],
debugDescription: "Invalid content for Resource decoder",
underlyingError: nil
))
The error originates in PackageInfo.Target.Resource.Rule.init(from:) and surfaces via PackageInfoLoader when Tuist calls swift package dump-package and decodes the result.
macOS version
26.3.1
Tuist version
4.162.1
Xcode version
26.3 (17C529)
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.