-
-
Notifications
You must be signed in to change notification settings - Fork 12.7k
/
Copy pathrecc.rb
127 lines (112 loc) · 3.98 KB
/
recc.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
class Recc < Formula
desc "Remote Execution Caching Compiler"
homepage "https://buildgrid.gitlab.io/recc"
url "https://gitlab.com/BuildGrid/buildbox/buildbox/-/archive/1.3.11/buildbox-1.3.11.tar.gz"
sha256 "dfebf2b8a25ce9ed21bc3d5c4720279baf21e56dd7fb944ea9d30763a245bf59"
license "Apache-2.0"
head "https://gitlab.com/BuildGrid/buildbox/buildbox.git", branch: "master"
bottle do
sha256 arm64_sequoia: "105100816296a843f996b6e901d935d247b9549b081866dab54c099b2d74aab0"
sha256 arm64_sonoma: "1e55d1d697bed39ab38f7438f4bff156cf02f3e3d992ea249b68a27ad572380d"
sha256 arm64_ventura: "d6394f816079ea251e85beac5c8bf76b2c1f48d899e92de4b765b143ad87c02a"
sha256 sonoma: "588bf00a94de25992f9621cb3a0f052020776100eaab3a781bad85de58c8dae9"
sha256 ventura: "7a5c7c48223a2375470a5c6a6ca8754620c011e4b2d9cd8a9b885d446e151912"
sha256 arm64_linux: "48331c9d61423c7eec624bfaf553475348d7ffe243e05f5ab9ab66c1de1f3852"
sha256 x86_64_linux: "3a3a4631b51cead407f53a3ee1ced810c1d20cf1d27414d2d7ad2a2dd29fa48b"
end
depends_on "cmake" => :build
depends_on "gettext" => :build # for envsubst
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 "pkgconf" => :build
depends_on "util-linux"
end
def install
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}
]
system "cmake", "-S", ".", "-B", "build", *buildbox_cmake_args, *std_cmake_args
system "cmake", "--build", "build"
system "cmake", "--install", "build"
makefile_args = %W[
RECC=#{opt_bin}/recc
RECC_CONFIG_PREFIX=#{etc}
RECC_SERVER=unix://#{var}/recc/casd/casd.sock
RECC_INSTANCE=recc-server
RECC_REMOTE_PLATFORM_ISA=#{Hardware::CPU.arch}
RECC_REMOTE_PLATFORM_OSFamily=#{OS.kernel_name.downcase}
RECC_REMOTE_PLATFORM_OSRelease=#{OS.kernel_version}
]
system "make", "-f", "scripts/wrapper-templates/Makefile", *makefile_args
etc.install "recc.conf"
bin.install "recc-cc"
bin.install "recc-c++"
bin.install "scripts/wrapper-templates/casd-helper" => "recc-server"
end
service do
run [opt_bin/"recc-server", "--local-server-instance", "recc-server", "#{var}/recc/casd"]
keep_alive true
working_dir var/"recc"
log_path var/"log/recc-server.log"
error_log_path var/"log/recc-server-error.log"
environment_variables PATH: std_service_path_env
end
def caveats
<<~EOS
To launch a compiler with recc, set the following variables:
CC=#{opt_bin}/recc-cc
CXX=#{opt_bin}/recc-c++
EOS
end
test do
# Start recc server
recc_cache_dir = testpath/"recc_cache"
recc_cache_dir.mkdir
recc_casd_pid = spawn bin/"recc-server", "--local-server-instance", "recc-server", recc_cache_dir
# Create a source file to test caching
test_file = testpath/"test.c"
test_file.write <<~C
int main() {}
C
# Wait for the server to start
sleep 2 unless (recc_cache_dir/"casd.sock").exist?
# Override default values of server and log_level
ENV["RECC_SERVER"] = "unix://#{recc_cache_dir}/casd.sock"
ENV["RECC_LOG_LEVEL"] = "info"
recc_test=[bin/"recc-cc", "-c", test_file]
# Compile the test file twice. The second run should get a cache hit
system(*recc_test)
output = shell_output("#{recc_test.join(" ")} 2>&1")
assert_match "Action Cache hit", output
# Stop the server
Process.kill("TERM", recc_casd_pid)
end
end