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.18.2/deno_src.tar.gz"
sha256 "fe2d6857d17071b6920102c13a15cc4db7e45b80a063554a12dba25ee310f77e"
license "MIT"
bottle do
sha256 cellar: :any_skip_relocation, arm64_monterey: "6bcc5bba72ac78800c7e909a3de38519821ba9548fdc800fcb68e5280757d96a"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "41768e2a0f65043fc07571b244ad1c49a1b768c9e436bf066fa4e729df409439"
sha256 cellar: :any_skip_relocation, monterey: "9cc58e3229f841e450365023084fc2cf8f3313d0731f891e6126628310016479"
sha256 cellar: :any_skip_relocation, big_sur: "42dfe4e5408ca15c6b400d645a02a9d21bda5be71899832e9dce9c29799f9f79"
sha256 cellar: :any_skip_relocation, catalina: "dea0f0c5092e20f566f03915051566c44a932cbfec0d796a3399a547262decc6"
sha256 x86_64_linux: "79a6c45b83554c05db0c55659907258c388200c43c3280da8bbba98211146f41"
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