From ec280664a6a91937b7a1c5657bc239939f53cf90 Mon Sep 17 00:00:00 2001 From: Ugo Mignon <56931733+TartanLeGrand@users.noreply.github.com> Date: Mon, 12 Oct 2026 12:31:19 +0200 Subject: [PATCH 1/3] packer: compile asset catalogs with AssetKit Add an `assetCatalogs` key to xtool.yml, on the app and on each extension (one catalog per product). `Packer` compiles the catalog with AssetKit into Assets.car and merges the AppIcon CFBundleIcons / CFBundleIconName keys and loose icon files into the product. The catalog's AppIcon takes precedence over `iconPath`. `XcodePacker` does not compile anything: it adds the .xcassets to the generated project's resources phase and sets ASSETCATALOG_COMPILER_APPICON_NAME so that actool handles it. AssetKit is pinned by revision until it tags a release that includes LZFSE compression. Builds on the work in #219. Co-authored-by: Toby --- Documentation/xtool.docc/Control.md | 17 +++ Package.resolved | 26 ++++ Package.swift | 6 + Sources/PackLib/PackSchema.swift | 7 + Sources/PackLib/Packer.swift | 65 +++++++- Sources/PackLib/Planner.swift | 8 +- Sources/PackLib/XcodePacker.swift | 37 ++++- Tests/XToolTests/AssetCatalogTests.swift | 142 ++++++++++++++++++ .../AppIcon.appiconset/Contents.json | 14 ++ .../AppIcon.appiconset/icon-1024.png | Bin 0 -> 5704 bytes .../SingleSize.xcassets/Contents.json | 6 + .../AppIcon.appiconset/Contents.json | 26 ++++ .../AppIcon.appiconset/icon-1024.png | Bin 0 -> 5704 bytes .../AppIcon.appiconset/icon-60@2x.png | Bin 0 -> 264 bytes .../AppIcon.appiconset/icon-60@3x.png | Bin 0 -> 419 bytes .../Brand.colorset/Contents.json | 20 +++ .../Fixtures/Test.xcassets/Contents.json | 6 + .../Test.xcassets/Logo.imageset/Contents.json | 22 +++ .../Test.xcassets/Logo.imageset/logo.png | Bin 0 -> 83 bytes .../Test.xcassets/Logo.imageset/logo@2x.png | Bin 0 -> 102 bytes 20 files changed, 396 insertions(+), 6 deletions(-) create mode 100644 Tests/XToolTests/AssetCatalogTests.swift create mode 100644 Tests/XToolTests/Fixtures/SingleSize.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Tests/XToolTests/Fixtures/SingleSize.xcassets/AppIcon.appiconset/icon-1024.png create mode 100644 Tests/XToolTests/Fixtures/SingleSize.xcassets/Contents.json create mode 100644 Tests/XToolTests/Fixtures/Test.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Tests/XToolTests/Fixtures/Test.xcassets/AppIcon.appiconset/icon-1024.png create mode 100644 Tests/XToolTests/Fixtures/Test.xcassets/AppIcon.appiconset/icon-60@2x.png create mode 100644 Tests/XToolTests/Fixtures/Test.xcassets/AppIcon.appiconset/icon-60@3x.png create mode 100644 Tests/XToolTests/Fixtures/Test.xcassets/Brand.colorset/Contents.json create mode 100644 Tests/XToolTests/Fixtures/Test.xcassets/Contents.json create mode 100644 Tests/XToolTests/Fixtures/Test.xcassets/Logo.imageset/Contents.json create mode 100644 Tests/XToolTests/Fixtures/Test.xcassets/Logo.imageset/logo.png create mode 100644 Tests/XToolTests/Fixtures/Test.xcassets/Logo.imageset/logo@2x.png diff --git a/Documentation/xtool.docc/Control.md b/Documentation/xtool.docc/Control.md index babd0c2e..00f55b67 100644 --- a/Documentation/xtool.docc/Control.md +++ b/Documentation/xtool.docc/Control.md @@ -108,6 +108,23 @@ iconPath: Resources/AppIcon.png > > Your app icon must be a png, and it should ideally have a resolution of 1024x1024px. +## Add an asset catalog + +To use an Xcode asset catalog (`.xcassets`), which can hold images, colors and the app icon, add it to `xtool.yml`: + +```yaml +assetCatalogs: +- Resources/Assets.xcassets +``` + +xtool compiles the catalog into `Assets.car` in the app bundle, so `Image("Logo", bundle: .main)` and `Color("Brand", bundle: .main)` work as usual. If the catalog contains an `AppIcon.appiconset`, xtool also adds the matching `CFBundleIcons` and `CFBundleIconName` keys to your `Info.plist`, and ignores `iconPath`. + +Extensions can have their own catalog via an `assetCatalogs` key on the extension entry. Each app or extension supports one catalog. + +> Note: +> +> xtool compiles catalogs itself, so it works on Linux. It supports PNG, JPEG and SVG images (SVG needs `rsvg-convert` installed), colors, and app icons with per-size entries. It does not yet support single-size (1024x1024 "universal") app icons, PDF vectors, data sets, sticker packs or other specialized asset types. When you generate an Xcode project with `xtool dev generate-xcode-project`, the catalog is passed to Xcode unchanged. + ## Add entitlements You may need to add special [entitlements](https://developer.apple.com/documentation/bundleresources/entitlements) to your app, for example you need the `com.apple.developer.homekit` entitlement in order to connect to HomeKit devices. diff --git a/Package.resolved b/Package.resolved index 4cc2f508..cf4b8ede 100644 --- a/Package.resolved +++ b/Package.resolved @@ -10,6 +10,14 @@ "version" : "4.7.0" } }, + { + "identity" : "assetkit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/xtool-org/AssetKit", + "state" : { + "revision" : "e763558b55fcbb5a443b1d7b2c6f0972d8bd14f7" + } + }, { "identity" : "async-http-client", "kind" : "remoteSourceControl", @@ -37,6 +45,15 @@ "version" : "1.2.2" } }, + { + "identity" : "h", + "kind" : "remoteSourceControl", + "location" : "https://github.com/rarestype/h", + "state" : { + "revision" : "aa3626829160917d4378330617971977cbd78f5b", + "version" : "1.0.1" + } + }, { "identity" : "openapikit", "kind" : "remoteSourceControl", @@ -334,6 +351,15 @@ "version" : "1.3.1" } }, + { + "identity" : "swift-png", + "kind" : "remoteSourceControl", + "location" : "https://github.com/tayloraswift/swift-png", + "state" : { + "revision" : "8a0bcd4df5e4b307c804937776a56dd6ecdf6396", + "version" : "4.5.1" + } + }, { "identity" : "swift-service-context", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index 4a7766f7..a39cd00b 100644 --- a/Package.swift +++ b/Package.swift @@ -52,6 +52,8 @@ let package = Package( .package(url: "https://github.com/xtool-org/SwiftyMobileDevice", .upToNextMinor(from: "1.7.0")), .package(url: "https://github.com/xtool-org/zsign", .upToNextMinor(from: "1.9.0")), .package(url: "https://github.com/xtool-org/xadi", .upToNextMinor(from: "0.4.2")), + // TODO: switch to a version requirement once AssetKit tags a release with LZFSE compression (post 1.0.0). + .package(url: "https://github.com/xtool-org/AssetKit", revision: "e763558b55fcbb5a443b1d7b2c6f0972d8bd14f7"), .package(url: "https://github.com/apple/swift-system", from: "1.4.0"), .package(url: "https://github.com/apple/swift-http-types", from: "1.3.1"), @@ -167,6 +169,9 @@ let package = Package( "XToolSupport", "PackLib", ], + resources: [ + .copy("Fixtures"), + ], swiftSettings: swiftSettings, ), .target( @@ -195,6 +200,7 @@ let package = Package( dependencies: [ "XUtils", "XcodeProjects", + .product(name: "AssetKit", package: "AssetKit"), .product(name: "Superutils", package: "xtool-core"), .product(name: "Yams", package: "Yams"), .product(name: "XcodeProjectFormat", package: "xcode-project-format"), diff --git a/Sources/PackLib/PackSchema.swift b/Sources/PackLib/PackSchema.swift index 297c4241..6cddd96c 100644 --- a/Sources/PackLib/PackSchema.swift +++ b/Sources/PackLib/PackSchema.swift @@ -19,6 +19,7 @@ public struct PackSchemaBase: Codable, Sendable { public var iconPath: String? public var resources: [String]? + public var assetCatalogs: [String]? public var extensions: [Extension]? @@ -30,6 +31,7 @@ public struct PackSchemaBase: Codable, Sendable { public var bundleID: String? public var infoPath: String public var resources: [String]? + public var assetCatalogs: [String]? public var entitlementsPath: String? } } @@ -75,6 +77,11 @@ public struct PackSchema: Sendable { throw StringError("xtool.yml: iconPath should have a 'png' path extension. Got '\(ext)'.") } } + + let catalogLists = [base.assetCatalogs] + (base.extensions ?? []).map(\.assetCatalogs) + if catalogLists.contains(where: { ($0?.count ?? 0) > 1 }) { + throw StringError("xtool.yml: assetCatalogs supports at most one catalog per product.") + } } // swiftlint:disable:next force_try diff --git a/Sources/PackLib/Packer.swift b/Sources/PackLib/Packer.swift index bd2057b7..5f8d0a92 100644 --- a/Sources/PackLib/Packer.swift +++ b/Sources/PackLib/Packer.swift @@ -1,6 +1,7 @@ import Foundation import XUtils import Subprocess +import AssetKit public struct Packer: Sendable { public let buildSettings: BuildSettings @@ -100,7 +101,7 @@ public struct Packer: Sendable { try await withThrowingTaskGroup(of: Void.self) { group in for product in plan.allProducts { - try pack( + try await pack( product: product, binDir: binDir, outputURL: product.directory(inApp: outputURL), @@ -131,7 +132,7 @@ public struct Packer: Sendable { binDir: URL, outputURL: URL, _ group: inout ThrowingTaskGroup - ) throws { + ) async throws { @Sendable func packFileToRoot(srcName: String) async throws { let srcURL = URL(fileURLWithPath: srcName) let destURL = outputURL.appendingPathComponent(srcURL.lastPathComponent) @@ -152,6 +153,9 @@ public struct Packer: Sendable { // Ensure output directory is available try? FileManager.default.createDirectory(at: outputURL, withIntermediateDirectories: true) + let assets = try await Packer.compileAssets(for: product) + let iconPath = Packer.iconPath(for: product, assets: assets) + for command in product.resources { group.addTask { switch command { @@ -179,11 +183,17 @@ public struct Packer: Sendable { } } } - if let iconPath = product.iconPath { + if let iconPath { group.addTask { try await packFileToRoot(srcName: iconPath) } } + if let assets { + group.addTask { + try assets.write(into: outputURL) + try Task.checkCancellation() + } + } group.addTask { try await packFile(srcName: product.targetName, dstName: product.product) } @@ -196,7 +206,11 @@ public struct Packer: Sendable { info["CFBundleSupportedPlatforms"] = Packer.cfBundleSupportedPlatforms(for: buildSettings.triple) } - if let iconPath = product.iconPath { + if let assets { + info.merge(assets.infoPlistAdditions) { _, new in new } + } + + if let iconPath { let iconName = URL(fileURLWithPath: iconPath).deletingPathExtension().lastPathComponent info["CFBundleIconFile"] = iconName } @@ -211,6 +225,49 @@ public struct Packer: Sendable { } } + /// The output of compiling a product's asset catalog. + struct CompiledAssets: Sendable { + /// The contents of `Assets.car`. + var carData: Data + /// Copies of the app icon renditions to place next to `Assets.car`, which SpringBoard falls back to. + var looseFiles: [LooseFile] = [] + /// Keys such as `CFBundleIcons` to merge into the product's Info.plist. + var infoPlistAdditions: [String: any Sendable] = [:] + + var hasAppIcon: Bool { !infoPlistAdditions.isEmpty } + + /// Writes `Assets.car` and the loose icon files into a product's bundle directory. + func write(into directory: URL) throws { + try carData.write(to: directory.appendingPathComponent("Assets.car")) + for file in looseFiles { + try file.data.write(to: directory.appendingPathComponent(file.name)) + } + } + } + + /// The loose `iconPath` file to pack. The catalog's AppIcon takes precedence over it. + static func iconPath(for product: Plan.Product, assets: CompiledAssets?) -> String? { + guard let iconPath = product.iconPath, assets?.hasAppIcon == true else { return product.iconPath } + FileHandle.standardError.write(Data( + "warning: ignoring iconPath '\(iconPath)' because the asset catalog defines an AppIcon.\n".utf8 + )) + return nil + } + + /// Compiles the product's asset catalog, if any. + /// + /// `XcodePacker` does not use this: it hands the catalog to Xcode, where actool compiles it. + static func compileAssets(for product: Plan.Product) async throws -> CompiledAssets? { + guard let catalogPath = product.assetCatalogPath else { return nil } + let result = try await XCAssetCompiler(deploymentTarget: product.deploymentTarget) + .compile(catalog: URL(fileURLWithPath: catalogPath)) + return CompiledAssets( + carData: result.carData, + looseFiles: result.appIconBundle?.looseFiles ?? [], + infoPlistAdditions: result.appIconBundle?.infoPlistAdditions ?? [:] + ) + } + static func cfBundleSupportedPlatforms(for triple: String) -> [String] { let components = triple.split(separator: "-").map(String.init) guard let appleIndex = components.firstIndex(of: "apple"), diff --git a/Sources/PackLib/Planner.swift b/Sources/PackLib/Planner.swift index df2f0125..61b87862 100644 --- a/Sources/PackLib/Planner.swift +++ b/Sources/PackLib/Planner.swift @@ -85,6 +85,7 @@ public struct Planner: Sendable { idSpecifier: schema.idSpecifier, iconPath: schema.iconPath, rootResources: schema.resources, + assetCatalogPath: schema.assetCatalogs?.first, entitlementsPath: schema.entitlementsPath ) @@ -101,6 +102,7 @@ public struct Planner: Sendable { idSpecifier: ext.bundleID.flatMap(PackSchema.IDSpecifier.bundleID) ?? .orgID(app.bundleID), iconPath: nil, rootResources: ext.resources, + assetCatalogPath: ext.assetCatalogs?.first, entitlementsPath: ext.entitlementsPath ) } @@ -123,6 +125,7 @@ public struct Planner: Sendable { idSpecifier: PackSchema.IDSpecifier, iconPath: String?, rootResources: [String]?, + assetCatalogPath: String?, entitlementsPath: String? ) async throws -> Plan.Product { let library = try selectLibrary( @@ -214,7 +217,8 @@ public struct Planner: Sendable { infoPlist: infoPlist, resources: resources, iconPath: iconPath, - entitlementsPath: entitlementsPath + entitlementsPath: entitlementsPath, + assetCatalogPath: assetCatalogPath ) } @@ -319,6 +323,8 @@ public struct Plan: Sendable { public var resources: [Resource] public var iconPath: String? public var entitlementsPath: String? + /// Path to an `.xcassets` catalog, relative to the package root. + public var assetCatalogPath: String? public var targetName: String { "\(self.product)-\(self.type.targetSuffix)" diff --git a/Sources/PackLib/XcodePacker.swift b/Sources/PackLib/XcodePacker.swift index d679ea78..17da23e7 100644 --- a/Sources/PackLib/XcodePacker.swift +++ b/Sources/PackLib/XcodePacker.swift @@ -61,6 +61,10 @@ public struct XcodePacker { "$(inherited)", "@executable_path/Frameworks", "@executable_path/../../Frameworks", ]) } + if let catalogPath = product.assetCatalogPath, + let iconName = Self.appIconName(inCatalogAt: URL(fileURLWithPath: catalogPath, relativeTo: root)) { + buildSettings["ASSETCATALOG_COMPILER_APPICON_NAME"] = .string(iconName) + } if let entitlementsPath = product.entitlementsPath { let path = (entitlementsPath as NSString).isAbsolutePath ? entitlementsPath @@ -97,12 +101,14 @@ public struct XcodePacker { buildFiles: [], ) let resources = try resourceReferences(for: product, at: root) + // the catalog is passed through untouched: actool compiles it as part of the Xcode build. + let catalog = try product.assetCatalogPath.map { try assetCatalogReference($0, for: product) } groups.append(.group(.init( objectID: nil, name: product.product, path: try .init(base: .group, path: product.product), includeInIndex: nil, - children: [.fileReference(source), .fileReference(info)] + resources, + children: [.fileReference(source), .fileReference(info)] + resources + (catalog.map { [$0] } ?? []), ))) let productFilename = "\(product.targetName).\(product.type == .application ? "app" : "appex")" @@ -141,6 +147,9 @@ public struct XcodePacker { ), ) var phases = [sourcePhase, frameworksPhase] + if catalog != nil { + phases.append(.resources(.init(objectID: nil, name: nil))) + } if !resources.isEmpty { phases.append(.copy(.init( objectID: nil, @@ -272,6 +281,32 @@ public struct XcodePacker { } } + private func assetCatalogReference(_ path: String, for product: Plan.Product) throws -> XCSchema.Reference { + let isAbsolute = (path as NSString).isAbsolutePath + let referencePath = isAbsolute ? path : ("../.." as NSString).appendingPathComponent(path) + return .fileReference(.init( + objectID: nil, + path: try .init(base: isAbsolute ? .absolute : .project, path: referencePath), + explicitFileType: .init(fileTypeID: "folder.assetcatalog"), + expectedSignature: nil, + textEncoding: nil, + lineEnding: nil, + includeInIndex: nil, + buildFiles: [.init( + objectID: nil, + buildPhase: .named(target: .init(targetName: product.targetName), kind: .resources, name: nil), + properties: buildFileProperties(), + )], + )) + } + + /// The basename of the `.appiconset` in the catalog, which Xcode needs as `ASSETCATALOG_COMPILER_APPICON_NAME`. + static func appIconName(inCatalogAt catalog: URL) -> String? { + let contents = (try? FileManager.default.contentsOfDirectory(atPath: catalog.path)) ?? [] + return contents.sorted().first { $0.hasSuffix(".appiconset") } + .map { ($0 as NSString).deletingPathExtension } + } + private func buildFileProperties(removeHeadersOnCopy: Bool = false) -> XCSchema.BuildFileProperties { XCSchema.BuildFileProperties( platformFilters: [], diff --git a/Tests/XToolTests/AssetCatalogTests.swift b/Tests/XToolTests/AssetCatalogTests.swift new file mode 100644 index 00000000..a0bf8b39 --- /dev/null +++ b/Tests/XToolTests/AssetCatalogTests.swift @@ -0,0 +1,142 @@ +import Foundation +import Testing +@testable import PackLib + +private let fixtures = Bundle.module.url(forResource: "Fixtures", withExtension: nil)! +private let fixtureCatalog = fixtures.appendingPathComponent("Test.xcassets") + +private func product( + type: Plan.ProductType = .application, + catalog: URL? = fixtureCatalog, + iconPath: String? = nil +) -> Plan.Product { + Plan.Product( + type: type, + product: "Demo", + deploymentTarget: "17.0", + bundleID: "com.example.Demo", + infoPlist: [:], + resources: [], + iconPath: iconPath, + entitlementsPath: nil, + assetCatalogPath: catalog?.path + ) +} + +@Test func compileAssetsProducesCarAndIconPlist() async throws { + let assets = try #require(try await Packer.compileAssets(for: product())) + + // Assets.car is a BOM store, and the facet names are stored in clear. + #expect(assets.carData.prefix(8) == Data("BOMStore".utf8)) + for name in ["AppIcon", "Logo", "Brand"] { + #expect(assets.carData.contains(Data(name.utf8)), "missing facet \(name)") + } + + #expect(assets.hasAppIcon) + #expect(assets.infoPlistAdditions["CFBundleIconName"] as? String == "AppIcon") + let icons = try #require(assets.infoPlistAdditions["CFBundleIcons"] as? [String: any Sendable]) + #expect(icons["CFBundleIconName"] as? String == "AppIcon") +} + +// Xcode 14+ defaults to a single 1024x1024 "universal" icon with no scale. AssetKit does not handle +// that format yet, so this is expected to fail until it does; `withKnownIssue` will flag when it starts to pass. +@Test func compileAssetsSingleSizeAppIcon() async throws { + let catalog = fixtures.appendingPathComponent("SingleSize.xcassets") + await withKnownIssue("AssetKit rejects single-size universal app icons") { + let assets = try #require(try await Packer.compileAssets(for: product(catalog: catalog))) + #expect(assets.hasAppIcon) + } +} + +@Test func catalogAppIconOverridesIconPath() async throws { + let withIcon = product(iconPath: "Icon.png") + let assets = try await Packer.compileAssets(for: withIcon) + #expect(Packer.iconPath(for: withIcon, assets: assets) == nil) + #expect(Packer.iconPath(for: withIcon, assets: nil) == "Icon.png") +} + +@Test func compiledAssetsAreWrittenIntoTheBundle() async throws { + let dir = FileManager.default.temporaryDirectory.appendingPathComponent("xtool-test-\(UUID().uuidString)") + try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true) + defer { try? FileManager.default.removeItem(at: dir) } + + let assets = try #require(try await Packer.compileAssets(for: product())) + try assets.write(into: dir) + #expect(try Data(contentsOf: dir.appendingPathComponent("Assets.car")) == assets.carData) + #expect(!assets.looseFiles.isEmpty) + for file in assets.looseFiles { + #expect(FileManager.default.fileExists(atPath: dir.appendingPathComponent(file.name).path)) + } +} + +@Test func compileAssetsIsNilWithoutCatalog() async throws { + #expect(try await Packer.compileAssets(for: product(catalog: nil)) == nil) +} + +@Test func compileAssetsFailsOnMissingCatalog() async { + let missing = fixtureCatalog.deletingLastPathComponent().appendingPathComponent("Missing.xcassets") + await #expect(throws: (any Error).self) { + _ = try await Packer.compileAssets(for: product(catalog: missing)) + } +} + +@Test func compiledCatalogIsDeterministic() async throws { + let first = try #require(try await Packer.compileAssets(for: product())) + let second = try #require(try await Packer.compileAssets(for: product())) + #expect(first.carData == second.carData) +} + +@Test func schemaAcceptsAssetCatalogsOnAppAndExtensions() async throws { + let yaml = """ + version: 1 + orgID: com.example + assetCatalogs: [Assets.xcassets] + extensions: + - product: Widget + infoPath: Widget.plist + assetCatalogs: [Widget/Assets.xcassets] + """ + let file = FileManager.default.temporaryDirectory.appendingPathComponent("xtool-\(UUID().uuidString).yml") + try Data(yaml.utf8).write(to: file) + defer { try? FileManager.default.removeItem(at: file) } + let schema = try await PackSchema(url: file) + #expect(schema.assetCatalogs == ["Assets.xcassets"]) + #expect(schema.extensions?.first?.assetCatalogs == ["Widget/Assets.xcassets"]) +} + +@Test func schemaRejectsMultipleCatalogsPerProduct() throws { + let app = PackSchemaBase(version: .v1, orgID: "com.example", assetCatalogs: ["A.xcassets", "B.xcassets"]) + #expect(throws: (any Error).self) { try PackSchema(validating: app) } + + let ext = PackSchemaBase.Extension( + product: "Widget", + infoPath: "Widget.plist", + assetCatalogs: ["A.xcassets", "B.xcassets"] + ) + let withExt = PackSchemaBase(version: .v1, orgID: "com.example", extensions: [ext]) + #expect(throws: (any Error).self) { try PackSchema(validating: withExt) } +} + +@Test func xcodePackerFindsAppIconName() { + #expect(XcodePacker.appIconName(inCatalogAt: fixtureCatalog) == "AppIcon") + #expect(XcodePacker.appIconName(inCatalogAt: fixtureCatalog.appendingPathComponent("Logo.imageset")) == nil) +} + +@Test func xcodePackerPassesCatalogThroughUncompiled() async throws { + let root = FileManager.default.temporaryDirectory.appendingPathComponent("xtool-test-\(UUID().uuidString)") + try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true) + defer { try? FileManager.default.removeItem(at: root) } + + let app = product(catalog: URL(fileURLWithPath: "Assets.xcassets")) + let plan = Plan(app: app, extensions: []) + let workspace = try await XcodePacker(plan: plan).createProject(at: root) + #expect(workspace.pathExtension == "xcworkspace") + + let pbxproj = try String( + contentsOf: root.appendingPathComponent("xtool/.xtool-tmp/Demo.xcodeproj/project.pbxproj"), + encoding: .utf8 + ) + #expect(pbxproj.contains("folder.assetcatalog")) + #expect(pbxproj.contains("Assets.xcassets")) + #expect(pbxproj.contains("PBXResourcesBuildPhase")) +} diff --git a/Tests/XToolTests/Fixtures/SingleSize.xcassets/AppIcon.appiconset/Contents.json b/Tests/XToolTests/Fixtures/SingleSize.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..d90c80b6 --- /dev/null +++ b/Tests/XToolTests/Fixtures/SingleSize.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,14 @@ +{ + "images": [ + { + "filename": "icon-1024.png", + "idiom": "universal", + "platform": "ios", + "size": "1024x1024" + } + ], + "info": { + "author": "xcode", + "version": 1 + } +} diff --git a/Tests/XToolTests/Fixtures/SingleSize.xcassets/AppIcon.appiconset/icon-1024.png b/Tests/XToolTests/Fixtures/SingleSize.xcassets/AppIcon.appiconset/icon-1024.png new file mode 100644 index 0000000000000000000000000000000000000000..ee0850b75764bfd1b813df889cb05461d7dcf034 GIT binary patch literal 5704 zcmeAS@N?(olHy`uVBq!ia0y~yU;#2&7&zE~RK2WrGXsMdzo(01NX4zUHw<|h7&s0X z2>rSJl!a$O!hj8VYEU(PbEAIioozY018CH z)g!oI7z7bHn%U8#5gaLlAr?oI2q-6E#01v(LTZE{F){Swsg6m@i-V`>H(DW}r4j>% z7LdrGNG3pc8~{0Hv_2rYRE31wAc#ehT~1m_0!$nbui`12kQC6$a1sJ~&@>rF#{w{u z4)Y-DAus{cHgTyMlE6twgGf1oAd{3VGn(0fafVrW4uV*OMDu780YwiaEWnXMO5!Fi b79VVS_u$z6{rSJl!a$O!hj8VYEU(PbEAIioozY018CH z)g!oI7z7bHn%U8#5gaLlAr?oI2q-6E#01v(LTZE{F){Swsg6m@i-V`>H(DW}r4j>% z7LdrGNG3pc8~{0Hv_2rYRE31wAc#ehT~1m_0!$nbui`12kQC6$a1sJ~&@>rF#{w{u z4)Y-DAus{cHgTyMlE6twgGf1oAd{3VGn(0fafVrW4uV*OMDu780YwiaEWnXMO5!Fi b79VVS_u$z6{J zm8GV}YEEPJ*EgEmjTkpDa6^zm0;3od9bnRdA)bf^RtS>7rjn5jt4dCoricbcsPP*Z tm|?~P?SUDua{!x4Zme!;@b!4d=yZL$we1PU9H7@2JYD@<);T3K0RZtgMXUe- literal 0 HcmV?d00001 diff --git a/Tests/XToolTests/Fixtures/Test.xcassets/AppIcon.appiconset/icon-60@3x.png b/Tests/XToolTests/Fixtures/Test.xcassets/AppIcon.appiconset/icon-60@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..c3676d5c94d391476980ae30e8a95c71a9183fe7 GIT binary patch literal 419 zcmeAS@N?(olHy`uVBq!ia0vp^TR@nD4M^IaWiw)6V9fG#aSW-r_4bk>F9QR|0Ry2w zx1X}u6ikvc-Jr9n>Or>vqjU4ZgBKDqczD~`z)T4#DAUjc%1q8MfH02%)q$D4U@agf zOt&rzCE5*4sG~cIg$%dDEr$mJDL#klewfF&h4qT}l%M|_fPv58>FVdQ&MBb@0IC~_ AfB*mh literal 0 HcmV?d00001 diff --git a/Tests/XToolTests/Fixtures/Test.xcassets/Brand.colorset/Contents.json b/Tests/XToolTests/Fixtures/Test.xcassets/Brand.colorset/Contents.json new file mode 100644 index 00000000..fd3f197d --- /dev/null +++ b/Tests/XToolTests/Fixtures/Test.xcassets/Brand.colorset/Contents.json @@ -0,0 +1,20 @@ +{ + "colors": [ + { + "color": { + "color-space": "srgb", + "components": { + "red": "0.012", + "green": "0.965", + "blue": "0.996", + "alpha": "1.000" + } + }, + "idiom": "universal" + } + ], + "info": { + "author": "xcode", + "version": 1 + } +} diff --git a/Tests/XToolTests/Fixtures/Test.xcassets/Contents.json b/Tests/XToolTests/Fixtures/Test.xcassets/Contents.json new file mode 100644 index 00000000..74d6a722 --- /dev/null +++ b/Tests/XToolTests/Fixtures/Test.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info": { + "author": "xcode", + "version": 1 + } +} diff --git a/Tests/XToolTests/Fixtures/Test.xcassets/Logo.imageset/Contents.json b/Tests/XToolTests/Fixtures/Test.xcassets/Logo.imageset/Contents.json new file mode 100644 index 00000000..6e053973 --- /dev/null +++ b/Tests/XToolTests/Fixtures/Test.xcassets/Logo.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images": [ + { + "filename": "logo.png", + "idiom": "universal", + "scale": "1x" + }, + { + "filename": "logo@2x.png", + "idiom": "universal", + "scale": "2x" + }, + { + "idiom": "universal", + "scale": "3x" + } + ], + "info": { + "author": "xcode", + "version": 1 + } +} diff --git a/Tests/XToolTests/Fixtures/Test.xcassets/Logo.imageset/logo.png b/Tests/XToolTests/Fixtures/Test.xcassets/Logo.imageset/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..ff6f7b516c4bc290199236c5b34890b30785015c GIT binary patch literal 83 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ql2i3Ar-fhBhG&KZ?8Hd@k&D= fvm3939#F~ru9fmxa$z@tsu(<7{an^LB{Ts54UiSV literal 0 HcmV?d00001 diff --git a/Tests/XToolTests/Fixtures/Test.xcassets/Logo.imageset/logo@2x.png b/Tests/XToolTests/Fixtures/Test.xcassets/Logo.imageset/logo@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..8c4860e3bc18c9ef2765ef2ee4474e496d335f68 GIT binary patch literal 102 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzT~8OskcwMx&nYr8Fz_%L{0gu1 mkYhGB+#hpmDF-T8!_1$^x@7v^gmuk8jSQZyelF{r5}E)$S{I7| literal 0 HcmV?d00001 From 2efdaefa38dc0eb50973aac6985e60eabdbfd17b Mon Sep 17 00:00:00 2001 From: Ugo Mignon <56931733+TartanLeGrand@users.noreply.github.com> Date: Mon, 12 Oct 2026 12:31:19 +0200 Subject: [PATCH 2/3] assets: support single-size app icons Bump AssetKit to a revision that expands the Xcode 14+ single 1024x1024 universal app icon, and cover it with a test instead of a known issue. The AssetKit revision is on a branch that is not merged yet: repin it to a released version once AssetKit tags one. --- Documentation/xtool.docc/Control.md | 2 +- Package.resolved | 2 +- Package.swift | 4 ++-- Tests/XToolTests/AssetCatalogTests.swift | 11 +++++------ 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Documentation/xtool.docc/Control.md b/Documentation/xtool.docc/Control.md index 00f55b67..7e7fbf28 100644 --- a/Documentation/xtool.docc/Control.md +++ b/Documentation/xtool.docc/Control.md @@ -123,7 +123,7 @@ Extensions can have their own catalog via an `assetCatalogs` key on the extensio > Note: > -> xtool compiles catalogs itself, so it works on Linux. It supports PNG, JPEG and SVG images (SVG needs `rsvg-convert` installed), colors, and app icons with per-size entries. It does not yet support single-size (1024x1024 "universal") app icons, PDF vectors, data sets, sticker packs or other specialized asset types. When you generate an Xcode project with `xtool dev generate-xcode-project`, the catalog is passed to Xcode unchanged. +> xtool compiles catalogs itself, so it works on Linux. It supports PNG, JPEG and SVG images (SVG needs `rsvg-convert` installed), colors, and app icons with per-size entries. Single-size (1024x1024 "universal") app icons are supported, but their dark and tinted variants are ignored. PDF vectors, data sets, sticker packs and other specialized asset types are not supported. When you generate an Xcode project with `xtool dev generate-xcode-project`, the catalog is passed to Xcode unchanged. ## Add entitlements diff --git a/Package.resolved b/Package.resolved index cf4b8ede..b5549399 100644 --- a/Package.resolved +++ b/Package.resolved @@ -15,7 +15,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/xtool-org/AssetKit", "state" : { - "revision" : "e763558b55fcbb5a443b1d7b2c6f0972d8bd14f7" + "revision" : "1336918b969a44b0bb3596cb0ff45908f755d6d7" } }, { diff --git a/Package.swift b/Package.swift index a39cd00b..11e21371 100644 --- a/Package.swift +++ b/Package.swift @@ -52,8 +52,8 @@ let package = Package( .package(url: "https://github.com/xtool-org/SwiftyMobileDevice", .upToNextMinor(from: "1.7.0")), .package(url: "https://github.com/xtool-org/zsign", .upToNextMinor(from: "1.9.0")), .package(url: "https://github.com/xtool-org/xadi", .upToNextMinor(from: "0.4.2")), - // TODO: switch to a version requirement once AssetKit tags a release with LZFSE compression (post 1.0.0). - .package(url: "https://github.com/xtool-org/AssetKit", revision: "e763558b55fcbb5a443b1d7b2c6f0972d8bd14f7"), + // TODO: use a version requirement once AssetKit tags a release with LZFSE and single-size app icons. + .package(url: "https://github.com/xtool-org/AssetKit", revision: "1336918b969a44b0bb3596cb0ff45908f755d6d7"), .package(url: "https://github.com/apple/swift-system", from: "1.4.0"), .package(url: "https://github.com/apple/swift-http-types", from: "1.3.1"), diff --git a/Tests/XToolTests/AssetCatalogTests.swift b/Tests/XToolTests/AssetCatalogTests.swift index a0bf8b39..6ef5eb4b 100644 --- a/Tests/XToolTests/AssetCatalogTests.swift +++ b/Tests/XToolTests/AssetCatalogTests.swift @@ -38,14 +38,13 @@ private func product( #expect(icons["CFBundleIconName"] as? String == "AppIcon") } -// Xcode 14+ defaults to a single 1024x1024 "universal" icon with no scale. AssetKit does not handle -// that format yet, so this is expected to fail until it does; `withKnownIssue` will flag when it starts to pass. +// Xcode 14+ defaults to a single 1024x1024 "universal" icon with no scale. @Test func compileAssetsSingleSizeAppIcon() async throws { let catalog = fixtures.appendingPathComponent("SingleSize.xcassets") - await withKnownIssue("AssetKit rejects single-size universal app icons") { - let assets = try #require(try await Packer.compileAssets(for: product(catalog: catalog))) - #expect(assets.hasAppIcon) - } + let assets = try #require(try await Packer.compileAssets(for: product(catalog: catalog))) + #expect(assets.hasAppIcon) + #expect(assets.infoPlistAdditions["CFBundleIconName"] as? String == "AppIcon") + #expect(assets.looseFiles.contains { $0.name == "AppIcon60x60@2x.png" }) } @Test func catalogAppIconOverridesIconPath() async throws { From c1e7683b1acfa644be92608536b87d4d4004345b Mon Sep 17 00:00:00 2001 From: Ugo Mignon <56931733+TartanLeGrand@users.noreply.github.com> Date: Mon, 12 Oct 2026 13:41:06 +0200 Subject: [PATCH 3/3] deps: use AssetKit with single-size app icons (temporary) The previous pin named a revision that only existed locally. Point at the branch of xtool-org/AssetKit#2 until AssetKit tags a release. --- Package.resolved | 4 ++-- Package.swift | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Package.resolved b/Package.resolved index b5549399..52aa06cc 100644 --- a/Package.resolved +++ b/Package.resolved @@ -13,9 +13,9 @@ { "identity" : "assetkit", "kind" : "remoteSourceControl", - "location" : "https://github.com/xtool-org/AssetKit", + "location" : "https://github.com/TartanLeGrand/AssetKit", "state" : { - "revision" : "1336918b969a44b0bb3596cb0ff45908f755d6d7" + "revision" : "90281d6dc0c4edef6176f9283283271198e4bafd" } }, { diff --git a/Package.swift b/Package.swift index 11e21371..d7d453ed 100644 --- a/Package.swift +++ b/Package.swift @@ -52,8 +52,9 @@ let package = Package( .package(url: "https://github.com/xtool-org/SwiftyMobileDevice", .upToNextMinor(from: "1.7.0")), .package(url: "https://github.com/xtool-org/zsign", .upToNextMinor(from: "1.9.0")), .package(url: "https://github.com/xtool-org/xadi", .upToNextMinor(from: "0.4.2")), - // TODO: use a version requirement once AssetKit tags a release with LZFSE and single-size app icons. - .package(url: "https://github.com/xtool-org/AssetKit", revision: "1336918b969a44b0bb3596cb0ff45908f755d6d7"), + // TODO: temporary, points at the branch of xtool-org/AssetKit#2. Switch to + // .upToNextMinor(from: "") once AssetKit tags a release including it. + .package(url: "https://github.com/TartanLeGrand/AssetKit", revision: "90281d6dc0c4edef6176f9283283271198e4bafd"), .package(url: "https://github.com/apple/swift-system", from: "1.4.0"), .package(url: "https://github.com/apple/swift-http-types", from: "1.3.1"),