class MinimalRacket < Formula desc "Modern programming language in the Lisp/Scheme family" homepage "https://racket-lang.org/" url "https://mirror.racket-lang.org/installers/9.1/racket-minimal-9.1-src.tgz" sha256 "d68e7f392cc842cf29daee2a8a9297a52881ba280c6a4c6108c02ae8c77357d5" 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_tahoe: "f8e3cfee531b50c4bb5dd5b92566061d9bdf7fabd5d2848e7578d7d416194d63" sha256 arm64_sequoia: "9dcc416b1c09fbafc4f5d6f6e8e516a02ee4885031aff19bb039cb7251c964d5" sha256 arm64_sonoma: "876c55172ce1fdab9d892b490c74e240dcf4d52c1c61fea6305031a4548ca473" sha256 sonoma: "49360583f8d75102cd8d3ccf3e810f5bccf81c867939f373f76f10c058284ee8" sha256 arm64_linux: "6bc1bbf57d83f01e4e77ae53476225c4f1b2b7df61ca0bdb56d17daff6193d7b" sha256 x86_64_linux: "9f5b9e82168584e00339df5624df392ea5005a1d2f5e87faa69d035e22cd661e" end depends_on "openssl@3" uses_from_macos "libffi" on_linux do depends_on "zlib-ng-compat" end # 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" # Link to the Homebrew ssl libraries, overwriting the bundled libraries if OS.mac? openssl = Formula["openssl@3"] racket_libdir = lib/"racket" %w[libssl.3.dylib libcrypto.3.dylib].each do |dylib| path = racket_libdir/dylib path.unlink if path.exist? end ln_s openssl.opt_lib/"libssl.3.dylib", racket_libdir/"libssl.3.dylib" ln_s openssl.opt_lib/"libcrypto.3.dylib", racket_libdir/"libcrypto.3.dylib" end 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