181 lines
7.5 KiB
Ruby
181 lines
7.5 KiB
Ruby
class V8 < Formula
|
|
desc "Google's JavaScript engine"
|
|
homepage "https://github.com/v8/v8/wiki"
|
|
# Track V8 version from Chrome stable: https://omahaproxy.appspot.com
|
|
url "https://github.com/v8/v8/archive/10.6.194.18.tar.gz"
|
|
sha256 "e852d29e06ab28ba6b97dcf0a401ccab8b2dde0d7f0c91fa487f594d57d641c2"
|
|
license "BSD-3-Clause"
|
|
|
|
livecheck do
|
|
url "https://omahaproxy.appspot.com/all.json?os=mac&channel=stable"
|
|
regex(/"v8_version": "v?(\d+(?:\.\d+)+)"/i)
|
|
end
|
|
|
|
bottle do
|
|
sha256 cellar: :any, arm64_ventura: "491653864182a5fa462689c80815ab2d40bb73cb7c7c9a9a3d01f6b96801d2a6"
|
|
sha256 cellar: :any, arm64_monterey: "5fef057a6447ffa2d2ad9cd362c5c64c48d5ed7a8432834df5dca3becab4a575"
|
|
sha256 cellar: :any, arm64_big_sur: "217d011ef57acee2c6091764a5bee4cfa61fe930e335f9ba565abb12cd944c44"
|
|
sha256 cellar: :any, ventura: "431df01e27cb64e2f1db2cb471f85d74bebfa137a91b8e4aab7d60aca9bda62b"
|
|
sha256 cellar: :any, monterey: "c4a343e6eac3b8f24d65836d8ba9f05a20dd8b3b3345fd6d17767100c0dd8418"
|
|
sha256 cellar: :any, big_sur: "2a5b8a521fa1c976e9b6a951f1b26593a3d9efca6ac16d971e74a3ca70a45e82"
|
|
sha256 cellar: :any, catalina: "fc5affb79c309a261178f6ff0984dab6b8251d2be80d2a37a2db68d907e1de9f"
|
|
sha256 cellar: :any_skip_relocation, x86_64_linux: "8939b81baa665cddf54ed9097eb9b755c27a4ae079474bc57a8dcfd778bc3644"
|
|
end
|
|
|
|
depends_on "ninja" => :build
|
|
depends_on "python@3.10" => :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/10.6.194.17/DEPS#46
|
|
resource "gn" do
|
|
url "https://gn.googlesource.com/gn.git",
|
|
revision: "0bcd37bd2b83f1a9ee17088037ebdfe6eab6d31a"
|
|
end
|
|
|
|
# e.g.: https://chromium.googlesource.com/v8/v8.git/+/refs/tags/10.6.194.17/DEPS#92
|
|
resource "v8/base/trace_event/common" do
|
|
url "https://chromium.googlesource.com/chromium/src/base/trace_event/common.git",
|
|
revision: "2ba7a48ca6167ee8ef311a7f3bc60b5e5cf5ee79"
|
|
end
|
|
|
|
resource "v8/build" do
|
|
url "https://chromium.googlesource.com/chromium/src/build.git",
|
|
revision: "339f8c652787781e6dd39ce0624c1a012f69ece8"
|
|
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: "b3070c52557323463e6b9827e2343e60e1b91f85"
|
|
end
|
|
|
|
resource "v8/third_party/jinja2" do
|
|
url "https://chromium.googlesource.com/chromium/src/third_party/jinja2.git",
|
|
revision: "ee69aa00ee8536f61db6a451f3858745cf587de6"
|
|
end
|
|
|
|
resource "v8/third_party/markupsafe" do
|
|
url "https://chromium.googlesource.com/chromium/src/third_party/markupsafe.git",
|
|
revision: "1b882ef6372b58bfd55a3285f37ed801be9137cd"
|
|
end
|
|
|
|
resource "v8/third_party/zlib" do
|
|
url "https://chromium.googlesource.com/chromium/src/third_party/zlib.git",
|
|
revision: "8d1d3e341948009ed8dc807a545204e7a1854c33"
|
|
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.10", "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
|