homebrew-core/Formula/v8.rb

143 lines
5.7 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/8.9.255.20.tar.gz"
sha256 "8081813a99a78941134de1491512d4b80ba0756e017069149bceb8eb357cdf3d"
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_big_sur: "96314008550f62d3cdf99744fd862a5fbfc631ea2a52694152e0efba88b5de58"
sha256 cellar: :any, big_sur: "83602cc93d59351c0365e7c8650d0b09fd251c3ebf4f77c648233200e8ef7f44"
sha256 cellar: :any, catalina: "1eae1b0bc93dfe83d8f9437417ec32c0ac90a2beb184c5b3076ab5234d2d1536"
sha256 cellar: :any, mojave: "26672c3f328d0e9ffc5f8a7a553f5b7b98bcfea22aa1831f49125d42635bbd53"
end
depends_on "llvm" => :build
depends_on "ninja" => :build
depends_on xcode: ["10.0", :build] # required by v8
# Look up the correct resource revisions in the DEP file of the specific releases tag
# e.g. for CIPD dependency gn: https://github.com/v8/v8/blob/8.9.255.20/DEPS#L50
resource "gn" do
url "https://gn.googlesource.com/gn.git",
revision: "595e3be7c8381d4eeefce62a63ec12bae9ce5140"
end
# e.g.: https://github.com/v8/v8/blob/8.9.255.20/DEPS#L91 for the revision of build for v8 8.9.255.20
resource "v8/build" do
url "https://chromium.googlesource.com/chromium/src/build.git",
revision: "d5995537211ebc4d1bc37f215c25fa3781ba9d6e"
end
resource "v8/third_party/icu" do
url "https://chromium.googlesource.com/chromium/deps/icu.git",
revision: "899e18383fd732b47e6978db2b960a1b2a80179b"
end
resource "v8/base/trace_event/common" do
url "https://chromium.googlesource.com/chromium/src/base/trace_event/common.git",
revision: "eb94f1c7aa96207f469008f29989a43feb2718f8"
end
resource "v8/third_party/googletest/src" do
url "https://chromium.googlesource.com/external/github.com/google/googletest.git",
revision: "1b0cdaae57c046c87fb99cb4f69c312a7e794adb"
end
resource "v8/third_party/jinja2" do
url "https://chromium.googlesource.com/chromium/src/third_party/jinja2.git",
revision: "11b6b3e5971d760bd2d310f77643f55a818a6d25"
end
resource "v8/third_party/markupsafe" do
url "https://chromium.googlesource.com/chromium/src/third_party/markupsafe.git",
revision: "0944e71f4b2cb9a871bcbe353f95e889b64a611a"
end
resource "v8/third_party/zlib" do
url "https://chromium.googlesource.com/chromium/src/third_party/zlib.git",
revision: "2c183c9f93a328bfb3121284da13cf89a0f7e64a"
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 "python", "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 clang from homebrew llvm formula, because the system clang is unreliable
ENV.remove "HOMEBREW_LIBRARY_PATHS", Formula["llvm"].opt_lib # but link against system libc++
# 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 all the things
(libexec/"include").install Dir["include/*"]
libexec.install Dir["out.gn/lib*.dylib", "out.gn/d8", "out.gn/icudtl.dat"]
bin.write_exec_script libexec/"d8"
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++14", "test.cpp",
"-I#{libexec}/include",
"-L#{libexec}", "-lv8", "-lv8_libplatform"
end
end