class MinimalRacket < Formula desc "Modern programming language in the Lisp/Scheme family" homepage "https://racket-lang.org/" url "https://mirror.racket-lang.org/installers/8.17/racket-minimal-8.17-src.tgz" sha256 "4acb365869290881fa07c69588cfa8b2dc1000bdc69955d70964b0b1e76b71ba" license any_of: ["MIT", "Apache-2.0"] # File links on the download page are created using JavaScript, so we parse # the filename from a string in an object. We match the version from the # "Unix Source + built packages" option, as the `racket-minimal` archive is # only found on the release page for a given version (e.g., `/releases/8.0/`). livecheck do url "https://download.racket-lang.org/" regex(/["'][^"']*?racket(?:-minimal)?[._-]v?(\d+(?:\.\d+)+)-src\.t/i) end bottle do sha256 arm64_sequoia: "94233ccf4855529eb037fbb967af7f8c86744c5f29c28295608777e4638ac64f" sha256 arm64_sonoma: "a3d27bb96382f5d0d8bec7d81f7b19748fa33c3619a33b73afe1090d88bc6cea" sha256 arm64_ventura: "9cefe4eeec12b2336be7ac7da5e6f2c2c840e9a41678c32caf88e92db2d73089" sha256 sonoma: "50070f5a19ea226744524551a8a2c0946d23e261ab06a968993f0e75c78d10cb" sha256 ventura: "9b14e9c9c57cc4f73303ee360ef582689cf7139b447c87490c5521b82a42daec" sha256 arm64_linux: "bbda2f3defd23d8983ef8be7634df86c4b2e25d8aeca609490927a91aa781d5c" sha256 x86_64_linux: "3ede573d7078a9acbf249fa05fc5221fa667ea13a4334a1e13bed8705bb7cdd0" end depends_on "openssl@3" uses_from_macos "libffi" uses_from_macos "zlib" # these two files are amended when (un)installing packages skip_clean "lib/racket/launchers.rktd", "lib/racket/mans.rktd" def racket_config etc/"racket/config.rktd" end def install # configure racket's package tool (raco) to do the Right Thing # see: https://docs.racket-lang.org/raco/config-file.html inreplace "etc/config.rktd", /\)\)\n$/, ") (default-scope . \"installation\"))\n" # Prioritise OpenSSL 3 over OpenSSL 1.1. inreplace %w[libssl.rkt libcrypto.rkt].map { |file| buildpath/"collects/openssl"/file }, '"1.1"', '"3"' cd "src" do args = %W[ --disable-debug --disable-dependency-tracking --enable-origtree=no --enable-macprefix --prefix=#{prefix} --mandir=#{man} --sysconfdir=#{etc} --enable-useprefix ] ENV["LDFLAGS"] = "-rpath #{Formula["openssl@3"].opt_lib}" ENV["LDFLAGS"] = "-Wl,-rpath=#{Formula["openssl@3"].opt_lib}" if OS.linux? system "./configure", *args system "make" system "make", "install" end inreplace racket_config, prefix, opt_prefix end def post_install # Run raco setup to make sure core libraries are properly compiled. # Sometimes the mtimes of .rkt and .zo files are messed up after a fresh # install, making Racket take 15s to start up because interpreting is slow. system bin/"raco", "setup" return unless racket_config.read.include?(HOMEBREW_CELLAR) ohai "Fixing up Cellar references in #{racket_config}..." inreplace racket_config, %r{#{Regexp.escape(HOMEBREW_CELLAR)}/minimal-racket/[^/]}o, opt_prefix end def caveats <<~EOS This is a minimal Racket distribution. If you want to build the DrRacket IDE, you may run: raco pkg install --auto drracket The full Racket distribution is available as a cask: brew install --cask racket EOS end test do output = shell_output("#{bin}/racket -e '(displayln \"Hello Homebrew\")'") assert_match "Hello Homebrew", output # show that the config file isn't malformed output = shell_output("'#{bin}/raco' pkg config") assert $CHILD_STATUS.success? assert_match Regexp.new(<<~EOS), output ^name: #{version} catalogs: https://download.racket-lang.org/releases/#{version}/catalog/ https://pkgs.racket-lang.org https://planet-compats.racket-lang.org default-scope: installation EOS # ensure Homebrew openssl is used if OS.mac? output = shell_output("DYLD_PRINT_LIBRARIES=1 #{bin}/racket -e '(require openssl)' 2>&1") assert_match(%r{.*openssl@3/.*/libssl.*\.dylib}, output) else output = shell_output("LD_DEBUG=libs #{bin}/racket -e '(require openssl)' 2>&1") assert_match "init: #{Formula["openssl@3"].opt_lib/shared_library("libssl")}", output end end end