-
-
Notifications
You must be signed in to change notification settings - Fork 12.3k
/
v8.rb
189 lines (159 loc) · 7.8 KB
/
v8.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
class V8 < Formula
desc "Google's JavaScript engine"
homepage "https://github.com/v8/v8/wiki"
# Track V8 version from Chrome stable: https://chromiumdash.appspot.com/releases?platform=Mac
url "https://github.com/v8/v8/archive/11.6.189.19.tar.gz"
sha256 "3f827114a0a47d2ec901d3fbb091080f49d6cf0fab34afbe19f1b2dc419f2640"
license "BSD-3-Clause"
livecheck do
url "https://chromiumdash.appspot.com/fetch_releases?channel=Stable&platform=Mac"
regex(/(\d+\.\d+\.\d+\.\d+)/i)
strategy :json do |json, regex|
# Find the v8 commit hash for the newest Chromium release version
v8_hash = json.max_by { |item| Version.new(item["version"]) }.dig("hashes", "v8")
next if v8_hash.blank?
# Check the v8 commit page for version text
v8_page = Homebrew::Livecheck::Strategy.page_content(
"https://chromium.googlesource.com/v8/v8.git/+/#{v8_hash}",
)
v8_page[:content]&.scan(regex)&.map { |match| match[0] }
end
end
bottle do
sha256 cellar: :any, arm64_ventura: "8432981636206ebeaa21dfd8fcf6d5d52a2dd56de7d52e909f26e5974dca5527"
sha256 cellar: :any, arm64_monterey: "34eac5533b95ea08b6bf642be47cdf496cff0408ab0cda1346b5441de8aac075"
sha256 cellar: :any, arm64_big_sur: "c41d1e28dcc0c28111fc28e6a3288c04474279416bda3be192ac33e296fb1111"
sha256 cellar: :any, ventura: "82b0aa5f74c65a45dcdde544f7af3c54ae87800dd8d8b72033645b1f593b2315"
sha256 cellar: :any, monterey: "e2e44656587199d88023e886656a4dba248db85b3f155a3d577d6f74ecf9774a"
sha256 cellar: :any, big_sur: "b65794dfd8732f87caadcd405dba28312046b18d3b7915ab19bdf4d3b9c6bcf6"
sha256 cellar: :any_skip_relocation, x86_64_linux: "28b89da1f28a28bccd5df1443557927f14e07f3ea4504087b8a30033f2065f50"
end
depends_on "ninja" => :build
depends_on "python@3.11" => :build
on_macos do
depends_on "llvm" => :build
depends_on xcode: ["10.0", :build] # required by v8
end
on_linux do
depends_on "pkg-config" => :build
depends_on "glib"
end
fails_with gcc: "5"
# Look up the correct resource revisions in the DEP file of the specific releases tag
# e.g. for CIPD dependency gn: https://chromium.googlesource.com/v8/v8.git/+/refs/tags/<version>/DEPS#59
resource "gn" do
url "https://gn.googlesource.com/gn.git",
revision: "4bd1a77e67958fb7f6739bd4542641646f264e5d"
end
resource "v8/base/trace_event/common" do
url "https://chromium.googlesource.com/chromium/src/base/trace_event/common.git",
revision: "147f65333c38ddd1ebf554e89965c243c8ce50b3"
end
resource "v8/build" do
url "https://chromium.googlesource.com/chromium/src/build.git",
revision: "04466898300bf849d1650cb35dcf2eb353e8e1e1"
end
resource "v8/third_party/googletest/src" do
url "https://chromium.googlesource.com/external/github.com/google/googletest.git",
revision: "af29db7ec28d6df1c7f0f745186884091e602e07"
end
resource "v8/third_party/icu" do
url "https://chromium.googlesource.com/chromium/deps/icu.git",
revision: "e8c3bc9ea97d4423ad0515e5f1c064f486dae8b1"
end
resource "v8/third_party/jinja2" do
url "https://chromium.googlesource.com/chromium/src/third_party/jinja2.git",
revision: "264c07d7e64f2874434a3b8039e101ddf1b01e7e"
end
resource "v8/third_party/markupsafe" do
url "https://chromium.googlesource.com/chromium/src/third_party/markupsafe.git",
revision: "13f4e8c9e206567eeb13bf585406ddc574005748"
end
resource "v8/third_party/zlib" do
url "https://chromium.googlesource.com/chromium/src/third_party/zlib.git",
revision: "e6795474e4885ae55b6c6c0a612d0889e2ebd8d9"
end
def install
(buildpath/"build").install resource("v8/build")
(buildpath/"third_party/jinja2").install resource("v8/third_party/jinja2")
(buildpath/"third_party/markupsafe").install resource("v8/third_party/markupsafe")
(buildpath/"third_party/googletest/src").install resource("v8/third_party/googletest/src")
(buildpath/"base/trace_event/common").install resource("v8/base/trace_event/common")
(buildpath/"third_party/icu").install resource("v8/third_party/icu")
(buildpath/"third_party/zlib").install resource("v8/third_party/zlib")
# Build gn from source and add it to the PATH
(buildpath/"gn").install resource("gn")
cd "gn" do
system "python3.11", "build/gen.py"
system "ninja", "-C", "out/", "gn"
end
ENV.prepend_path "PATH", buildpath/"gn/out"
# create gclient_args.gni
(buildpath/"build/config/gclient_args.gni").write <<~EOS
declare_args() {
checkout_google_benchmark = false
}
EOS
# setup gn args
gn_args = {
is_debug: false,
is_component_build: true,
v8_use_external_startup_data: false,
v8_enable_i18n_support: true, # enables i18n support with icu
clang_base_path: "\"#{Formula["llvm"].opt_prefix}\"", # uses Homebrew clang instead of Google clang
clang_use_chrome_plugins: false, # disable the usage of Google's custom clang plugins
use_custom_libcxx: false, # uses system libc++ instead of Google's custom one
treat_warnings_as_errors: false, # ignore not yet supported clang argument warnings
use_lld: false, # upstream use LLD but this leads to build failure on ARM
}
if OS.linux?
gn_args[:is_clang] = false # use GCC on Linux
gn_args[:use_sysroot] = false # don't use sysroot
gn_args[:custom_toolchain] = "\"//build/toolchain/linux/unbundle:default\"" # uses system toolchain
gn_args[:host_toolchain] = "\"//build/toolchain/linux/unbundle:default\"" # to respect passed LDFLAGS
ENV["AR"] = DevelopmentTools.locate("ar")
ENV["NM"] = DevelopmentTools.locate("nm")
gn_args[:use_rbe] = false
end
# Make sure private libraries can be found from lib
ENV.prepend "LDFLAGS", "-Wl,-rpath,#{rpath(target: libexec)}"
# Transform to args string
gn_args_string = gn_args.map { |k, v| "#{k}=#{v}" }.join(" ")
# Build with gn + ninja
system "gn", "gen", "--args=#{gn_args_string}", "out.gn"
system "ninja", "-j", ENV.make_jobs, "-C", "out.gn", "-v", "d8"
# Install libraries and headers into libexec so d8 can find them, and into standard directories
# so other packages can find them and they are linked into HOMEBREW_PREFIX
libexec.install "include"
# Make sure we don't symlink non-headers into `include`.
header_files_and_directories = (libexec/"include").children.select do |child|
(child.extname == ".h") || child.directory?
end
include.install_symlink header_files_and_directories
libexec.install "out.gn/d8", "out.gn/icudtl.dat"
bin.write_exec_script libexec/"d8"
libexec.install Pathname.glob("out.gn/#{shared_library("*")}")
lib.install_symlink libexec.glob(shared_library("libv8*"))
lib.glob("*.TOC").map(&:unlink) if OS.linux? # Remove symlinks to .so.TOC text files
end
test do
assert_equal "Hello World!", shell_output("#{bin}/d8 -e 'print(\"Hello World!\");'").chomp
t = "#{bin}/d8 -e 'print(new Intl.DateTimeFormat(\"en-US\").format(new Date(\"2012-12-20T03:00:00\")));'"
assert_match %r{12/\d{2}/2012}, shell_output(t).chomp
(testpath/"test.cpp").write <<~EOS
#include <libplatform/libplatform.h>
#include <v8.h>
int main(){
static std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform();
v8::V8::InitializePlatform(platform.get());
v8::V8::Initialize();
return 0;
}
EOS
# link against installed libc++
system ENV.cxx, "-std=c++17", "test.cpp",
"-I#{include}", "-L#{lib}",
"-Wl,-rpath,#{libexec}",
"-lv8", "-lv8_libplatform"
end
end