mozilla / sccache

Sccache is a ccache-like tool. It is used as a compiler wrapper and avoids compilation when possible. Sccache has the capability to utilize caching in remote storage environments, including various cloud storage options, or alternatively, in local storage.
Apache License 2.0
5.88k stars 552 forks source link

Suggestion: Include compiler wrapper binaries #1155

Open melvyn2 opened 2 years ago

melvyn2 commented 2 years ago

ccache and distcc both ship bin directories with wrapper binaries of the compilers they support:

$ pacman -Fl ccache
ccache usr/
ccache usr/bin/
ccache usr/bin/ccache
ccache usr/lib/
ccache usr/lib/ccache/
ccache usr/lib/ccache/bin/
ccache usr/lib/ccache/bin/c++
ccache usr/lib/ccache/bin/cc
ccache usr/lib/ccache/bin/clang
ccache usr/lib/ccache/bin/clang++
ccache usr/lib/ccache/bin/g++
ccache usr/lib/ccache/bin/gcc
ccache usr/lib/ccache/bin/x86_64-pc-linux-gnu-c++
ccache usr/lib/ccache/bin/x86_64-pc-linux-gnu-g++
ccache usr/lib/ccache/bin/x86_64-pc-linux-gnu-gcc
...

These allow users to change their PATH environment variable so that the wrappers' bin folder is set before the general folder where the real compilers are stored, instead of having to modify whatever the build system calls. I believe that adding a similar feature to sccache would make it easier to drop in to different systems with less modification.

melvyn2 commented 2 years ago

As a bit of clarification, the wrapper binaries are actually symlinks to the usual distcc/ccache binaries, who use the 0th argument to decide what to call (I believe). In the mean time, I am using this script to generate a similar directory:

#!/usr/bin/bash

cd "$(dirname "$0")"

for COMPILER in "c++" "c89" "c99" "cc" "clang" "clang++" "cpp" "g++" "gcc" "rustc" "x86_64-pc-linux-gnu-c++" "x86_64-pc-linux-gnu-cc" "x86_64-pc-linux-gnu-g++" "x86_64-pc-linux-gnu-gcc"; do
  cat > "./${COMPILER}" <<-EOF
#!/bin/bash
SCCACHE_WRAPPER_BINDIR="\$(dirname \${BASH_SOURCE[0]})"  # Intentionally don't resolve symlinks
PATH=\${PATH//":\$SCCACHE_WRAPPER_BINDIR:"/":"} # delete any instances in the middle
PATH=\${PATH/#"\$SCCACHE_WRAPPER_BINDIR:"/} # delete any instance at the beginning
PATH=\${PATH/%":\$SCCACHE_WRAPPER_BINDIR"/} # delete any instance in the at the end
/usr/bin/sccache ${COMPILER} "\$@"
  EOF
  chmod 755 "./${COMPILER}"
done