|
| 1 | +class GhcAT910 < Formula |
| 2 | + desc "Glorious Glasgow Haskell Compilation System" |
| 3 | + homepage "https://haskell.org/ghc/" |
| 4 | + url "https://downloads.haskell.org/~ghc/9.10.1/ghc-9.10.1-src.tar.xz" |
| 5 | + sha256 "bf386a302d4ee054791ffd51748900f15d71760fd199157922d120cc1f89e2f7" |
| 6 | + # We build bundled copies of libffi and GMP so GHC inherits the licenses |
| 7 | + license all_of: [ |
| 8 | + "BSD-3-Clause", |
| 9 | + "MIT", # libffi |
| 10 | + any_of: ["LGPL-3.0-or-later", "GPL-2.0-or-later"], # GMP |
| 11 | + ] |
| 12 | + |
| 13 | + livecheck do |
| 14 | + url "https://www.haskell.org/ghc/download.html" |
| 15 | + regex(/href=.*?download[._-]ghc[._-][^"' >]+?\.html[^>]*?>\s*?v?(9\.10(?:\.\d+)+)\s*?</i) |
| 16 | + end |
| 17 | + |
| 18 | + bottle do |
| 19 | + sha256 cellar: :any, arm64_sequoia: "ec9bf60301efe6176480908497e6bbcf760c8933cb6e7e5f37ebb974511503ad" |
| 20 | + sha256 cellar: :any, arm64_sonoma: "6adabdb9471ae60464844e605ea1b125072093c3545bbb6be58c97e068e4b179" |
| 21 | + sha256 cellar: :any, arm64_ventura: "7873d62ffe85f56f79253dd01207e5d2ff9d517327908d24df0cddf0507a894d" |
| 22 | + sha256 cellar: :any, sonoma: "468cb6b1d315ee7666776732ff81810ef758fafab73cb9e4625f2eae4eec6b53" |
| 23 | + sha256 cellar: :any, ventura: "bdb6eb7758ff9cbe21ddd04b686adde591cccf4cc783f61f6dbd748d1d717d51" |
| 24 | + sha256 cellar: :any_skip_relocation, x86_64_linux: "7094724850adb80577444deb76d26cd865c71f45d6afaae2f92cb9809cf7fd76" |
| 25 | + end |
| 26 | + |
| 27 | + keg_only :versioned_formula |
| 28 | + |
| 29 | + depends_on "autoconf" => :build |
| 30 | + depends_on "automake" => :build |
| 31 | + depends_on "[email protected]" => :build |
| 32 | + depends_on "sphinx-doc" => :build |
| 33 | + depends_on "xz" => :build |
| 34 | + |
| 35 | + uses_from_macos "m4" => :build |
| 36 | + uses_from_macos "ncurses" |
| 37 | + |
| 38 | + # Build uses sed -r option, which is not available in Catalina shipped sed. |
| 39 | + on_catalina :or_older do |
| 40 | + depends_on "gnu-sed" => :build |
| 41 | + end |
| 42 | + |
| 43 | + on_linux do |
| 44 | + depends_on "gmp" => :build |
| 45 | + end |
| 46 | + |
| 47 | + # A binary of ghc is needed to bootstrap ghc |
| 48 | + resource "binary" do |
| 49 | + on_macos do |
| 50 | + on_arm do |
| 51 | + url "https://downloads.haskell.org/~ghc/9.8.2/ghc-9.8.2-aarch64-apple-darwin.tar.xz" |
| 52 | + sha256 "67be089dedbe599d911efd8f82e4f9a19225761a3872be74dfd4b5a557fb8e1a" |
| 53 | + end |
| 54 | + on_intel do |
| 55 | + url "https://downloads.haskell.org/~ghc/9.8.2/ghc-9.8.2-x86_64-apple-darwin.tar.xz" |
| 56 | + sha256 "64e8cca6310443cd6de8255edcf391d937829792e701167f7e5fb234f7150078" |
| 57 | + end |
| 58 | + end |
| 59 | + on_linux do |
| 60 | + on_arm do |
| 61 | + url "https://downloads.haskell.org/~ghc/9.8.2/ghc-9.8.2-aarch64-deb10-linux.tar.xz" |
| 62 | + sha256 "9a3776fd8dc02f95b751f0e44823d6727dea2c212857e2c5c5f6a38a034d1575" |
| 63 | + end |
| 64 | + on_intel do |
| 65 | + url "https://downloads.haskell.org/~ghc/9.8.2/ghc-9.8.2-x86_64-ubuntu20_04-linux.tar.xz" |
| 66 | + sha256 "a65a4726203c606b58a7f6b714a576e7d81390158c8afa0dece3841a4c602de2" |
| 67 | + end |
| 68 | + end |
| 69 | + end |
| 70 | + |
| 71 | + resource "cabal-install" do |
| 72 | + on_macos do |
| 73 | + on_arm do |
| 74 | + url "https://downloads.haskell.org/~cabal/cabal-install-3.12.1.0/cabal-install-3.12.1.0-aarch64-darwin.tar.xz" |
| 75 | + sha256 "9c165ca9a2e593b12dbb0eca92c0b04f8d1c259871742d7e9afc352364fe7a3f" |
| 76 | + end |
| 77 | + on_intel do |
| 78 | + url "https://downloads.haskell.org/~cabal/cabal-install-3.12.1.0/cabal-install-3.12.1.0-x86_64-darwin.tar.xz" |
| 79 | + sha256 "e89392429f59bbcfaf07e1164e55bc63bba8e5c788afe43c94e00b515c1578af" |
| 80 | + end |
| 81 | + end |
| 82 | + on_linux do |
| 83 | + on_arm do |
| 84 | + url "https://downloads.haskell.org/~cabal/cabal-install-3.12.1.0/cabal-install-3.12.1.0-aarch64-linux-deb10.tar.xz" |
| 85 | + sha256 "c01f2e0b3ba1fe4104cf2933ee18558a9b81d85831a145e8aba33fa172c7c618" |
| 86 | + end |
| 87 | + on_intel do |
| 88 | + url "https://downloads.haskell.org/~cabal/cabal-install-3.12.1.0/cabal-install-3.12.1.0-x86_64-linux-ubuntu20_04.tar.xz" |
| 89 | + sha256 "3724f2aa22f330c5e6605978f3dd9adee4e052866321a8dd222944cd178c3c24" |
| 90 | + end |
| 91 | + end |
| 92 | + end |
| 93 | + |
| 94 | + # Backport fix to avoid unnecessary `alex` dependency |
| 95 | + patch do |
| 96 | + url "https://gitlab.haskell.org/ghc/ghc/-/commit/aba2c9d4728262cd9a2d711eded9050ac131c6c1.diff" |
| 97 | + sha256 "152cd2711a7e103bbf0526dc62e51b437e6c60e26149f2cd50ccafaa057316ce" |
| 98 | + end |
| 99 | + |
| 100 | + def install |
| 101 | + # ENV.cc and ENV.cxx return specific compiler versions on Ubuntu, e.g. |
| 102 | + # gcc-11 and g++-11 on Ubuntu 22.04. Using such values effectively causes |
| 103 | + # the bottle (binary package) to only run on systems where gcc-11 and g++-11 |
| 104 | + # binaries are available. This breaks on many systems including Arch Linux, |
| 105 | + # Fedora and Ubuntu 24.04, as they provide g** but not g**-11 specifically. |
| 106 | + # |
| 107 | + # The workaround here is to hard-code both CC and CXX on Linux. |
| 108 | + ENV["CC"] = ENV["ac_cv_path_CC"] = OS.linux? ? "cc" : ENV.cc |
| 109 | + ENV["CXX"] = ENV["ac_cv_path_CXX"] = OS.linux? ? "c++" : ENV.cxx |
| 110 | + ENV["LD"] = ENV["MergeObjsCmd"] = "ld" |
| 111 | + ENV["PYTHON"] = which("python3.13") |
| 112 | + |
| 113 | + binary = buildpath/"binary" |
| 114 | + resource("binary").stage do |
| 115 | + binary_args = [] |
| 116 | + if OS.linux? |
| 117 | + binary_args << "--with-gmp-includes=#{Formula["gmp"].opt_include}" |
| 118 | + binary_args << "--with-gmp-libraries=#{Formula["gmp"].opt_lib}" |
| 119 | + end |
| 120 | + |
| 121 | + system "./configure", "--prefix=#{binary}", *binary_args |
| 122 | + ENV.deparallelize { system "make", "install" } |
| 123 | + end |
| 124 | + |
| 125 | + ENV.prepend_path "PATH", binary/"bin" |
| 126 | + # Build uses sed -r option, which is not available in Catalina shipped sed. |
| 127 | + ENV.prepend_path "PATH", Formula["gnu-sed"].libexec/"gnubin" if OS.mac? && MacOS.version <= :catalina |
| 128 | + |
| 129 | + resource("cabal-install").stage { (binary/"bin").install "cabal" } |
| 130 | + system "cabal", "v2-update" |
| 131 | + |
| 132 | + args = [] |
| 133 | + if OS.mac? |
| 134 | + # https://gitlab.haskell.org/ghc/ghc/-/issues/22595#note_468423 |
| 135 | + args << "--with-ffi-libraries=#{MacOS.sdk_path_if_needed}/usr/lib" |
| 136 | + args << "--with-ffi-includes=#{MacOS.sdk_path_if_needed}/usr/include/ffi" |
| 137 | + args << "--with-system-libffi" |
| 138 | + end |
| 139 | + |
| 140 | + system "./configure", "--prefix=#{prefix}", "--disable-numa", "--with-intree-gmp", *args |
| 141 | + hadrian_args = %W[ |
| 142 | + -j#{ENV.make_jobs} |
| 143 | + --prefix=#{prefix} |
| 144 | + --flavour=release |
| 145 | + --docs=no-sphinx-pdfs |
| 146 | + ] |
| 147 | + # Let hadrian handle its own parallelization |
| 148 | + ENV.deparallelize { system "hadrian/build", "install", *hadrian_args } |
| 149 | + |
| 150 | + bash_completion.install "utils/completion/ghc.bash" => "ghc" |
| 151 | + (lib/"ghc-#{version}/lib/package.conf.d/package.cache").unlink |
| 152 | + (lib/"ghc-#{version}/lib/package.conf.d/package.cache.lock").unlink |
| 153 | + end |
| 154 | + |
| 155 | + def post_install |
| 156 | + system bin/"ghc-pkg", "recache" |
| 157 | + end |
| 158 | + |
| 159 | + test do |
| 160 | + (testpath/"hello.hs").write('main = putStrLn "Hello Homebrew"') |
| 161 | + assert_match "Hello Homebrew", shell_output("#{bin}/runghc hello.hs") |
| 162 | + end |
| 163 | +end |
0 commit comments