This page looks best with JavaScript enabled

Distributed Compilation with Gentoo

 ·  🎃 kr0m

There are times when compiling source code on the local machine can cause the microprocessor to melt, in my case I have Gentoo installed on a laptop that heats up when compiling a big application like Firefox or Thunderbird. Gentoo allows us to compile source code on an external machine, the only restriction is that they must share the same gcc branch.

We must have the same gcc branch on all machines, whether client or server, 3.3.x with 3.2.x will cause problems, while 3.3.2 3.3.4 will work, the version can be checked using gcc -v.


Server:

emerge -av distcc
vi /etc/conf.d/distccd
DISTCCD_OPTS="${DISTCCD_OPTS} --allow IP_CLIENT/32"

If we have filtered traffic using Iptables, we will add the following rule:

/sbin/iptables -I INPUT 1 -p tcp --dport 3632 -j DROP
/sbin/iptables -I INPUT 1 -p tcp --dport 3632 -s IP_CLIENT -j ACCEPT


Client:

vi /etc/portage/package.use/distcc
sys-devel/distcc gtk
emerge -av distcc
vi /etc/portage/make.conf
MAKEOPTS="-jN -lM"
FEATURES="distcc"

NOTE: N = Number of machines that will compile code (local and remote) + 1, M = Number of local cores, M is used when the compilation is local.

/usr/bin/distcc-config --set-hosts IP_SERVER

Both the local machine and the server can be used for compilation:

/usr/bin/distcc-config --set-hosts IP_SERVER localhost


Server/Client:

rc-update add distccd default
/etc/init.d/distccd start
export PATH="/usr/lib/ccache/bin:/usr/lib/distcc/bin:${PATH}"

It can be added to bashrc to do it automatically:

vi /home/USER/.bashrc

export PATH="/usr/lib/ccache/bin:/usr/lib/distcc/bin:${PATH}"

Now when we run emerge, the code compilation will be executed on the compilation server and the rest like linking locally.

NOTE: There is a configuration mode called pump that also distributes preprocessing among the compilation servers.

If you liked the article, you can treat me to a RedBull here