`xtool dev` fails on macOS with packages using platform-conditional target dependencies (e.g. swift-crypto)

Aperta
#433 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
swift
Ambito
build-system

Direzione di ricerca

Start with Sources/PackLib/Planner.swift around the dependency walk and Sources/PackLib/Packer.swift around bundle copying; reproduce with the provided swift-crypto package using xtool dev build. Check whether platform conditions are available from swift package dump-package and how the planner uses them. Done means the app packs successfully without attempting to copy bundles for targets SwiftPM excluded.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

On macOS, xtool dev build fails at the packing step for any app that depends on swift-crypto's Crypto product. SwiftPM builds successfully, then xtool tries to copy a resource bundle that was never built:

Build complete! (22.01s)
Error: The file “swift-crypto_CryptoBoringWrapper.bundle” couldn’t be opened because there is no such file.

Steps to reproduce

Package.swift:

// swift-tools-version: 6.0
import PackageDescription

let package = Package(
    name: "repro",
    platforms: [.iOS(.v17), .macOS(.v14)],
    products: [.library(name: "repro", targets: ["repro"])],
    dependencies: [
        .package(url: "https://github.com/apple/swift-crypto", exact: "3.15.1"),
    ],
    targets: [
        .target(name: "repro", dependencies: [.product(name: "Crypto", package: "swift-crypto")]),
    ]
)

xtool.yml:

version: 1
bundleID: com.example.repro

Sources/repro/App.swift:

import Crypto
import SwiftUI

@main
struct ReproApp: App {
    var body: some Scene {
        WindowGroup { Text(SHA256.hash(data: Data()).description) }
    }
}

Then run xtool dev build.

Expected: the app is packed, containing only the bundles SwiftPM built.

Actual: the build succeeds, packing fails with the error above, and swift-crypto_Crypto.bundle is the only bundle in .build/arm64-apple-ios/debug/.

Cause

swift-crypto declares the BoringSSL targets as dependencies of Crypto only on non-Apple platforms:

.target(name: "CryptoBoringWrapper", condition: .when(platforms: platforms)),

So SwiftPM correctly doesn't build those targets or their bundles for iOS. However, swift package describe lists these dependencies without their conditions:

Crypto ['CCryptoBoringSSL', 'CCryptoBoringSSLShims', 'CryptoBoringWrapper']

Planner.swift follows that list and plans a bundle for every target with resources. Packer.swift then copies each planned bundle unconditionally, which fails for swift-crypto_CCryptoBoringSSL, swift-crypto_CCryptoBoringSSLShims, and swift-crypto_CryptoBoringWrapper.

This appears to be specific to macOS hosts, because swift-crypto declares these resources only under #if canImport(Darwin). I haven't tested on Linux.

Possible fixes

I haven't tried either of these:

  1. Have the planner evaluate platform conditions, for example from swift package dump-package, so that excluded targets are never walked. This also avoids following their dependencies.
  2. Have the packer skip planned bundles that don't exist. This is smaller, but it could hide a bundle that is genuinely missing.

Workaround

After a failed build, copy each target's PrivacyInfo.xcprivacy into the bundle path SwiftPM would have used, then rerun. This has to be repeated whenever .build is deleted.

for t in CCryptoBoringSSL CCryptoBoringSSLShims CryptoBoringWrapper; do
  d=.build/arm64-apple-ios/debug/swift-crypto_$t.bundle
  mkdir -p "$d" && cp ".build/checkouts/swift-crypto/Sources/$t/PrivacyInfo.xcprivacy" "$d/"
done

Environment

  • xtool 1.24.0
  • Xcode 26.5, Swift 6.3.2
  • macOS 26, Intel host
  • swift-crypto 3.15.1
Lingua principale
Swift
Stelle
5.5k
Fork
163
Merge medio
1g 12h
PR unite (30g)
32

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di xtool-org/xtool

Tutte le issue di xtool-org/xtool

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.