homebrew-core/Formula/deno.rb

93 lines
3.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.19.0/deno_src.tar.gz"
sha256 "46eb0f8db206393fcddf600b929d47492a1d73f4487eacddad5cf33173bce4f3"
license "MIT"
bottle do
sha256 cellar: :any_skip_relocation, arm64_monterey: "c7010ebf7bf149c2c2a6e3300def96e0c42653a96332ef5a5af10056193af527"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "f88bc56f98aa0cbecbc820c486ca2479e469f04581095a6568d0f8e682914e78"
sha256 cellar: :any_skip_relocation, monterey: "3b9bc5190a086240c2465fb6fbe10f656b491fa027c3d13957bf0c1064ce44f2"
sha256 cellar: :any_skip_relocation, big_sur: "95b4adb5972f1c14cf53bbac232b457ff445b35dd99bb56b69aef11bd3924e04"
sha256 cellar: :any_skip_relocation, catalina: "6ce97e063e4361bdbcf3826f19d3a4988a102be1ad3c7d67724ecc74b805a8ec"
sha256 x86_64_linux: "874a31da44a1a53d8510e4c1c6f91d08df6d70b149101d015a35edd867b05ebe"
end
depends_on "llvm" => :build
depends_on "ninja" => :build
depends_on "python@3.9" => :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 "gcc"
depends_on "glib"
end
fails_with gcc: "5"
# To find the version of gn used:
# 1. Find v8 version: https://github.com/denoland/deno/blob/v#{version}/core/Cargo.toml
# 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: "53d92014bf94c3893886470a1c7c1289f8818db0"
end
def install
if OS.mac? && (MacOS.version < :mojave)
# Overwrite Chromium minimum SDK version of 10.15
ENV["FORCE_MAC_SDK_MIN"] = MacOS.version
end
# env args for building a release build with our python3, ninja and gn
ENV.prepend_path "PATH", Formula["python@3.9"].libexec/"bin"
ENV["PYTHON"] = Formula["python@3.9"].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
ENV.remove "HOMEBREW_LIBRARY_PATHS", Formula["llvm"].opt_lib
resource("gn").stage buildpath/"gn"
cd "gn" do
system "python3", "build/gen.py"
system "ninja", "-C", "out"
end
cd "cli" do
# cargo seems to build rusty_v8 twice in parallel, which causes problems,
# hence the need for -j1
system "cargo", "install", "-vv", "-j1", *std_cargo_args
end
bash_output = Utils.safe_popen_read(bin/"deno", "completions", "bash")
(bash_completion/"deno").write bash_output
zsh_output = Utils.safe_popen_read(bin/"deno", "completions", "zsh")
(zsh_completion/"_deno").write zsh_output
fish_output = Utils.safe_popen_read(bin/"deno", "completions", "fish")
(fish_completion/"deno.fish").write fish_output
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