Upgrade to Pro — share decks privately, control downloads, hide ads and more …

'Improving Xcode build time​' by Sameh Mabrouk

'Improving Xcode build time​' by Sameh Mabrouk

Sameh will describe few things:
- The problem of relatively high build times with CocoaPods
- How to deal with it
- How to handle it
- What Swift issues may arise while customizing your build process

This talk was made for CocoaHeads Kyiv #13 which took place Dec 16 2017.

CocoaHeads Ukraine

December 16, 2017
Tweet

More Decks by CocoaHeads Ukraine

Other Decks in Programming

Transcript

  1. Optimisation on code level More class extensions increase build time

    Type inference, Swift takes more time to infers the types
  2. Dependency management Change debug information formate to “DWARF” post_install do

    |installer| puts("Update debug pod settings to speed up build time") Dir.glob(File.join("Pods", "**", "Pods*{debug}.xcconfig")).each do |file| File.open(file, 'a') { |f| f.puts "\nDEBUG_INFORMATION_FORMAT = dwarf" } end end
  3. Dependency management Change debug information formate to “DWARF” post_install do

    |installer| puts("Update debug pod settings to speed up build time") Dir.glob(File.join("Pods", "**", "Pods*{debug}.xcconfig")).each do |file| File.open(file, 'a') { |f| f.puts "\nDEBUG_INFORMATION_FORMAT = dwarf" } end end simply changing one option in Xcode reduced the waiting time in 25 seconds: nice!
  4. How to use Framework with CocoaPods Update pod spec Add

    binary/framework to your remote repo Pod install - to get the framework
  5. Example1: Podspec Pod::Spec.new do |s| s.name = 'ObjectMapper' s.version =

    '2.2.8' s.license = 'MIT' s.summary = 'JSON Object mapping written in Swift' s.homepage = 'https://github.com/Hearst-DD/ObjectMapper' s.authors = { 'Tristan Himmelman' => '[email protected]' } s.source = { :git => 'https://github.com/Hearst-DD/ObjectMapper.git', :tag => s.version.to_s } s.watchos.deployment_target = '2.0' s.ios.deployment_target = '8.0' s.osx.deployment_target = '10.9' s.tvos.deployment_target = '9.0' s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3.1', } s.requires_arc = true s.ios.vendored_frameworks = 'framework/ObjectMapper.framework' end
  6. Example2: subspecs Pod::Spec.new do |s| s.name = 'BananaLib' s.version =

    '1.0' s.author = 'Banana Corp' s.license = 'Proprietary' s.homepage = 'http://banana-corp.local/banana-lib.html' s.summary = 'Chunky bananas!' s.default_subspec = 'Source' s.subspec 'Source' do |source| source.source = { :git => 'http://banana-corp.local/banana-lib.git', :tag => 'v1.0' } source.source_files = '**/*.swift' end s.subspec 'Binary' do |binary| binary.source = { :http => 'http://banana-corp.local/banana-framework.zip' } binary.vendored_frameworks = 'BananaFramework.framework' end end
  7. #!/bin/bash # clonning remote git repo function lazyclone { url=$1"

    "$2" "$3; echo $url reponame=$(echo $url | awk -F/ '{print $NF}' | sed -e 's/.git$//'); echo $reponame git clone $url $reponame; cd $reponame; } lazyclone $1" "$2" "$3 # using carthage to create dynamic framework from .xcodeproj carthage build --no-skip-current cd "Carthage/Build/iOS" # Go back to repo main directory cd .. cd .. cd .. # Create a directory called framework that hold the binary mkdir framework # Copy .framework from Carthage/Build/iOS directory to framwork directory cp -R ${PWD}/Carthage/Build/iOS/$reponame.framework ${PWD}/framework cp -R ${PWD}/Carthage/Build/iOS/$reponame.framework.dSYM ${PWD}/framework # Change .podspec so it should contain s.ios.vendored_frameworks sed -i '' '/source_files/c\ s.source_files = '"'""'"' $'\n'' ./${reponame}.podspec sed -i '' '/end/i\ s.ios.vendored_frameworks = '"'"framework/${reponame}.framework"'"' $'\n'' ./${reponame}.podspec # Remove Carthage directory rm -r Carthage # Commit and push .podspec and framework to remote repo function lazyPush() { git add . git commit -a -m "$1" git push } lazyPush "Change pod spec to support dynamic framework + add dynamic framework" echo "Done!" echo "Now you have a framework for this dependency, just do pod install in your project to use it" echo "Have a good day!"
  8. Conclusion It only requires spending some time on it once

    in a while, ideally only costing a few hours every few months.