Skip to content

Commit

Permalink
recc 1.2.20
Browse files Browse the repository at this point in the history
RECC is a compiler launcher that caches the results on compilation and
link command, and optionally forward them to a remote execution service.

Remove running launchctrl command in caveat

Update Formula/r/recc.rb

Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>

Update Formula/r/recc.rb

Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>

Update Formula/r/recc.rb

Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>

Update Formula/r/recc.rb

Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
  • Loading branch information
msabakka and carlocab committed Sep 25, 2024
1 parent 16dce87 commit 9cb484d
Showing 1 changed file with 210 additions and 0 deletions.
210 changes: 210 additions & 0 deletions Formula/r/recc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
class Recc < Formula
desc "Remote Execution Caching Compiler"
homepage "https://buildgrid.gitlab.io/recc"
url "https://gitlab.com/BuildGrid/buildbox/buildbox/-/archive/1.2.20/buildbox-1.2.20.tar.gz"
sha256 "5ad5ccbad1250accc984823bd5d78604441c7711320b0569889f45f329ed6311"
license "Apache-2.0"
head "https://gitlab.com/BuildGrid/buildbox/buildbox.git", branch: "master"

depends_on "cmake" => :build
depends_on "tomlplusplus" => :build
depends_on "abseil"
depends_on "c-ares"
depends_on "glog"
depends_on "grpc"
depends_on "openssl@3"
depends_on "protobuf"
depends_on "re2"
uses_from_macos "zlib"

on_macos do
depends_on "gflags"
end

on_linux do
depends_on "pkg-config" => :build
depends_on "util-linux" => :build
end

def generate_recc_conf(config_directory)
recc_conf_tmpl = <<~EOS
##
# For the list of configuration parameters please visit:
# https://buildgrid.gitlab.io/recc/configuration-variables.html
#
# The configuration file settings use lowercase letters without the RECC_ prefix
# By default recc reads the configuration options from the following places,
# applying settings bottom-up, with 1 being the last applied configuration.
# If an option is set in multiple places, the one higher on this list will be the
# effective one
#
# 1. Environment variables
# 2. ${cwd}/recc/recc.conf
# 3. {$RECC_CONFIG_DIRECTORY}/recc.conf
# 4. ~/.recc/recc.conf
# 5. <%= "#{etc}/recc/recc.conf" %>
# 6. <%= "#{prefix}/etc/recc/recc.conf" %>
##
# Protocol version used for communicating with the REAPI server
reapi_version=2.2
# The URI of the server
server=<%= "unix://#{var}/recc/casd/casd.sock" %>
# Instance name provided by the server
instance=recc-server
# Identifier to correlate all recc invocations#{" "}
correlated_invocations_id=<%= #{`hostname`.strip} %>
# Use cache-only mode, build anything not available in the cache locally
cache_only=1
# Upload results from the local builds to cache
cache_upload_local_build=1
# Upload failed results from the local builds to cache
cache_upload_failed_build=1
# Enable for link commands#{" "}
link=1
# Use cache-only mode for link commands#{" "}
link_cache_only=1
# Report all entries returned by the dependency command, even if they are absolute paths
deps_global_paths=1
# Do not rewrite absolute paths to be relative.
no_path_rewrite=1
# Do not retry#{" "}
retry_limit=0
# Platform properties
REMOTE_PLATFORM_OS=<%= platform_os %>
REMOTE_PLATFORM_ISA=<%= Hardware::CPU.arch.to_s %>
EOS

config_directory.mkpath
File.write(config_directory / "recc.conf", ERB.new(recc_conf_tmpl).result(binding))
end

def generate_recc_server(bin_directory)
(bin_directory / "recc-server").write <<~EOS
#!/usr/bin/env sh
#{bin}/buildbox-casd \
--local-server-instance=recc-server \
--protect-session-blobs \
#{var}/recc/casd
EOS
end

def generate_recc_wrapper(bin_directory, compiler)
(bin_directory / "recc-#{compiler}").write <<~EOS
#!/usr/bin/env sh
#{bin}/recc $(command -v #{compiler}) $@
EOS
end

