Share
Embed
Transcript
93 slides
-
はじめに •App Intentsフレームワーク import AppIntents struct SomeIntent: AppIntent { static
let title: LocalizedStringResource = "Some Intent" static let description = IntentDescription("A plain demo intent.") } func perform() async throws -> some IntentResult { // do something return .result() } -
はじめに •ビルドするだけでシステムが認識 import AppIntents struct SomeIntent: AppIntent { static let
title: LocalizedStringResource = "Some Intent" static let description = IntentDescription("A plain demo intent.") } func perform() async throws -> some IntentResult { // do something return .result() } -
はじめに •ビルドするだけでシステムが認識 import AppIntents struct SomeIntent: AppIntent { static let
title: LocalizedStringResource = "Some Intent" static let description = IntentDescription("A plain demo intent.") } func perform() async throws -> some IntentResult { // do something return .result() } 静的解析でメタデータを生成しアプリに同封 -
ビルドプロセス概要 .xcodeproj Xcode Project管理 Swift Build ビルド計画 llbuild 計画の実行 swiftc
コンパイル等 *.swift その他ツール -
ビルドプロセス概要: App Intents .xcodeproj .app Xcode exec *.swift Info.plist Swift
Build llbuild その他ツール swiftc -
ビルドプロセス概要: App Intents .xcodeproj .app Xcode exec *.swift Info.plist Swift
Build llbuild appintentsmetadataprocessor swiftc -
ビルドプロセス概要: App Intents .xcodeproj .app Xcode exec *.swift Info.plist Swift
Build Metadata.appintents appintentsmetadataprocessor llbuild swiftc -
ビルドプロセス概要: App Intents .xcodeproj .app Xcode exec *.swift Info.plist Swift
Build Metadata.appintents appintentsmetadataprocessor .swiftconstvalues llbuild swiftc -
ビルドプロセス概要: App Intents .xcodeproj .app Xcode exec *.swift Info.plist Swift
Build llbuild appintentsmetadataprocessor swiftc Metadata.appintents -
ビルドプロセス概要: App Intents デバイス .app exec Siri Info.plist Metadata.appintents ショートカット
ランタイムでアプリが持つApp Intentを認識 -
ビルドプロセス概要: App Intents .xcodeproj .app Xcode exec *.swift Info.plist Swift
Build Metadata.appintents appintentsmetadataprocessor .swiftconstvalues llbuild swiftc Metadata.appintents -
swiftc Const Extract .xcodeproj .app Xcode exec *.swift Info.plist Swift
Build Metadata.appintents appintentsmetadataprocessor .swiftconstvalues llbuild swiftc Metadata.appintents -
swiftc Const Extract •コードから型情報を抽出する仕組み swiftc -c Source.swift \ -Xfrontend -emit-const-values-path
-Xfrontend X.swiftconstvalues \ -Xfrontend -const-gather-protocols-file -Xfrontend protocols.json -
swiftc Const Extract •コードから型情報を抽出する仕組み swiftc -c Source.swift \ -Xfrontend -emit-const-values-path
-Xfrontend X.swiftconstvalues \ -Xfrontend -const-gather-protocols-file -Xfrontend protocols.json Const Extractを実行するオプション -
swiftc Const Extract •コードから型情報を抽出する仕組み swiftc -c Source.swift \ -Xfrontend -emit-const-values-path
-Xfrontend X.swiftconstvalues \ -Xfrontend -const-gather-protocols-file -Xfrontend protocols.json Const Extractの対象となるprotocol -
swiftc Const Extract swiftc -c Source.swift \ -Xfrontend -emit-const-values-path -Xfrontend
X.swiftconstvalues \ -Xfrontend -const-gather-protocols-file -Xfrontend protocols.json Source.swift protocol SomeProtocol {} struct SomeType: SomeProtocol { let title = "Hello World" let isEnabled = true } protocols.json ["SomeProtocol"] -
"properties": [ { "label": "title", "type": "Swift.String", "mangledTypeName": "n/a -
deprecated" "isStatic": "false", [ "isComputed": "false", { "file": "Source.swift", "typeName": "Source.SomeType", "line": 4, "mangledTypeName": "6Source8SomeTypeV", "valueKind": "RawLiteral", "kind": "struct", "value": "Hello World" "file": "Source.swift", }, "line": 3, { "conformances": [ "label": "isEnabled", "Source.SomeProtocol", "type": "Swift.Bool", "Swift.Sendable" "mangledTypeName": "n/a - deprecated" ], "isStatic": "false", "allConformances": [ "isComputed": "false", { "file": "Source.swift", "protocolName": "Source.SomeProtocol", "line": 5, "conformanceDefiningModule": "Source" "valueKind": "RawLiteral", }, "value": "true" { } "protocolName": "Swift.Sendable", "conformanceDefiningModule": "Source" … } swiftc Const Extract -
swiftc Const Extract Source.swift protocol SomeProtocol {} struct SomeType: SomeProtocol
{ let title = "Hello World" let isEnabled = true } Source.swiftconstvalues [ { "typeName": "Source.SomeType", "mangledTypeName": "6Source8SomeTypeV", "kind": "struct", "file": "Source.swift", "line": 3, "conformances": [ "Source.SomeProtocol", "Swift.Sendable" ], "properties": [ { "label": "title", "type": "Swift.String", "mangledTypeName": "n/a - deprecated" "isStatic": "false", "isComputed": "false", "file": "Source.swift", "line": 4, "valueKind": "RawLiteral", "value": "Hello World" }, { "label": "isEnabled", "type": "Swift.Bool", "mangledTypeName": "n/a - deprecated" "isStatic": "false", "isComputed": "false", "file": "Source.swift", "line": 5, "valueKind": "RawLiteral", "value": "true" } … -
swiftc Const Extract Source.swift protocol SomeProtocol {} struct SomeType: SomeProtocol
{ let title = "Hello World" let isEnabled = true } Source.swiftconstvalues [ { "typeName": "Source.SomeType", "mangledTypeName": "6Source8SomeTypeV", "kind": "struct", "file": "Source.swift", "line": 3, "conformances": [ "Source.SomeProtocol", "Swift.Sendable" ], "properties": [ { "label": "title", "type": "Swift.String", "mangledTypeName": "n/a - deprecated" "isStatic": "false", "isComputed": "false", "file": "Source.swift", "line": 4, "valueKind": "RawLiteral", "value": "Hello World" }, { "label": "isEnabled", "type": "Swift.Bool", "mangledTypeName": "n/a - deprecated" "isStatic": "false", "isComputed": "false", "file": "Source.swift", "line": 5, "valueKind": "RawLiteral", "value": "true" } … -
swiftc Const Extract Source.swift protocol SomeProtocol {} struct SomeType: SomeProtocol
{ let title = "Hello World" let isEnabled = true } Source.swiftconstvalues [ { "typeName": "Source.SomeType", "mangledTypeName": "6Source8SomeTypeV", "kind": "struct", "file": "Source.swift", "line": 3, "conformances": [ "Source.SomeProtocol", "Swift.Sendable" ], "properties": [ { "label": "title", "type": "Swift.String", "mangledTypeName": "n/a - deprecated" "isStatic": "false", "isComputed": "false", "file": "Source.swift", "line": 4, "valueKind": "RawLiteral", "value": "Hello World" }, { "label": "isEnabled", "type": "Swift.Bool", "mangledTypeName": "n/a - deprecated" "isStatic": "false", "isComputed": "false", "file": "Source.swift", "line": 5, "valueKind": "RawLiteral", "value": "true" } … -
swiftc Const Extract: App Intents •ビルドするだけでシステムが認識 import AppIntents struct SomeIntent:
AppIntent { static let title: LocalizedStringResource = "Some Intent" static let description = IntentDescription("A plain demo intent.") } func perform() async throws -> some IntentResult { // do something return .result() } -
swiftc Const Extract: 初期値抽出の制約 •初期値は即値のみ抽出可能 struct SomeIntent: AppIntent { //
🔴 Unsupported value for interpolated string segment: memberReference(baseType: "L10n.AppIntent", memberLabel: "title") static let title: LocalizedStringResource = “\(L10n.AppIntent.title)" // 🔴 The property 'description' must be static, have a compile-time constant value and cannot be computed or dynamic static var description: IntentDescription { let result = IntentDescription("A plain demo intent.") // do something } } return result -
swiftc Const Extract: 初期値抽出の制約 Source.swiftconstvalues •初期値は即値のみ抽出可能 Source.swift let anotherTitle =
"title" struct SomeType: SomeProtocol { let title1: String = anotherTitle var title2: String { let title = "title" } } return title "properties": [ { "label": "title1", "type": "Swift.String", "mangledTypeName": "n/a "isStatic": "false", "isComputed": "false", "file": "Source.swift", "line": 5, "valueKind": "Runtime" }, { "label": "title2", "type": "Swift.String", "mangledTypeName": "n/a "isStatic": "false", "isComputed": "true", "file": "Source.swift", "line": 7, "valueKind": "Runtime" } -
swiftc Const Extract: 初期値抽出の制約 •初期値は即値のみ抽出可能 struct SomeIntent: AppIntent { //
🔴 Unsupported value for interpolated string segment: memberReference(baseType: "L10n.AppIntent", memberLabel: "title") static let title: LocalizedStringResource = “\(L10n.AppIntent.title)" // 🔴 The property 'description' must be static, have a compile-time constant value and cannot be computed or dynamic static var description: IntentDescription { let result = IntentDescription("A plain demo intent.") // do something } } return result -
ビルドプロセス概要: 主要なツール .xcodeproj .app Xcode exec *.swift Info.plist Swift Build
Metadata.appintents appintentsmetadataprocessor .swiftconstvalues llbuild swiftc Metadata.appintents -
専用ツールによるメタデータの出力 xcrun appintentsmetadataprocessor \ --toolchain-dir ... \ --module-name ... \
--sdk-root ... \ --xcode-version ... \ --platform-family ... \ --deployment-target ... \ --bundle-identifier ... \ --output ... \ --target-triple ... \ --binary-file ... \ --dependency-file ... \ --stringsdata-file ... \ --source-file-list SwiftFileList \ --metadata-file-list DependencyMetadataFileList \ --static-metadata-file-list DependencyStaticMetadataFileList \ --swift-const-vals-list SwiftConstValuesFileList \ --compile-time-extraction \ --deployment-aware-processing \ --no-app-shortcuts-localization -
専用ツールによるメタデータの出力 xcrun appintentsmetadataprocessor \ --toolchain-dir ... \ --module-name ... \
--sdk-root ... \ --xcode-version ... \ --platform-family ... \ --deployment-target ... \ --bundle-identifier ... \ --output ... \ --target-triple ... \ --binary-file ... \ --dependency-file ... \ --stringsdata-file ... \ --source-file-list SwiftFileList \ --metadata-file-list DependencyMetadataFileList \ --static-metadata-file-list DependencyStaticMetadataFileList \ --swift-const-vals-list SwiftConstValuesFileList \ --compile-time-extraction \ --deployment-aware-processing \ --no-app-shortcuts-localization swiftconstvalues(のパスを羅列したファイル) -
メタデータの形式: extract.actionsdata { } "actions": {}, "assistantEntities": [], "assistantIntentNegativePhrases": [],
"assistantIntents": [], "autoShortcuts": [], "entities": {}, "enums": [], "negativePhrases": [], "queries": {}, "shortcutTileColor": 14, "version": 1 -
メタデータの形式: extract.actionsdata import AppIntents struct SomeIntent: AppIntent { static let
title: LocalizedStringResource = "Some Intent" static let description = IntentDescription("A plain demo intent.") } func perform() async throws -> some IntentResult { // do something return .result() } -
メタデータの形式: extract.actionsdata { "actions": { "SomeIntent": { "assistantDefinedSchemaTraits": [], "assistantDefinedSchemas":
[], "authenticationPolicy": 0, "availabilityAnnotations": { "LNPlatformNameWildcard": { "introducedVersion": "*" } }, "descriptionMetadata": { "descriptionText": { "alternatives": [], "key": "A plain demo intent." }, "searchKeywords": [] }, "effectiveBundleIdentifiers": [], "fullyQualifiedTypeName": "MyApp.SomeIntent", "identifier": "SomeIntent", "isAuthPolExplicit": false, "isDiscoverable": true, "mangledTypeName": "5MyApp10SomeIntentV", "mangledTypeNameByBundleIdentifier": {}, }, "mangledTypeNameByBundleIdentifierV2": {}, "mangledTypeNameV2": "5MyApp10SomeIntentV", "openAppWhenRun": false, "outputFlags": 0, "parameters": [], "presentationStyle": 0, "requiredCapabilities": [], "supportedModes": 1, "systemProtocolMetadata": [], "systemProtocolMetadataV2": [], "systemProtocols": [], "title": { "alternatives": [], "key": "Some Intent" }, "typeSpecificMetadata": [], "visibilityMetadata": { "assistantOnly": false, "isDiscoverable": true } } -
メタデータの形式: extract.actionsdata { "actions": { "SomeIntent": { "assistantDefinedSchemaTraits": [], "assistantDefinedSchemas":
[], "authenticationPolicy": 0, "availabilityAnnotations": { "LNPlatformNameWildcard": { "introducedVersion": "*" } }, "descriptionMetadata": { "descriptionText": { "alternatives": [], "key": "A plain demo intent." }, "searchKeywords": [] }, "effectiveBundleIdentifiers": [], "fullyQualifiedTypeName": "MyApp.SomeIntent", "identifier": "SomeIntent", "isAuthPolExplicit": false, "isDiscoverable": true, "mangledTypeName": "5MyApp10SomeIntentV", "mangledTypeNameByBundleIdentifier": {}, }, "mangledTypeNameByBundleIdentifierV2": {}, "mangledTypeNameV2": "5MyApp10SomeIntentV", "openAppWhenRun": false, "outputFlags": 0, "parameters": [], "presentationStyle": 0, "requiredCapabilities": [], "supportedModes": 1, "systemProtocolMetadata": [], "systemProtocolMetadataV2": [], "systemProtocols": [], "title": { "alternatives": [], "key": "Some Intent" }, "typeSpecificMetadata": [], "visibilityMetadata": { "assistantOnly": false, "isDiscoverable": true } } -
メタデータの形式: extract.actionsdata { "actions": { "SomeIntent": { "assistantDefinedSchemaTraits": [], "assistantDefinedSchemas":
[], "authenticationPolicy": 0, "availabilityAnnotations": { "LNPlatformNameWildcard": { "introducedVersion": "*" } }, "descriptionMetadata": { "descriptionText": { "alternatives": [], "key": "A plain demo intent." }, "searchKeywords": [] }, "effectiveBundleIdentifiers": [], "fullyQualifiedTypeName": "MyApp.SomeIntent", "identifier": "SomeIntent", "isAuthPolExplicit": false, "isDiscoverable": true, "mangledTypeName": "5MyApp10SomeIntentV", "mangledTypeNameByBundleIdentifier": {}, }, "mangledTypeNameByBundleIdentifierV2": {}, "mangledTypeNameV2": "5MyApp10SomeIntentV", "openAppWhenRun": false, "outputFlags": 0, "parameters": [], "presentationStyle": 0, "requiredCapabilities": [], "supportedModes": 1, "systemProtocolMetadata": [], "systemProtocolMetadataV2": [], "systemProtocols": [], "title": { "alternatives": [], "key": "Some Intent" }, "typeSpecificMetadata": [], "visibilityMetadata": { "assistantOnly": false, "isDiscoverable": true } } -
メタデータの形式: AppSchema @AppIntent(schema: .system.search) struct SearchIntent: AppIntent { var criteria:
StringSearchCriteria } func perform() async throws -> some IntentResult { // do search something .result() } -
メタデータの形式: AppSchema @AppIntent(schema: .system.search) struct SearchIntent: AppIntent { var criteria:
StringSearchCriteria } func perform() async throws -> some IntentResult { // do search something .result() } "SearchIntent": { "assistantDefinedSchemaTraits": [], "assistantDefinedSchemas": [ { "domain": "system", "name": "ShowInAppSearchResultsIntent", "version": "1.0.0" } ], … "systemProtocolMetadata": [ "com.apple.link.systemProtocol.AssistantIntent", -
Swift Build: メタデータのハンドリング .xcodeproj .app Xcode exec *.swift Info.plist Swift
Build Metadata.appintents appintentsmetadataprocessor .swiftconstvalues llbuild swiftc Metadata.appintents -
Swift Build: マルチモジュール static link App.app Module A Module B
struct AIntent struct BIntent Module C struct CIntent SPMを利用したマルチモジュール構成で検証 -
Swift Build: マルチモジュール static link App.app static link Module A
Module B struct AIntent struct BIntent Module C struct CIntent library(type: .static) -
Swift Build: マルチモジュール static link App.app Module A Module B
struct AIntent struct BIntent Module C struct CIntent -
Swift Build: マルチモジュール static link App.app Module A Module B
struct AIntent struct BIntent Module C struct CIntent C/Metadata.appintents "CIntent" -
Swift Build: マルチモジュール static link App.app Module A Module B
struct AIntent struct BIntent A/Metadata.appintents B/Metadata.appintents "AIntent" "BIntent" "CIntent" "CIntent" Module C struct CIntent C/Metadata.appintents "CIntent" -
Swift Build: マルチモジュール static link Metadata.appintents "AIntent" App.app "BIntent" "CIntent"
Module A Module B struct AIntent struct BIntent A/Metadata.appintents B/Metadata.appintents "AIntent" "BIntent" "CIntent" "CIntent" Module C struct CIntent C/Metadata.appintents "CIntent" -
Swift Build: マルチモジュール dynamic link •static link •メタデータがマージされる •dynamic link
•メタデータがbundleごとに同封される -
Swift Build: マルチモジュール dynamic link App.app .framework struct SomeIntent Xcodeのframework
target (Mach-O Type=Dynamic Library)を利用して検証 -
Swift Build: マルチモジュール dynamic link .app Metadata.appintents extract.actionsdata Frameworks .framework
Metadata.appintents extract.actionsdata “SomeIntent" -
Swift Build: マルチモジュール dynamic link .app Metadata.appintents extract.actionsdata Frameworks .framework
Metadata.appintents extract.actionsdata “SomeIntent" システムは自動でFrameworksまで参照しない -
Swift Build: マルチモジュール dynamic link LibraryKit/Source.swift public struct LibraryKitAppIntentsPackage: AppIntentsPackage
{} App Target/Source.swift import ModuleC struct AppTargetAppIntentsPackage: AppIntentsPackage {} -
Swift Build: マルチモジュール dynamic link LibraryKit/Source.swift public struct LibraryKitAppIntentsPackage: AppIntentsPackage
{} App Target/Source.swift import ModuleC struct AppTargetAppIntentsPackage: AppIntentsPackage { static var includedPackages: [any AppIntentsPackage.Type] { [ LibraryKitAppIntentsPackage.self ] } } -
Swift Build: マルチモジュール dynamic link •AppIntentsPackage •extract.packagedataを生成する .app/Metadata.appintents/extract.packagedata { "includes":
[ "10LibraryKit0aB16AppIntentsPackageV" ], "version": 1 } -
Swift Build: マルチモジュール dynamic link .app Metadata.appintents extract.actionsdata Frameworks LibraryKit.framework
Metadata.appintents extract.actionsdata “SomeIntent" -
Swift Build: マルチモジュール dynamic link .app Metadata.appintents extract.actionsdata extract.packagedata “10LibraryKit0aB16AppIntentPackageV"
Frameworks LibraryKit.framework Metadata.appintents extract.actionsdata “SomeIntent" -
Swift Build: マルチモジュール dynamic link .app Metadata.appintents extract.actionsdata extract.packagedata “10LibraryKit0aB16AppIntentPackageV"
Frameworks LibraryKit.framework Metadata.appintents extract.actionsdata “SomeIntent" -
Swift Build: マルチモジュール dynamic link .app Metadata.appintents extract.actionsdata extract.packagedata “10LibraryKit0aB16AppIntentPackageV"
Frameworks LibraryKit.framework Metadata.appintents extract.actionsdata “SomeIntent" ※Siriの挙動なので、推測を含みます -
Swift Build: マルチモジュール dynamic link .app Metadata.appintents extract.actionsdata extract.packagedata “10LibraryKit0aB16AppIntentPackageV"
Frameworks LibraryKit.framework Metadata.appintents extract.actionsdata “SomeIntent" ※Siriの挙動なので、推測を含みます -
Swift Build: マルチモジュール dynamic link .app Metadata.appintents extract.actionsdata extract.packagedata “10LibraryKit0aB16AppIntentPackageV"
Frameworks LibraryKit.framework Metadata.appintents extract.actionsdata “SomeIntent" ※Siriの挙動なので、推測を含みます -
Swift Build: マルチモジュール xcrun appintentsmetadataprocessor \ --static-metadata-file-list DependencyStaticMetadataFileList \ —-metadata-file-list
DependencyMetadataFileList \ •static-metadata- le-list: static link用 •依存メタデータをマージする •metadata- le-list: dynamic link用 fi fi •依存メタデータのマージはしない、解決のみ -
Swift Build: マルチモジュールの注意 •AppShortcutsProviderはマージされない •.app/.appex (bundle root) に記述する必要あり struct MultiAppShortcuts:
AppShortcutsProvider { static var appShortcuts: [AppShortcut] { AppShortcut( intent: AppTargetModuleIntent(), phrases: [ "Run parent intent in \(.applicationName)", ], shortTitle: “Run Intent", systemImageName: "1.circle" ) } } -
参考 • Swiftビルド弾丸ツアー - Swift Buildが作る新しいエコシステム • swiftlang/swift lib/ConstExtract •
swiftlang/swift-build AppIntentsMetadataTaskProducer • サンプルコード • https://github.com/kntkymt/ios-appintents-metadata-build-sample