class Ldc < Formula desc "Portable D programming language compiler" homepage "https://wiki.dlang.org/LDC" url "https://github.com/ldc-developers/ldc/releases/download/v1.30.0/ldc-1.30.0-src.tar.gz" sha256 "fdbb376f08242d917922a6a22a773980217fafa310046fc5d6459490af23dacd" license "BSD-3-Clause" revision 1 head "https://github.com/ldc-developers/ldc.git", branch: "master" livecheck do url :stable strategy :github_latest end bottle do sha256 arm64_monterey: "51fa3cac2b7a1cf24ccd2513ac717558bad15ab0bf372d77f9e533a6e206a5e6" sha256 arm64_big_sur: "44edf489e8c3cc251e5aaaa54500b68048f403a8bcf921ab15e1a08a309d14e9" sha256 monterey: "06b057c83bfc5915fdf4ce3e5ce0c9769324a2540616174adde6b39b5840c43a" sha256 big_sur: "ec17a74f6430156728ecc45e79c51ff3537b95cb124b1ca33713a15bf634c250" sha256 catalina: "68722090b10934b81b4852cee6b24e634cbf0af948fb525423e03ca787f952f3" sha256 x86_64_linux: "8360bdaac2d2910dcfda59757142a9d429631db654e8d8df2478e89d1570a4c7" end depends_on "cmake" => :build depends_on "libconfig" => :build depends_on "pkg-config" => :build depends_on "llvm@14" uses_from_macos "libxml2" => :build on_linux do # Superenv does not support building with a versioned LLVM. depends_on "llvm" => [:build, :test] end fails_with :gcc resource "ldc-bootstrap" do on_macos do on_intel do url "https://github.com/ldc-developers/ldc/releases/download/v1.28.1/ldc2-1.28.1-osx-x86_64.tar.xz" sha256 "9aa43e84d94378f3865f69b08041331c688e031dd2c5f340eb1f3e30bdea626c" end on_arm do url "https://github.com/ldc-developers/ldc/releases/download/v1.28.1/ldc2-1.28.1-osx-arm64.tar.xz" sha256 "9bddeb1b2c277019cf116b2572b5ee1819d9f99fe63602c869ebe42ffb813aed" end end on_linux do # ldc 1.27 requires glibc 2.27, which is too new for Ubuntu 16.04 LTS. The last version we can bootstrap with # is 1.26. Change this when we migrate to Ubuntu 18.04 LTS. url "https://github.com/ldc-developers/ldc/releases/download/v1.26.0/ldc2-1.26.0-linux-x86_64.tar.xz" sha256 "06063a92ab2d6c6eebc10a4a9ed4bef3d0214abc9e314e0cd0546ee0b71b341e" end end def llvm deps.reject { |d| d.build? || d.test? } .map(&:to_formula) .find { |f| f.name.match?(/^llvm(@\d+)?$/) } end def install ENV.cxx11 (buildpath/"ldc-bootstrap").install resource("ldc-bootstrap") args = %W[ -DLLVM_ROOT_DIR=#{llvm.opt_prefix} -DINCLUDE_INSTALL_DIR=#{include}/dlang/ldc -DD_COMPILER=#{buildpath}/ldc-bootstrap/bin/ldmd2 ] args += if OS.mac? ["-DCMAKE_INSTALL_RPATH=#{rpath};#{rpath(source: lib, target: llvm.opt_lib)}"] else # Fix ldc-bootstrap/bin/ldmd2: error while loading shared libraries: libxml2.so.2 ENV.prepend_path "LD_LIBRARY_PATH", Formula["libxml2"].opt_lib end system "cmake", "-S", ".", "-B", "build", *args, *std_cmake_args system "cmake", "--build", "build" system "cmake", "--install", "build" end test do # Don't set CC=llvm_clang since that won't be in PATH, # nor should it be used for the test. ENV.method(DevelopmentTools.default_compiler).call (testpath/"test.d").write <<~EOS import std.stdio; void main() { writeln("Hello, world!"); } EOS system bin/"ldc2", "test.d" assert_match "Hello, world!", shell_output("./test") system bin/"ldc2", "-flto=thin", "test.d" assert_match "Hello, world!", shell_output("./test") system bin/"ldc2", "-flto=full", "test.d" assert_match "Hello, world!", shell_output("./test") system bin/"ldmd2", "test.d" assert_match "Hello, world!", shell_output("./test") end end