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.2.tar.gz"
|
|
sha256 "6d963a71ef5f6c73faa272a0f81b50e9ddbf814b1ec07e557ce5c95f84d6077e"
|
|
|
|
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: "7a7f9dd94a238cf2cf3ef52d4f599657e68fa20db67bd924928f8b9f639a1950"
|
|
sha256 arm64_big_sur: "a9a3c2d74078ecf21714efc1c21a6c5fb6316f81dca3a7701e5ab8a243d23d0c"
|
|
sha256 monterey: "09afea2b21777b0c89a6c7e24a2a83bbd568bcbfd58d627f4dbc3e4b45f878e0"
|
|
sha256 big_sur: "db50f8a2b4279ba7de96ea9dcbef0aaab679103416c5048b7666a22e9eafc2d3"
|
|
sha256 catalina: "91ba5feee45f416d7d3cb071522b89955c859118320abb83111ab1f234f098cd"
|
|
sha256 x86_64_linux: "3d93258d3fead4f8be2b5a6244f6be342fe05ad85db0fd1eb77f87c8c6ed72df"
|
|
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
|