Closed keith closed 4 years ago
For our project for a single architecture (arm64) this has a massive impact on ipa size:
Before:
% du -sh Lyft.ipa
108M Lyft.ipa
% du -sh SwiftSupport
41M SwiftSupport
After:
% du -sh Lyft.ipa
81M Lyft.ipa
% du -sh SwiftSupport
7.8M SwiftSupport
I assume this won't end up impacting app store builds since I assume apple will re-package those no matter what, but this would affect enterprise builds
We might be able to do something inside the swift_stdlib_tool.sh
tool, maybe pass an argument to do the stripping of the bitcode support.
We've recently run into this as well. It would be really nice if rules_swift
stripped the Swift Symbols.
To be clear, it should be more than swift_stdlib_tool.sh
, since that would only strip the dylibs. We should also strip dynamic frameworks.
For example, HTMLEntities is a dynamic framework we use and it's 300kb when copied/stripped by Xcode but 1.4mb when handled by Bazel.
We are now naively doing this with a ipa_post_processor
:
#!/bin/bash
set -eo pipefail
readonly work_dir="$1"
# Strip swiftlibs
find "$work_dir/Payload/" -type f -name "*.dylib" -exec sh -c 'xcrun bitcode_strip -r -o {} {}' \;
# Strip Frameworks
find "$work_dir/Payload/" -type d -name "*.framework" -exec sh -c 'xcrun bitcode_strip -r -o {}/$(basename {} .framework) {}/$(basename {} .framework)' \;
find "$work_dir/Payload/" -type d -name "*.framework" -exec sh -c 'xcrun strip -ST {}/$(basename {} .framework)' \;
The end result of this is a smaller IPA, but had no effect on reported sizes in the App Store.
@thii I think #881 only strips bitcode, correct? What about the swift symbols? In my above example I call
find "$work_dir/Payload/" -type d -name "*.framework" -exec sh -c 'xcrun strip -ST {}/$(basename {} .framework)' \;
to strip Swift Symbols from imported frameworks.
I totally forgot about it. rules_apple
doesn't currently have something equivalent to Xcode's "strip swift symbols" checkbox. How does adding a new define for it sound? (stripping bitcode doesn't mean also to strip symbols, right?)
A new flag sounds good. I like your approach in #979.
Do we need a flag or could it be safe to opt everyone into this?
Xcode has a checkbox, so I would prefer to give the same option?
I think in general I would prefer that we don't add options until they have a solid use case. Also that reduces the shear number of options people have to know about, and reduces the diff from upstream
. So in general if we can do the "right" thing for everyone I would prefer that until it's no longer the case.
Currently since rules_apple is incompatible with bitcode, we should mirror Xcode's behavior which is to strip the dylibs of bitcode and symbols to reduce their size. I'm not entirely sure how this affects final download size, but the "strip swift symbols" checkbox when archive from Xcode does this.
More specifically Xcode invokes
ipatool
with this value, which happens to be a ruby script in Xcode. Here's the relevant logic:Mainly the logic here is: