-
Notifications
You must be signed in to change notification settings - Fork 63
[WIP][Functional] Add example Siri Shortcut #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
4e921b1
d788327
f50ee16
5425b68
041564e
14764a7
247ca35
8715e5c
3ad2a02
f90fe86
5fffe75
a060fc7
3f21c5f
74c83fd
c22f380
676c06b
5e5b111
d1b0509
d519409
7b8faf7
52dc9d6
ad6af79
227131b
c67e7e6
85c3b1a
41cbae1
a20ea1f
df13572
3a92916
fbc7a7d
b565ae5
8d39ccc
87f7185
ee1ec1e
48d7ba5
b3acc6f
b2d5237
f656cb6
ac938b3
582508b
c067ed0
7cff1b0
bb258ac
f16f11b
7acb92f
3794fd0
7a82c08
463e3b4
0a5b442
c467c8b
a4d12b6
d4c45d4
fca3075
ba21ce4
b8f1ceb
bdcc891
b7fad87
204ed2e
51f6dba
85dcd1a
6cea09f
3d9eb26
b71cd9e
76538ff
2948f14
25c64b8
94e7b39
52e65d6
c98c372
490ca98
40d7705
0cc6ae8
69c2596
9037297
227623b
358dc67
380c709
6386ea8
905456a
7061d33
884ea19
dc1823a
07a4ae6
273c29a
0c6c4b2
c34ca1e
1daee65
b637c4e
8338c76
3e90047
ac70379
91a4096
17209dd
70033a6
08fa2d4
b9632e2
0cd69bf
07b4ebd
a215603
e40af55
f031411
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| load("//Config:configs.bzl", "app_binary_configs", "library_configs", "watch_binary_configs", "message_binary_configs", "pretty", "info_plist_substitutions", "bundle_identifier", "DEVELOPMENT_LANGUAGE") | ||
| load("//Config:buck_rule_macros.bzl", "apple_lib", "apple_test_lib", "apple_test_all") | ||
| load("//Config:configs.bzl", "app_binary_configs", "library_configs", "watch_binary_configs", "message_binary_configs", "intent_binary_configs", "pretty", "info_plist_substitutions", "bundle_identifier", "DEVELOPMENT_LANGUAGE") | ||
| load("//Config:buck_rule_macros.bzl", "apple_lib", "apple_test_lib", "apple_test_all", "intent_interface") | ||
|
|
||
| apple_asset_catalog( | ||
| name = "ExampleAppAssets", | ||
|
|
@@ -57,8 +57,10 @@ apple_library( | |
| swift_version = "4.0", | ||
| srcs = [ | ||
| "ViewController.swift", | ||
| "ViewController+INUIAddVoiceShortcutViewControllerDelegate.swift", | ||
| "AppDelegate.swift", | ||
| "LocalizationHelper.swift", | ||
| ":BuckPhotoIntentInterface", | ||
| ], | ||
| tests = app_tests, | ||
| deps = [ | ||
|
|
@@ -69,10 +71,16 @@ apple_library( | |
|
|
||
| # Resources | ||
| "//App/Resources:ExampleAppStringResources", | ||
| "//App/Resources:IntentsDefinition", | ||
| "//App/Resources:IntentsStringResources", | ||
| "//App/Resources:StoryboardResources", | ||
| ] | ||
| + first_party_library_dependencies | ||
| + build_phase_scripts, | ||
| frameworks = [ | ||
| "$SDKROOT/System/Library/Frameworks/Intents.framework", | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure that
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nevermind. This is used by the generated intent source code.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So it's good we keep |
||
| "$SDKROOT/System/Library/Frameworks/IntentsUI.framework", | ||
| ], | ||
| ) | ||
|
|
||
| apple_binary( | ||
|
|
@@ -82,6 +90,7 @@ apple_binary( | |
| "//App/...", | ||
| ], | ||
| configs = app_binary_configs("ExampleApp"), | ||
| entitlements_file = "ExampleApp.entitlements", | ||
| swift_version = "4.0", | ||
| srcs = [ | ||
| "BuckSupportFiles/Dummy.swift", | ||
|
|
@@ -148,7 +157,9 @@ apple_bundle( | |
| deps = [ | ||
| # For "#watch", https://buckbuild.com/rule/apple_bundle.html#deps | ||
| ":ExampleWatchApp#watch", | ||
| ":ExampleMessageExtension" | ||
| ":ExampleMessageExtension", | ||
| ":ExampleIntentExtension", | ||
| ":ExampleIntentUIExtension", | ||
| ] | ||
| + prebuilt_frameworks, | ||
| ) | ||
|
|
@@ -158,6 +169,129 @@ apple_package( | |
| bundle = ":ExampleApp", | ||
| ) | ||
|
|
||
| ### Siri Shortcut Begin ### | ||
|
|
||
| # Set up `BuckPhotoIntent` by handling the .intentdefinition file. | ||
| intent_interface( | ||
| "BuckPhotoIntentInterface", | ||
| "BuckPhoto", | ||
| "SiriShortcut/_IntentsCompiler/IntentsCompiler.xcodeproj") | ||
|
|
||
| # The non-UI code for processing `BuckPhotoIntent`. | ||
| intent_bundle_identifier = bundle_identifier("ExampleApp.IntentExtension") | ||
| intent_binary_name = "ExampleIntentBinary" | ||
| intent_bundle_name = "ExampleIntentExtension" | ||
| intent_info_plist_substitutions = { | ||
| "DEVELOPMENT_LANGUAGE": "en-us", | ||
| "EXECUTABLE_NAME": intent_bundle_name, | ||
| "PRODUCT_BUNDLE_DISPLAY_NAME": intent_bundle_name, | ||
| "PRODUCT_BUNDLE_IDENTIFIER": intent_bundle_identifier, | ||
| "PRODUCT_NAME": intent_bundle_name, | ||
| # The Swift module name for `IntentHandler` is the binary name. | ||
| "NS_EXTENSION_PRINCIPAL_CLASS": "%s.IntentHandler" % intent_binary_name, | ||
| } | ||
|
|
||
| apple_binary( | ||
| name = intent_binary_name, | ||
| srcs = glob([ | ||
| "SiriShortcut/ExampleIntent/**/*.swift", | ||
| ]) + [":BuckPhotoIntentInterface"], | ||
| configs = intent_binary_configs(intent_info_plist_substitutions), | ||
|
|
||
| # "-e _NSExtensionMain" tell linker this binary is app extension, so it won't fail due to | ||
| # missing _main "-Xlinker -rpath -Xlinker @executable_path/../../Frameworks" tells the | ||
| # executable binary to look for frameworks in ExampleApp.app/Frameworks instead of PlugIns, so | ||
| # that we don't need to have the libSwift*.dylib in ExampleApp.app/PlugIns/*.appex/Frameworks | ||
| linker_flags = [ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need to add
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. Thanks for sharing @rockbruno. Are you on Swift 5?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m trying to understand if this is because the Swift libraries packaged with the app are now being ignored. If I understand correctly this occurs with Swift 5+ and iOS 12.2+.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm on 4.2, but I'm using Xcode 10.2 which IIRC uses the Swift 5 compiler regardless of the version. |
||
| "-e", | ||
| "_NSExtensionMain", | ||
| "-Xlinker", | ||
| "-rpath", | ||
| "-Xlinker", | ||
| "@executable_path/../../Frameworks", | ||
| ], | ||
| deps = [ | ||
| "//App/Resources:IntentsDefinition", | ||
| "//App/Resources:IntentsStringResources", | ||
| ], | ||
| frameworks = [ | ||
| "$SDKROOT/System/Library/Frameworks/Intents.framework", | ||
| ], | ||
| ) | ||
|
|
||
| apple_bundle( | ||
| name = intent_bundle_name, | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If necessary you can also set
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When unspecified |
||
| binary = ":" + intent_binary_name, | ||
| extension = "appex", | ||
| info_plist = "SiriShortcut/ExampleIntent/Info.plist", | ||
| info_plist_substitutions = intent_info_plist_substitutions, | ||
| xcode_product_type = "com.apple.product-type.app-extension", | ||
| ) | ||
|
|
||
| # The UI code for displaying the response to `BuckPhotoIntent`. | ||
| intentui_bundle_identifier = bundle_identifier("ExampleApp.IntentUIExtension") | ||
| intentui_binary_name = "ExampleIntentUIBinary" | ||
| intentui_bundle_name = "ExampleIntentUIExtension" | ||
| intentui_resources_name = intentui_bundle_name + "Resources" | ||
| intentui_info_plist_substitutions = { | ||
| "DEVELOPMENT_LANGUAGE": "en-us", | ||
| "EXECUTABLE_NAME": intentui_bundle_name, | ||
| "PRODUCT_BUNDLE_DISPLAY_NAME": intentui_bundle_name, | ||
| "PRODUCT_BUNDLE_IDENTIFIER": intentui_bundle_identifier, | ||
| "PRODUCT_NAME": intentui_bundle_name, | ||
| } | ||
|
|
||
| apple_binary( | ||
| name = intentui_binary_name, | ||
| srcs = glob([ | ||
| "SiriShortcut/ExampleIntentUI/**/*.swift", | ||
| ]) + [":BuckPhotoIntentInterface"], | ||
| configs = intent_binary_configs(intentui_info_plist_substitutions), | ||
|
|
||
| # "-e _NSExtensionMain" tell linker this binary is app extension, so it won't fail due to | ||
| # missing _main "-Xlinker -rpath -Xlinker @executable_path/../../Frameworks" tells the | ||
| # executable binary to look for frameworks in ExampleApp.app/Frameworks instead of PlugIns, so | ||
| # that we don't need to have the libSwift*.dylib in ExampleApp.app/PlugIns/*.appex/Frameworks | ||
| linker_flags = [ | ||
| "-e", | ||
| "_NSExtensionMain", | ||
| "-Xlinker", | ||
| "-rpath", | ||
| "-Xlinker", | ||
| "@executable_path/../../Frameworks", | ||
| ], | ||
| deps = [ | ||
| "//App/Resources:IntentsDefinition", | ||
| "//App/Resources:IntentsStringResources", | ||
| ], | ||
| frameworks = [ | ||
| "$SDKROOT/System/Library/Frameworks/Intents.framework", | ||
| "$SDKROOT/System/Library/Frameworks/IntentsUI.framework", | ||
| ], | ||
| ) | ||
|
|
||
| apple_resource( | ||
| name = intentui_resources_name, | ||
| dirs = [], | ||
| # WORKAROUND: Buck CLI requires you to explicitly set the "Module Name" of the | ||
| # `IntentViewController` class to `ExampleIntentUIBinary` in MainInterface.storyboard. | ||
| files = glob(["SiriShortcut/ExampleIntentUI/**/*.storyboard"]) | ||
| ) | ||
|
|
||
| apple_bundle( | ||
| name = intentui_bundle_name, | ||
| binary = ":" + intentui_binary_name, | ||
| extension = "appex", | ||
| info_plist = "SiriShortcut/ExampleIntentUI/Info.plist", | ||
| info_plist_substitutions = intentui_info_plist_substitutions, | ||
| xcode_product_type = "com.apple.product-type.app-extension", | ||
| deps = [ | ||
| ":" + intentui_resources_name, | ||
| ], | ||
| ) | ||
|
|
||
| ### Siri Shortcut End ### | ||
|
|
||
| ### Watch App Begin ### | ||
| # Define the watch app in the same BUCK file as the binary into which the watch app will be installed. | ||
| # Xcode is finicky when it comes to how it embeds watch apps into main app bundles. Watch apps are | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>com.apple.developer.siri</key> | ||
| <true/> | ||
| </dict> | ||
| </plist> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's behind a feature flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works around having Xcode 9 in CI.