143 lines
5.7 KiB
Ruby
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.8.278.17.tar.gz"
|
|
sha256 "58f9fb29a330a30964a978af1cc02c0bf73bff8123b437d87111c9ce9587852a"
|
|
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: "f6c2b9e090e92d4e9eef6b135995bf252b14d98d124ab55939f28ff2fa26e6a9"
|
|
sha256 cellar: :any, big_sur: "e885780347352e0a98fe30c5621030ab58b482faa0c04be9c6c04b9fc7b37c50"
|
|
sha256 cellar: :any, catalina: "3d37fb2a28072ebf8512d0f97211e7b17d0608b147be946047148a3430cdfd45"
|
|
sha256 cellar: :any, mojave: "551645e919115dcaf480727992dd3c9bad9e73a71e4f5e62f750fb0d5586366a"
|
|
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.8.278.17/DEPS#L53
|
|
resource "gn" do
|
|
url "https://gn.googlesource.com/gn.git",
|
|
revision: "53d92014bf94c3893886470a1c7c1289f8818db0"
|
|
end
|
|
|
|
# e.g.: https://github.com/v8/v8/blob/8.8.278.17/DEPS#L94 for the revision of build for v8 8.8.278.17
|
|
resource "v8/build" do
|
|
url "https://chromium.googlesource.com/chromium/src/build.git",
|
|
revision: "2101eff1ac4bfd25f2dfa71ad632a600a38c1ed9"
|
|
end
|
|
|
|
resource "v8/third_party/icu" do
|
|
url "https://chromium.googlesource.com/chromium/deps/icu.git",
|
|
revision: "c2a4cae149aae7fd30c4cbe3cf1b30df03b386f1"
|
|
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: "4fe018038f87675c083d0cfb6a6b57c274fb1753"
|
|
end
|
|
|
|
resource "v8/third_party/jinja2" do
|
|
url "https://chromium.googlesource.com/chromium/src/third_party/jinja2.git",
|
|
revision: "a82a4944a7f2496639f34a89c9923be5908b80aa"
|
|
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: "e84c9a3fd75fdc39055b7ae27d6ec508e50bd39e"
|
|
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
|