Search code examples
xcodeclangxcode9xcodebuildstrip

Xcode 9.2: Size Discrepancy between Release builds inside Xcode and using xcodebuild


It appears that when building with Xcode 9.2, binaries generated with xcodebuild are slightly larger than by using Xcode's regular 'Build for Profiling' command. Both are set to generate Release builds, the configuration for command-line builds is also set to 'Release' and this did not occur with previous versions of Xcode.

These are the frameworks with their respective sizes when building from within Xcode:

enter image description here

And these are generated by xcodebuild:

enter image description here

I suspect that some debug or code coverage data is left in some of the frameworks when using xcodebuild.

FYI: A previous build had way larger C binaries (e.g. sqlite3.framework was several megabytes in size). After discovering https://github.com/Carthage/Carthage/issues/2056, I disabled code coverage in the 'Test' action of my build scheme and disabled the "Undefined Behavior" sanitizer. Before that, the frameworks were even larger (again, note sqlite3.framework) and there was a dylib from the "Undefined Behavior" sanitizer which should not be present in Release builds:

enter image description here

Did anyone encounter something similar and/or was able to fix this issue? Happy to provide the output of e.g. nm or otool if that helps (and you tell me which options to pass to those tools to generate meaningful information).

P.S.: I am using this command for xcodebuild:

xcodebuild -workspace Timing.xcworkspace -scheme 'Timing 2' -configuration 'Release' -derivedDataPath build clean build  

I did enable parallel builds with

defaults write com.apple.dt.Xcode BuildSystemScheduleInherentlyParallelCommandsExclusively -bool NO  

and am using the new Xcode build system, however the issue also appears with the "regular" build settings. Plus, there should not be a difference between the outputs of Xcode's build step and xcodebuild in either case. Also, sqlite3.framework is built via CocoaPods, but that should not matter, either.


Solution

  • Looks like the extra data was code coverage data injected due to xcodebuild adding the compiler options -profile-generate -profile-coverage-mapping. The "solution" was to uncheck the "Gather coverage data" option on the "Test" scheme action, even though xcodebuild was not building for testing.