def buildbox_cmake_args
%W[
-DCASD=ON
-DCASD_BUILD_BENCHMARK=OFF
-DCASDOWNLOAD=OFF
-DCASUPLOAD=OFF
-DFUSE=OFF
-DLOGSTREAMRECEIVER=OFF
-DLOGSTREAMTAIL=OFF
-DOUTPUTSTREAMER=OFF
-DRECC=ON
-DREXPLORER=OFF
-DRUMBA=OFF
-DRUN_BUBBLEWRAP=OFF
-DRUN_HOSTTOOLS=ON
-DRUN_OCI=OFF
-DRUN_USERCHROOT=OFF
-DTREXE=OFF
-DWORKER=OFF
-DRECC_CONFIG_PREFIX_DIR=#{etc}/recc
]
end

def install
system "cmake", "-S", ".", "-B", "build", *buildbox_cmake_args, *std_cmake_args
system "cmake", "--build", "build", "-j", ENV.make_jobs.to_s
system "cmake", "--install", "build"

generate_recc_wrapper bin, "cc"
generate_recc_wrapper bin, "c++"
generate_recc_wrapper bin, "gcc"
generate_recc_wrapper bin, "g++"
generate_recc_wrapper bin, "clang"
generate_recc_wrapper bin, "clang++"

generate_recc_server bin

generate_recc_conf prefix/"etc/recc/"
end

def macos_caveats
on_macos do
<<~EOS
If you are starting the `recc` service via `brew service start`, please ensure the maxfiles limit
for `launchctl` is larger than 364. If you are running `recc-server` directly, please ensure
`ulimit -Sn` is larger than 364. The current limit is #{ulimit_sn}.
To increase the limit and make the change persist across reboots, you can create a launch daemon
using the following steps:
sudo /usr/libexec/PlistBuddy /Library/LaunchDaemons/limit.maxfiles.plist \\
-c "add Label string com.launchd.maxfiles" \\
-c "add ProgramArguments array" \\
-c "add ProgramArguments: string launchctl" \\
-c "add ProgramArguments: string limit" \\
-c "add ProgramArguments: string maxfiles" \\
-c "add ProgramArguments: string 512" \\
-c "add ProgramArguments: string unlimited" \\
-c "add RunAtLoad bool true" && \\
sudo chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist && \\
sudo chmod 644 /Library/LaunchDaemons/limit.maxfiles.plist && \\
sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist#{" "}
EOS
end
end

def caveats
<<~EOS
The recc configuration is read in the following order.
1. Environment variables (see: https://buildgrid.gitlab.io/recc/configuration-variables.html)
2. $(pwd)/recc/recc.conf
3. {$RECC_CONFIG_DIRECTORY}/recc.conf
4. ~/.recc/recc.conf
5. #{etc}/recc/recc.conf
6. #{bin}/../etc/recc/recc.conf
If an option is set in multiple places, the one higher up in the list will be effective.
To launch a compiler with recc, set the following variables:
CC=#{bin}/recc-cc
CXX=#{bin}/recc-c++
For CMake builds, an alternative option is to use CMAKE_<LANG>_COMPILER/LINKER_LAUNCHER.
Please do not set both CC/CXX and CMAKE_<LANG>COMPILER?LINKER_LAUNCHER variables to recc.
CMAKE_C_COMPILER_LAUNCHER=#{bin}/recc
CMAKE_CXX_COMPILER_LAUNCHER=#{bin}/recc
CMAKE_C_LINKER_LAUNCHER=#{bin}/recc
CMAKE_CXX_LINKER_LAUNCHER=#{bin}/recc
Start the recc service to use the out-of-the-box configuration (see instructions below).
#{macos_caveats}
EOS
end

test do
system bin/"recc", "--version"
end

service do
run [opt_bin/"recc-server"]
keep_alive true
working_dir var/"recc"
log_path var/"log/casd.log"
error_log_path var/"log/casd-error.log"
end
end

0 comments on commit 9cb484d

Please sign in to comment.