127 lines
4.8 KiB
Ruby
127 lines
4.8 KiB
Ruby
class Crystal < Formula
|
|
desc "Fast and statically typed, compiled language with Ruby-like syntax"
|
|
homepage "https://crystal-lang.org/"
|
|
license "Apache-2.0"
|
|
|
|
stable do
|
|
url "https://github.com/crystal-lang/crystal/archive/1.2.1.tar.gz"
|
|
sha256 "fd35d4a9b97d5085afd3276693605f59c452c7ab3fd940af9cd4f72faf4c3aa6"
|
|
|
|
resource "shards" do
|
|
url "https://github.com/crystal-lang/shards/archive/v0.16.0.tar.gz"
|
|
sha256 "e23a51fdcb9747e86b3c58d733a1c7556a78002b46482ca0fdacfe63924dc454"
|
|
end
|
|
end
|
|
|
|
livecheck do
|
|
url :stable
|
|
regex(/^v?(\d+(?:\.\d+)+)$/i)
|
|
end
|
|
|
|
bottle do
|
|
sha256 arm64_monterey: "a6007c31aee6ba42c738d10dbab889424e15afdc7e067cd9e854c2f16c3cffac"
|
|
sha256 arm64_big_sur: "d15da269f1709aa366452de6da5a6f850e98ae1bc66613a02b251145cfa4de8a"
|
|
sha256 monterey: "d94ddefba69d4ea2ab997672b3e70181d47d9581f7183c97a53b8c23c283c8f9"
|
|
sha256 big_sur: "d7bc58fdb974a42911ee545de685fb9e1fb1ee4c444a02d6d801cffed7690225"
|
|
sha256 catalina: "4af8254887a183155d2e67eb69c293bda143afb85dc501b97cfc4eb2c0800151"
|
|
sha256 x86_64_linux: "241042d3623bf4ee1318efcd1bee5d78f6cff67a56f19661acbff16d6772bdd8"
|
|
end
|
|
|
|
head do
|
|
url "https://github.com/crystal-lang/crystal.git"
|
|
|
|
resource "shards" do
|
|
url "https://github.com/crystal-lang/shards.git"
|
|
end
|
|
end
|
|
|
|
depends_on "bdw-gc"
|
|
depends_on "gmp" # std uses it but it's not linked
|
|
depends_on "libevent"
|
|
depends_on "libyaml"
|
|
depends_on "llvm@11"
|
|
depends_on "openssl@1.1" # std uses it but it's not linked
|
|
depends_on "pcre"
|
|
depends_on "pkg-config" # @[Link] will use pkg-config if available
|
|
|
|
# Every new crystal release is built from the previous one. The exceptions are
|
|
# when crystal make a minor release (only bug fixes). Resason is because those
|
|
# bugs could make the compiler from stopping compiling the next compiler.
|
|
#
|
|
# See: https://github.com/Homebrew/homebrew-core/pull/81318
|
|
resource "boot" do
|
|
on_macos do
|
|
url "https://github.com/crystal-lang/crystal/releases/download/1.2.0/crystal-1.2.0-1-darwin-universal.tar.gz"
|
|
version "1.2.0-1"
|
|
sha256 "ce9e671abec489a95df39e347d109e6a99b7388dffe1942b726cb62e2f433ac3"
|
|
end
|
|
on_linux do
|
|
url "https://github.com/crystal-lang/crystal/releases/download/1.1.1/crystal-1.1.1-1-linux-x86_64.tar.gz"
|
|
version "1.1.1-1"
|
|
sha256 "e78873f8185b45f8c6e480a6d2a6a4f3a8b4ee7ca2594e8170dd123a41566704"
|
|
end
|
|
end
|
|
|
|
def install
|
|
(buildpath/"boot").install resource("boot")
|
|
ENV.append_path "PATH", "boot/bin"
|
|
ENV.append_path "CRYSTAL_LIBRARY_PATH", Formula["bdw-gc"].opt_lib
|
|
ENV.append_path "CRYSTAL_LIBRARY_PATH", ENV["HOMEBREW_LIBRARY_PATHS"]
|
|
ENV.append_path "CRYSTAL_LIBRARY_PATH", Formula["libevent"].opt_lib
|
|
ENV.append_path "LLVM_CONFIG", Formula["llvm@11"].opt_bin/"llvm-config"
|
|
|
|
# Build crystal
|
|
crystal_build_opts = []
|
|
crystal_build_opts << "release=true"
|
|
crystal_build_opts << "FLAGS=--no-debug"
|
|
crystal_build_opts << "CRYSTAL_CONFIG_LIBRARY_PATH="
|
|
crystal_build_opts << "CRYSTAL_CONFIG_BUILD_COMMIT=#{Utils.git_short_head}" if build.head?
|
|
(buildpath/".build").mkpath
|
|
system "make", "deps"
|
|
system "make", "crystal", *crystal_build_opts
|
|
|
|
# Build shards (with recently built crystal)
|
|
#
|
|
# Setup the same path the wrapper script would, but just for building shards.
|
|
# NOTE: it seems that the installed crystal in bin/"crystal" can be used while
|
|
# building the formula. Otherwise this ad-hoc setup could be avoided.
|
|
embedded_crystal_path=`"#{buildpath/".build/crystal"}" env CRYSTAL_PATH`.strip
|
|
ENV["CRYSTAL_PATH"] = "#{embedded_crystal_path}:#{buildpath/"src"}"
|
|
|
|
# Install shards
|
|
resource("shards").stage do
|
|
system "make", "bin/shards", "CRYSTAL=#{buildpath/"bin/crystal"}",
|
|
"SHARDS=false",
|
|
"release=true",
|
|
"FLAGS=--no-debug"
|
|
|
|
# Install shards
|
|
bin.install "bin/shards"
|
|
man1.install "man/shards.1"
|
|
man5.install "man/shard.yml.5"
|
|
end
|
|
|
|
# Install crystal
|
|
libexec.install ".build/crystal"
|
|
(bin/"crystal").write <<~SH
|
|
#!/bin/bash
|
|
EMBEDDED_CRYSTAL_PATH=$("#{libexec/"crystal"}" env CRYSTAL_PATH)
|
|
export CRYSTAL_PATH="${CRYSTAL_PATH:-"$EMBEDDED_CRYSTAL_PATH:#{prefix/"src"}"}"
|
|
export CRYSTAL_LIBRARY_PATH="${CRYSTAL_LIBRARY_PATH:+$CRYSTAL_LIBRARY_PATH:}#{HOMEBREW_PREFIX}/lib"
|
|
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH:+$PKG_CONFIG_PATH:}#{Formula["openssl@1.1"].opt_lib/"pkgconfig"}"
|
|
exec "#{libexec/"crystal"}" "${@}"
|
|
SH
|
|
|
|
prefix.install "src"
|
|
|
|
bash_completion.install "etc/completion.bash" => "crystal"
|
|
zsh_completion.install "etc/completion.zsh" => "_crystal"
|
|
|
|
man1.install "man/crystal.1"
|
|
end
|
|
|
|
test do
|
|
assert_match "1", shell_output("#{bin}/crystal eval puts 1")
|
|
end
|
|
end
|