homebrew-core/Formula/deno.rb

91 lines
3.6 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.14.0/deno_src.tar.gz"
sha256 "56f370825f019e4bdb95f354a49576c057f90ef1cc07b7491566763b2147edc6"
license "MIT"
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "c7bb0e7f76f00ae210844079f036b82037b85545ea51b9aef55f458c5ef4255e"
sha256 cellar: :any_skip_relocation, big_sur: "d9589b60d1b5cf3ed83e84f3f789c60ad345c52056aae42d80267d6e497d113a"
sha256 cellar: :any_skip_relocation, catalina: "9e9f0f8ced1e45614bd5dff7c78ae4f0aac0150f47573e01e96aa12835789407"
sha256 cellar: :any_skip_relocation, mojave: "e3265b4cc0cf207347b2676a10054d517c3b9ee98bfec7cb28be5df4a6ce10b0"
sha256 x86_64_linux: "210c7b3301da0bd3e5f800b53ed667fcb8a4918b4a9debe3dabe052c149bc026"
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 "glib"
end
fails_with gcc: "5"
# To find the version of gn used:
# 1. Find rusty_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#{rusty_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