homebrew-core/Formula/ghc.rb

112 lines
4.3 KiB
Ruby

class Ghc < Formula
desc "Glorious Glasgow Haskell Compilation System"
homepage "https://haskell.org/ghc/"
url "https://downloads.haskell.org/~ghc/9.2.4/ghc-9.2.4-src.tar.xz"
sha256 "15213888064a0ec4e7723d075f31b87a678ce0851773d58b44ef7aa3de996458"
# We build bundled copies of libffi and GMP so GHC inherits the licenses
license all_of: [
"BSD-3-Clause",
"MIT", # libffi
any_of: ["LGPL-3.0-or-later", "GPL-2.0-or-later"], # GMP
]
livecheck do
url "https://www.haskell.org/ghc/download.html"
regex(/href=.*?download[._-]ghc[._-][^"' >]+?\.html[^>]*?>\s*?v?(\d+(?:\.\d+)+)\s*?</i)
end
bottle do
sha256 cellar: :any, arm64_monterey: "e561c3b8ae12ab2a7b94a09b3c3b5895b9684a08eb136d484c9924e6d1f1efa2"
sha256 cellar: :any, arm64_big_sur: "4673cdb3ffc12715c76c1531c6b67f2bb76c2b0f46857d89037971fcfccdfd69"
sha256 ventura: "44380e395bfd793fe5bd194b7ad5297f367bd8a9a33e0c663f7670c533b94a52"
sha256 monterey: "9958adc0fe9861b032206d1d08f1b3ffc2d1db10ac3ca75c470ef1db03cc54c0"
sha256 big_sur: "2aaeb6627b6266759a3812ce9a1ffdbf82067dc1ade27736f0ec74706bc5870e"
sha256 catalina: "e32a672210b61c79a293e64040a6135f78617de5ee8d1f9e0ea83ee8fd11015f"
sha256 cellar: :any_skip_relocation, x86_64_linux: "66de55e420c039535422aed4c7803285faedf5292dd2385f6b7d7bcc5d899d94"
end
depends_on "python@3.10" => :build
depends_on "sphinx-doc" => :build
depends_on macos: :catalina
uses_from_macos "m4" => :build
uses_from_macos "ncurses"
on_linux do
depends_on "gmp" => :build
end
# GHC 9.2.4 user manual recommend use LLVM 9 through 12
# https://downloads.haskell.org/~ghc/9.2.4/docs/html/users_guide/9.2.4-notes.html
# and we met some unknown issue w/ LLVM 13 before https://gitlab.haskell.org/ghc/ghc/-/issues/20559
# so conservatively use LLVM 12 here
on_arm do
depends_on "llvm@12"
end
# https://www.haskell.org/ghc/download_ghc_9_0_2.html#macosx_x86_64
# "This is a distribution for Mac OS X, 10.7 or later."
# A binary of ghc is needed to bootstrap ghc
resource "binary" do
on_macos do
on_intel do
url "https://downloads.haskell.org/~ghc/9.0.2/ghc-9.0.2-x86_64-apple-darwin.tar.xz"
sha256 "e1fe990eb987f5c4b03e0396f9c228a10da71769c8a2bc8fadbc1d3b10a0f53a"
end
on_arm do
url "https://downloads.haskell.org/~ghc/9.0.2/ghc-9.0.2-aarch64-apple-darwin.tar.xz"
sha256 "b1fcab17fe48326d2ff302d70c12bc4cf4d570dfbbce68ab57c719cfec882b05"
end
end
on_linux do
url "https://downloads.haskell.org/~ghc/9.0.2/ghc-9.0.2-x86_64-ubuntu20.04-linux.tar.xz"
sha256 "a0ff9893618d597534682123360e7c80f97441f0e49f261828416110e8348ea0"
end
end
def install
ENV["CC"] = ENV.cc
ENV["LD"] = "ld"
ENV["PYTHON"] = which("python3.10")
# Work around build failure: fatal error: 'ffitarget_arm64.h' file not found
# Issue ref: https://gitlab.haskell.org/ghc/ghc/-/issues/20592
# TODO: remove once bootstrap ghc is 9.2.3 or later.
ENV.append_path "C_INCLUDE_PATH", "#{MacOS.sdk_path_if_needed}/usr/include/ffi" if OS.mac? && Hardware::CPU.arm?
resource("binary").stage do
binary = buildpath/"binary"
binary_args = []
if OS.linux?
binary_args << "--with-gmp-includes=#{Formula["gmp"].opt_include}"
binary_args << "--with-gmp-libraries=#{Formula["gmp"].opt_lib}"
end
system "./configure", "--prefix=#{binary}", *binary_args
ENV.deparallelize { system "make", "install" }
ENV.prepend_path "PATH", binary/"bin"
end
system "./configure", "--prefix=#{prefix}", "--disable-numa", "--with-intree-gmp"
system "make"
ENV.deparallelize { system "make", "install" }
bash_completion.install "utils/completion/ghc.bash" => "ghc"
(lib/"ghc-#{version}/package.conf.d/package.cache").unlink
(lib/"ghc-#{version}/package.conf.d/package.cache.lock").unlink
bin.env_script_all_files libexec, PATH: "${PATH}:#{Formula["llvm@12"].opt_bin}" if Hardware::CPU.arm?
end
def post_install
system "#{bin}/ghc-pkg", "recache"
end
test do
(testpath/"hello.hs").write('main = putStrLn "Hello Homebrew"')
assert_match "Hello Homebrew", shell_output("#{bin}/runghc hello.hs")
end
end