rules_apple
rules_apple copied to clipboard
Add apple.strip_swift_symbols feature
This is equivalent to Xcode's STRIP_SWIFT_SYMBOLS setting, if enabled
all Swift symbols from Swift standard libraries and imported dynamic
frameworks will be removed.
@brentleyjones Do you have any ideas how to test this?
Could we use binary_contents_test for both sides of the flag to check for the symbols? Resulting in at least 4 things tested:
- dylibs not stripped
- dylibs stripped
- imported framework not stripped
- imported framework stripped
How does this interplay with bazel's native strip logic?
Bazel strips the built target's binary (built by Bazel), where this is for the Swift standard libraries and imported dynamic frameworks. And it looks like it doesn't strip Swift symbols (there's no -T flag): https://cs.opensource.google/bazel/bazel/+/c282526c071389cd6f88cb77565283b257316267:src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java;l=1574-1597;drc=b38680a0ee3822e32adb4a63a29106bf64643718
Looking again at Xcode's documentation and our build logs, it seems the STRIP_SWIFT_SYMBOLS build setting and the "Strip Swift Symbols" export option are completely different things. The former is used for stripping the product when archiving, while the latter is used only for stripping the Swift standard libraries when exporting an ipa.
Symbols striping of imported frameworks in Xcode is controlled by another build setting called COPY_PHASE_STRIP.
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.
Agreed. I think it's fine to make this the default (same with Xcode), but it'd be better to have an option to allow users to opt-out, since it might cause problems:
The new Strip Swift Symbols (STRIP_SWIFT_SYMBOLS) build setting is enabled by default. It adjusts the level of symbol stripping so that when the linked product of the build is stripped, all Swift symbols are removed. This significantly reduces the size of Swift frameworks. If the lack of Swift symbols causes problems, such as when using dladdr(), this setting can be disabled. To view the exported symbols from file that has been stripped, use xcrun dyldinfo -export instead of nm. (31306055)
A side issue is that, since rules_apple doesn't yet have a full-fledge feature configuration support like rules_swift, so in order to make this enabled by default, we would have to name it a negative naming like apple.no_strip_swift_symbols 😢?
Update: Implemented the default features support.
@thii Can this PR be merged or does it need some other fixes? (Wondering if I should create a patch or wait for this to be merged.)
I'll try to get back to this and finish it soon, hopefully within next week.