Post

Replies

Boosts

Views

Activity

Reply to How to prevent duplicate resource bundles from SPM dynamic framework in app extensions?
While waiting for the enhancement request to SwiftPM, here's a battle-tested workaround to remove the duplicated resource bundles from app extensions (such as widgets): Add a run script phase to run after the "Embed Foundation Extensions" build phase: for path in "$BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH"/PlugIns/*/*.bundle; do bundle=$(basename "$path") if [ -d "$BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH/$bundle" ]; then >&2 echo "Stripping $path ..." rm -rf "$path" ln -vs "../../$bundle" "$path" else >&2 echo "Not stripping $path" fi done That changes into symlinks any resource bundles that are already found by the same name under the host app. It works because app extensions are sandboxed to the same file tree as their host app. One thing it does not solve however, is the deduplication of logic: because SwiftPM dependencies are linked statically by Xcode, any library code you include for the host app and its extensions will be duplicated in each executable binary. I think a holistic solution by Xcode would turn the whole SwiftPM library into a dynamic framework instead, statically linked by the app and its extensions. The resource bundles could then probably exist inside the framework rather than next to it.
1w