114 lines
4.7 KiB
Ruby
114 lines
4.7 KiB
Ruby
class Deno < Formula
|
|
desc "Secure runtime for JavaScript and TypeScript"
|
|
homepage "https://deno.land/"
|
|
url "https://github.com/denoland/deno/releases/download/v1.29.1/deno_src.tar.gz"
|
|
sha256 "96c9742682307e02e389a01535a9877525b5bcd88e2fa037611e47250c917498"
|
|
license "MIT"
|
|
head "https://github.com/denoland/deno.git", branch: "main"
|
|
|
|
bottle do
|
|
sha256 cellar: :any_skip_relocation, arm64_ventura: "cc9e2a84469ba68477b51d38f8304e74a2325a06369a82405eaae3254c7683c9"
|
|
sha256 cellar: :any_skip_relocation, arm64_monterey: "296b0dfb27ddede6c02d3f285a300a7f2382fc1ec24381f51784c6e7c39a33e9"
|
|
sha256 cellar: :any_skip_relocation, arm64_big_sur: "2c546f96f479baf8c20f2af7663c53cec2d51495bd4b036fb49925ed21be9947"
|
|
sha256 cellar: :any_skip_relocation, ventura: "c507403eeffb6d5eddbef816eedd824424ec4ed36fa9284e4c327bdf3db8a9b5"
|
|
sha256 cellar: :any_skip_relocation, monterey: "3794f62289223713f0be7adf0d6a6e0d03320a036e5a99ee037a9109bc3de7f5"
|
|
sha256 cellar: :any_skip_relocation, big_sur: "f57a47c3a5a4e9c4a0b582a4bd4665730fa98ac24d9742fd8612010b287a4f58"
|
|
sha256 cellar: :any_skip_relocation, x86_64_linux: "7d8e365745d65c08891fb1dd4289357b929b50896fcff1144ad46cd871409928"
|
|
end
|
|
|
|
depends_on "llvm" => :build
|
|
depends_on "ninja" => :build
|
|
depends_on "python@3.11" => :build
|
|
depends_on "rust" => :build
|
|
|
|
uses_from_macos "xz"
|
|
|
|
on_macos do
|
|
depends_on xcode: ["10.0", :build] # required by v8 7.9+
|
|
end
|
|
|
|
on_linux do
|
|
depends_on "pkg-config" => :build
|
|
depends_on "glib"
|
|
end
|
|
|
|
fails_with gcc: "5"
|
|
|
|
# Temporary resources to work around build failure due to files missing from crate
|
|
# We use the crate as GitHub tarball lacks submodules and this allows us to avoid git overhead.
|
|
# TODO: Remove this and `v8` resource when https://github.com/denoland/rusty_v8/pull/1063 is released
|
|
resource "rusty-v8" do
|
|
url "https://static.crates.io/crates/v8/v8-0.60.0.crate"
|
|
sha256 "5867543c19b87c45ed3f2bc49eb6135474ed6a1803cac40c278620b53e9865ef"
|
|
end
|
|
|
|
resource "v8" do
|
|
url "https://github.com/denoland/v8/archive/05fb6e97fc6c5fdd2e79e4f9a51c5bf0ca0ef991.tar.gz"
|
|
sha256 "a083d815b21b0a2a59d1f133fd897c1f803f1418cfdffd411a89583bf37f22a8"
|
|
end
|
|
|
|
# To find the version of gn used:
|
|
# 1. Find v8 version: https://github.com/denoland/deno/blob/v#{version}/Cargo.toml#L43
|
|
# 2. Find ninja_gn_binaries tag: https://github.com/denoland/rusty_v8/tree/v#{v8_version}/tools/ninja_gn_binaries.py
|
|
# 3. Find short gn commit hash from commit message: https://github.com/denoland/ninja_gn_binaries/tree/#{ninja_gn_binaries_tag}
|
|
# 4. Find full gn commit hash: https://gn.googlesource.com/gn.git/+/#{gn_commit}
|
|
resource "gn" do
|
|
url "https://gn.googlesource.com/gn.git",
|
|
revision: "bf4e17dc67b2a2007475415e3f9e1d1cf32f6e35"
|
|
end
|
|
|
|
def install
|
|
# Work around files missing from crate
|
|
# TODO: Remove this at the same time as `rusty-v8` + `v8` resources
|
|
(buildpath/"v8").mkpath
|
|
resource("rusty-v8").stage do |r|
|
|
system "tar", "--strip-components", "1", "-xzvf", "v8-#{r.version}.crate", "-C", buildpath/"v8"
|
|
end
|
|
resource("v8").stage do
|
|
cp_r "tools/builtins-pgo", buildpath/"v8/v8/tools/builtins-pgo"
|
|
end
|
|
inreplace "Cargo.toml",
|
|
/^v8 = { version = ("[\d.]+"),.*}$/,
|
|
"v8 = { version = \\1, path = \"./v8\" }"
|
|
|
|
if OS.mac? && (MacOS.version < :mojave)
|
|
# Overwrite Chromium minimum SDK version of 10.15
|
|
ENV["FORCE_MAC_SDK_MIN"] = MacOS.version
|
|
end
|
|
|
|
python3 = "python3.11"
|
|
# env args for building a release build with our python3, ninja and gn
|
|
ENV.prepend_path "PATH", Formula["python@3.11"].libexec/"bin"
|
|
ENV["PYTHON"] = Formula["python@3.11"].opt_bin/python3
|
|
ENV["GN"] = buildpath/"gn/out/gn"
|
|
ENV["NINJA"] = Formula["ninja"].opt_bin/"ninja"
|
|
# build rusty_v8 from source
|
|
ENV["V8_FROM_SOURCE"] = "1"
|
|
# Build with llvm and link against system libc++ (no runtime dep)
|
|
ENV["CLANG_BASE_PATH"] = Formula["llvm"].prefix
|
|
|
|
resource("gn").stage buildpath/"gn"
|
|
cd "gn" do
|
|
system python3, "build/gen.py"
|
|
system "ninja", "-C", "out"
|
|
end
|
|
|
|
# cargo seems to build rusty_v8 twice in parallel, which causes problems,
|
|
# hence the need for -j1
|
|
# Issue ref: https://github.com/denoland/deno/issues/9244
|
|
system "cargo", "install", "-vv", "-j1", *std_cargo_args(path: "cli")
|
|
|
|
generate_completions_from_executable(bin/"deno", "completions")
|
|
end
|
|
|
|
test do
|
|
(testpath/"hello.ts").write <<~EOS
|
|
console.log("hello", "deno");
|
|
EOS
|
|
assert_match "hello deno", shell_output("#{bin}/deno run hello.ts")
|
|
assert_match "console.log",
|
|
shell_output("#{bin}/deno run --allow-read=#{testpath} https://deno.land/std@0.50.0/examples/cat.ts " \
|
|
"#{testpath}/hello.ts")
|
|
end
|
|
end
|