XCode工程运行使用CCache提高编译速度

使用CocoaPods工程越来越大时,每次运行都要花很长时间

使用CCache来消灭漫长的等待过程

1. 首选安装Homebrew,已安装可以跳过

(1)安装Command Line Tools for Xcode

        https://developer.apple.com/download/more/下载安装对应版本的Command Line Tools
(2)安装homebrew,需要先安装ruby

        /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2. 安装ccache

(1)homebrew安装ccchae
         brew install ccache

(2)添加Path         

cd ~
vi .bash_profile

//添加ccache的PATH
export PATH=$PATH:/usr/local/opt/ccache/libexec

//保存退出 
//让改动生效
source .bash_profile


(3)在工程目录下创建配置文件ccache-clang,如果工程中使用C++,将文件名和文件中的ccache-clang都替换为ccache-clang++。

        这里以ccache-clang++为例子

 cd  工程目录下
 touch ccache-clang++
 vi ccache-clang++


        copy以下内容保存        

#!/bin/sh
if type -p ccache >/dev/null 2>&1; then
  export CCACHE_MAXSIZE=10G
  export CCACHE_CPP2=true
  export CCACHE_HARDLINK=true
  export CCACHE_SLOPPINESS=file_macro,time_macros,include_file_mtime,include_file_ctime,file_stat_matches

  #日志排查问题用,不用时注释
  #export CCACHE_LOGFILE='../CCache.log'
  exec ccache /usr/bin/clang++ "$@"
else
  exec clang++ "$@"
fi

3.工程配置

(1)buildSetting中添加Add User-Defined Settings

         key为CC  value为$(SRCROOT)/ccache-clang++

(2)Enable Modules 设置为NO。不再支持@import的方式,将@import 替换为#import

(3)同上,Pods工程在Podfile中配置

post_install do |installer|
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['CLANG_ENABLE_MODULES'] = 'NO'
        config.build_settings['CC'] = '$(PODS_ROOT)/../ccache-clang++'
      end
    end
end

配置完成后第一次编译比较慢,缓存之后飞速

4. 另外Pods的脚本运行还是会卡一下

当没有资源文件变动时

第一次编译完之后将Build Phases  ->Copy Pods Resources下

run script only when installing勾选☑️

这样再次运行不会再遍历资源文件

如果变更资源文件 记得先关闭再运行

猜你喜欢

转载自blog.csdn.net/wnnvv/article/details/86476375
今日推荐