github 地址: https://github.com/icecc/icecream
是基于 distcc 实现的,相比较 distcc 有以下优点:
用yum install icecream
可以安装 icecream ,是 2017 年的版本,且测试下来有问题
因此选择编译 icecream 的方式安装 icecream
编译脚本如下:
#!/bin/bash
set -ex
yum install automake autoconf libtool libcap-ng-devel lzo-devel libzstd-devel libarchive-devel -y
git clone https://github.com/icecc/icecream.git
pushd icecream/
./autogen.sh
./configure --without-man
make
make install
popd
icecc-scheduler 是 icecream 的调度服务器
安装部署,类似如下脚本,这里包含做成 systemd 服务
先创建 icecc 账号,systemd 服务用该账号启动:
groupadd icecc
useradd -g icecc icecc -s /sbin/nologin
具体脚本如下:
#!/bin/bash
set -ex
cat >/etc/sysconfig/icecc-scheduler <<EOF
ICECREAM_NETNAME="icecream_net1"
ICECREAM_SCHEDULER_HOST="172.26.144.19"
ICECREAM_MAX_JOBS=""
ICECREAM_ALLOW_REMOTE="yes"
# ICECREAM_SCHEDULER_DEBUG="-vvv"
ICECREAM_SCHEDULER_DEBUG="-v"
EOF
cat > /usr/lib/systemd/system/icecc-scheduler.service <<EOF
[Unit]
Description=Icecream distributed compiler scheduler
[Service]
Type=simple
User=icecc
Group=icecc
SyslogIdentifier=icecc-scheduler
EnvironmentFile=-/etc/sysconfig/icecc-scheduler
ExecStart=/usr/local/sbin/icecc-scheduler -n \${ICECREAM_NETNAME} --persistent-client-connection \${ICECREAM_SCHEDULER_DEBUG}
[Install]
WantedBy=multi-user.target
EOF
systemctl enable icecc-scheduler.service
systemctl daemon-reload
systemctl restart icecc-scheduler.service
iceccd 是 icecream 的编译守护进程
编译机、开发机都要安装
安装部署,类似如下脚本,这里包含做成 systemd 服务
先创建 icecc 账号,systemd 服务用该账号启动:
groupadd icecc
useradd -g icecc icecc -s /sbin/nologin
具体脚本如下:
#!/bin/bash
set -ex
mkdir -p /data/iceccd/cache
chown -R icecc:icecc /data/iceccd/cache
cat >/etc/sysconfig/icecream <<EOF
ICECREAM_NETNAME="icecream_net1"
ICECREAM_SCHEDULER_HOST="172.26.144.19"
ICECREAM_MAX_JOBS=""
ICECREAM_ALLOW_REMOTE="yes"
ICECREAM_DEBUG="yes"
ICECREAM_LOG_FILE=/tmp/iceccd.log
ICECREAM_DEBUG="-v"
ICECREAM_CACHE_DIR="/data/iceccd/cache"
EOF
cat > /usr/lib/systemd/system/iceccd.service<<EOF
[Unit]
Description=Icecream Distributed Compiler
After=network.target nss-lookup.target
[Service]
Type=simple
Environment=SHELL=/bin/bash
SyslogIdentifier=iceccd
EnvironmentFile=-/etc/sysconfig/icecream
ExecStart=/usr/local/sbin/iceccd -u icecc -b \${ICECREAM_CACHE_DIR} -n \${ICECREAM_NETNAME} -s \${ICECREAM_SCHEDULER_HOST} \${ICECREAM_DEBUG}
Nice=5
[Install]
WantedBy=multi-user.target
EOF
systemctl enable iceccd.service
systemctl daemon-reload
systemctl restart iceccd.service
打包本地编译环境,类似如下脚本:
export CC=""
export CXX=""
export PATH=${your_gcc_bin_path}:$PATH
icecc --build-native```
本地项目编译脚本类似如下:
```shell
#!/bin/bash
set -ex
rm -rf build
mkdir -p build
pushd build
export PATH=/usr/local/libexec/icecc/bin/:$PATH
export ICECC_VERSION=xxx.tar.gz
export ICECC_DEBUG=info
cmake ..
make -j <num>
make install
popd
xxx.tar.gz 为 icecc --build-native 出来的文件
num 取多少值合适
引用官方的话:
Then you just compile with make -j , where is the amount of jobs you want to compile in parallel. As a start, take the number of logical processors multiplied with 2, or a larger number if your compile cluster can serve all the compilation jobs. But note that too large numbers may in fact make the build slower (for example if your local machine gets overloaded with preparing more jobs than it can handle at a time).
取决于编译集群规模与本地开发机的处理能力
需要实际跑几次确定
通过 ccache 缓存,编译速度还可以提高
github 地址: https://github.com/ccache/ccache
开发机安装 ccache
编译脚本,类似如下:
#!/bin/bash
set -ex
yum install asciidoctor -y
git clone https://github.com/ccache/ccache.git
pushd ccache
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DHIREDIS_FROM_INTERNET=ON ..
make
make install
popd
mkdir -p /usr/local/libexec/ccache/bin
ln -s /usr/local/bin/ccache /usr/local/libexec/ccache/bin/gcc
ln -s /usr/local/bin/ccache /usr/local/libexec/ccache/bin/g++
ln -s /usr/local/bin/ccache /usr/local/libexec/ccache/bin/cc
ln -s /usr/local/bin/ccache /usr/local/libexec/ccache/bin/c++
项目编译脚本类似:
#!/bin/bash
set -ex
rm -rf build
mkdir -p build
pushd build
export PATH=/usr/local/libexec/ccache/bin/:$PATH
export ICECC_VERSION=xxx.tar.gz
export ICECC_DEBUG=info
export CCACHE_PREFIX=icecc
cmake ..
make -j 16
make install
popd
以上