LoginSignup
1
2

More than 1 year has passed since last update.

UnityのiOS版→Xcodeビルド時にccacheを使う

Posted at

Unityで出力したiOS版プロジェクトからccache使う方法がわかってきたのでメモ。

作業環境(2022.11.08時点)

  • MacOS Ventura 13.0
  • Xcode 14.1
  • xcode-select --install を実行してあること
  • Homebrew 3.6.9
  • ccache 4.7.3
  • Unity 2020.3.37f1
  • iOS 16.1

参考URL

ccache で Unity の生成する Xcode プロジェクトのビルドを高速化する
https://zenn.dev/pobo380/articles/1a5d838ee857e1

M1 環境で Homebrew 導入コマンドを Xcode から叩けない場合の対処法
https://qiita.com/hugehoge/items/0f805c1a264488f7807c

ccacheのインストール

brew install ccache

ccache_wrapper の作成

#!/bin/bash

if [ -d "/opt/homebrew/bin" ]; then
  export PATH=$PATH:/opt/homebrew/bin
fi
if [ -d "/opt/homebrew/sbin" ]; then
  export PATH=$PATH:/opt/homebrew/sbin
fi
if [ -d "/usr/local/Cellar/ccache" ]; then
  export PATH=$PATH:/usr/local/bin
fi

if type "ccache" > /dev/null 2>&1; then
    export CCACHE_SLOPPINESS=pch_defines,time_macros
    exec `which ccache` $DT_TOOLCHAIN_DIR/usr/bin/clang -Xclang -fno-pch-timestamp "$@"
else
    exec $DT_TOOLCHAIN_DIR/usr/bin/clang "$@"
fi

M1/M2環境のMacではXcodeからのビルド時にHomebrewパスが見えないという問題があるため、直接PATHを記載した。
同様にIntel Mac環境でもccacheのフォルダを確認できたらパスを追加するという処理を記載。
(より柔軟な対応をするのであれば参考URL先のほうが良い対応であるけれど、今回は場当たり対応で問題ないので直接指定)

Unityのビルド後アクションの追加

参考記事「ccache で Unity の生成する Xcode プロジェクトのビルドを高速化する」の内容をもとにcsファイルを追加

Xcodeでビルドを実行

ccache 初回実行

20221108_151250_1665295970954 - 20221108_151502_1665296102141
Cacheable calls: 812 /  812 (100.0%)
Hits: 0 /  812 ( 0.00%)
Direct: 0
Preprocessed: 0
Misses: 812 /  812 (100.0%)
Local storage:
 Cache size (GB): 0.25 / 5.00 ( 4.95%)

ビルド時間は132秒(131187ミリ秒)

2回目、プロジェクトCleanを行い再度のビルド(内容に変更なし)

20221108_151607_1665296167122 - 20221108_151615_1665296175946
Cacheable calls: 1624 / 1624 (100.0%)
Hits: 812 / 1624 (50.00%)
Direct: 812 /  812 (100.0%)
Preprocessed: 0 /  812 ( 0.00%)
Misses: 812 / 1624 (50.00%)
Local storage:
 Cache size (GB): 0.25 / 5.00 ( 4.95%)

ビルド時間は8秒(8824ミリ秒)

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2