Skip to content

Commit 41168b2

Browse files
authored
Merge pull request Homebrew#191819 from sakeeb/recc
recc 1.2.21
2 parents 81db5dd + e0e31f7 commit 41168b2

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed

Formula/r/recc.rb

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
class Recc < Formula
2+
desc "Remote Execution Caching Compiler"
3+
homepage "https://buildgrid.gitlab.io/recc"
4+
url "https://gitlab.com/BuildGrid/buildbox/buildbox/-/archive/1.2.24/buildbox-1.2.24.tar.gz"
5+
sha256 "098de85fa2dc25c3aff4c91d9b7482dfc5842125344e51571991b0eddecbb1c2"
6+
license "Apache-2.0"
7+
head "https://gitlab.com/BuildGrid/buildbox/buildbox.git", branch: "master"
8+
9+
bottle do
10+
sha256 arm64_sequoia: "183dfd1da635da84e7b5ad05f7d2039c328ed9fafc4859840936e69bcd2c3578"
11+
sha256 arm64_sonoma: "54134c21c95d54b97716380ac73aaa496850ed149fc9731634d21654deeae7dd"
12+
sha256 arm64_ventura: "fbbdd33b2fed59f07eb7c73bd033fa0a9788985ee26122579d0006c6a627e3d5"
13+
sha256 sonoma: "89a15307fe615f1a871774776c12f37cd4c61a860fe4431ecd858bcbc939126d"
14+
sha256 ventura: "c855341953276bba6a882e7755c62bda47ade2d364f322ee18efeb85eac1f166"
15+
sha256 x86_64_linux: "145386d6b43da859dc86b85b830cfac10291e74428c2297915ff1f2068d8c656"
16+
end
17+
18+
depends_on "cmake" => :build
19+
depends_on "gettext" => :build # for envsubst
20+
depends_on "tomlplusplus" => :build
21+
depends_on "abseil"
22+
depends_on "c-ares"
23+
depends_on "glog"
24+
depends_on "grpc"
25+
depends_on "openssl@3"
26+
depends_on "protobuf"
27+
depends_on "re2"
28+
uses_from_macos "zlib"
29+
30+
on_macos do
31+
depends_on "gflags"
32+
end
33+
34+
on_linux do
35+
depends_on "pkg-config" => :build
36+
depends_on "util-linux"
37+
end
38+
39+
def install
40+
buildbox_cmake_args = %W[
41+
-DCASD=ON
42+
-DCASD_BUILD_BENCHMARK=OFF
43+
-DCASDOWNLOAD=OFF
44+
-DCASUPLOAD=OFF
45+
-DFUSE=OFF
46+
-DLOGSTREAMRECEIVER=OFF
47+
-DLOGSTREAMTAIL=OFF
48+
-DOUTPUTSTREAMER=OFF
49+
-DRECC=ON
50+
-DREXPLORER=OFF
51+
-DRUMBA=OFF
52+
-DRUN_BUBBLEWRAP=OFF
53+
-DRUN_HOSTTOOLS=ON
54+
-DRUN_OCI=OFF
55+
-DRUN_USERCHROOT=OFF
56+
-DTREXE=OFF
57+
-DWORKER=OFF
58+
-DRECC_CONFIG_PREFIX_DIR=#{etc}
59+
]
60+
system "cmake", "-S", ".", "-B", "build", *buildbox_cmake_args, *std_cmake_args
61+
system "cmake", "--build", "build"
62+
system "cmake", "--install", "build"
63+
64+
ENV["RECC_BIN"] = bin/"recc"
65+
system "command envsubst < scripts/wrapper-templates/recc-c++.in > recc-c++"
66+
system "command envsubst < scripts/wrapper-templates/recc-cc.in > recc-cc"
67+
bin.install "recc-c++"
68+
bin.install "recc-cc"
69+
70+
ENV["RECC_CONFIG_PREFIX"] = "$(brew --prefix)/etc"
71+
ENV["RECC_CONFIG_DIRECTORY"] = "\"${RECC_CONFIG_DIRECTORY}\""
72+
ENV["RECC_SERVER"] = "unix://#{var}/recc/casd/casd.sock"
73+
ENV["RECC_INSTANCE"] = "recc-server"
74+
ENV["RECC_REMOTE_PLATFORM_ISA"] = Hardware::CPU.arch.to_s
75+
ENV["RECC_REMOTE_PLATFORM_OS"] = OS.kernel_name.downcase
76+
ENV["RECC_REMOTE_PLATFORM_OS_VERSION"] = OS.kernel_version.to_s
77+
system "command envsubst < scripts/wrapper-templates/recc.conf.in > recc.conf"
78+
etc.install "recc.conf"
79+
80+
bin.install "scripts/wrapper-templates/casd-helper" => "recc-server"
81+
end
82+
83+
service do
84+
run [opt_bin/"recc-server", "--local-server-instance", "recc-server", "#{var}/recc/casd}"]
85+
keep_alive true
86+
working_dir var/"recc"
87+
log_path var/"log/recc-server.log"
88+
error_log_path var/"log/recc-server-error.log"
89+
end
90+
91+
def caveats
92+
<<~EOS
93+
To launch a compiler with recc, set the following variables:
94+
CC=#{opt_bin}/recc-cc
95+
CXX=#{opt_bin}/recc-c++
96+
EOS
97+
end
98+
99+
test do
100+
# Start recc server
101+
recc_cache_dir = testpath/"recc_cache"
102+
recc_cache_dir.mkdir
103+
recc_casd_pid = spawn bin/"recc-server", "--local-server-instance", "recc-server", recc_cache_dir
104+
105+
# Create a source file to test caching
106+
test_file = testpath/"test.c"
107+
test_file.write <<~EOS
108+
int main() {}
109+
EOS
110+
111+
# Wait for the server to start
112+
sleep 2 unless (recc_cache_dir/"casd.sock").exist?
113+
114+
# Override default values of server and log_level
115+
ENV["RECC_SERVER"] = "unix://#{recc_cache_dir}/casd.sock"
116+
ENV["RECC_LOG_LEVEL"] = "info"
117+
recc_test=[bin/"recc-cc", "-c", test_file]
118+
119+
# Compile the test file twice. The second run should get a cache hit
120+
system(*recc_test)
121+
output = shell_output("#{recc_test.join(" ")} 2>&1")
122+
assert_match "Action Cache hit", output
123+
124+
# Stop the server
125+
Process.kill("TERM", recc_casd_pid)
126+
end
127+
end

0 commit comments

Comments
 (0)