homebrew-core/Formula/crystal.rb

121 lines
4.3 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"
revision 1
stable do
url "https://github.com/crystal-lang/crystal/archive/1.0.0.tar.gz"
sha256 "6b85c9139a891732c1f10638030635ff9dbe4e6818cad81a5dbd72db40913019"
resource "shards" do
url "https://github.com/crystal-lang/shards/archive/v0.14.1.tar.gz"
sha256 "040b080acb4d4d44bfe07897219fdcb7525f783e253d8878d8381bf78f13f328"
end
end
livecheck do
url :stable
regex(/^v?(\d+(?:\.\d+)+)$/i)
end
bottle do
sha256 big_sur: "a5deb38c8911b4d8aea515981a4f485e0235ce47c8a606b569288d084a75120e"
sha256 catalina: "f1e79efb22b37d85ddcfd02e689ca0d31bbb3e32997f43c1171b66c6487ea912"
sha256 mojave: "b9d9b425b670df3fdbd89f2cd368bf95185626be94dc28359d0e3f38113d6d5b"
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"
# NOTE: Using llvm@11 is possible but compiling in release mode
# has currently a known issue https://github.com/crystal-lang/crystal/issues/10359
depends_on "llvm@9"
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
resource "boot" do
on_macos do
url "https://github.com/crystal-lang/crystal/releases/download/0.36.1/crystal-0.36.1-1-darwin-x86_64.tar.gz"
version "0.36.1-1"
sha256 "3b381d4ac1241514d63b1f243ed183a1b10945b0e77c5dd625067e91a657ef75"
end
on_linux do
url "https://github.com/crystal-lang/crystal/releases/download/0.36.1/crystal-0.36.1-1-linux-x86_64.tar.gz"
version "0.36.1-1"
sha256 "38cc7514f8d9e463665ebaf7232d3a6c46a7397fc9ff5c05fd0f9e4706febb18"
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 "LLVM_CONFIG", Formula["llvm@9"].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