homebrew-core/Formula/ldc.rb

99 lines
3.7 KiB
Ruby

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.29.0/ldc-1.29.0-src.tar.gz"
sha256 "d0c066eb965467625d9c5e75c00c583451b9ffa363601f9e37275ca8a8aea140"
license "BSD-3-Clause"
head "https://github.com/ldc-developers/ldc.git", branch: "master"
livecheck do
url :stable
strategy :github_latest
end
bottle do
sha256 arm64_monterey: "73cf7c5d2fef44f20d1572eb6df3404d3e5669e3218a573b96ec77b987aa76c1"
sha256 arm64_big_sur: "f5e4db7df43b34689898bd2dbed85f0db1097c3b9c79995427006a3bc6076747"
sha256 monterey: "14e7af742428839eb82d45281862b44ccf71010d5d93bceb1ae0c4f8955c33f8"
sha256 big_sur: "b9004c94ca080627d484d680a78de4d91d85ecab38e992a7f66e9f34455b7c26"
sha256 catalina: "00e5907a5628b93578a61f81730e90923666353fc108012c1a6b58f2f4c60c48"
sha256 x86_64_linux: "efd8dd1c816d77b608944563d037efaadca7a3ba51414dc211a29cadc3e647e3"
end
depends_on "cmake" => :build
depends_on "libconfig" => :build
depends_on "pkg-config" => :build
depends_on "llvm@12"
uses_from_macos "libxml2" => :build
# CompilerSelectionError: ldc cannot be built with any available compilers.
uses_from_macos "llvm" => [:build, :test]
fails_with :gcc
resource "ldc-bootstrap" do
on_macos do
if Hardware::CPU.intel?
url "https://github.com/ldc-developers/ldc/releases/download/v1.28.1/ldc2-1.28.1-osx-x86_64.tar.xz"
sha256 "9aa43e84d94378f3865f69b08041331c688e031dd2c5f340eb1f3e30bdea626c"
else
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")
# Fix ldc-bootstrap/bin/ldmd2: error while loading shared libraries: libxml2.so.2
ENV.prepend_path "LD_LIBRARY_PATH", Formula["libxml2"].lib if OS.linux?
args = %W[
-DLLVM_ROOT_DIR=#{llvm.opt_prefix}
-DINCLUDE_INSTALL_DIR=#{include}/dlang/ldc
-DD_COMPILER=#{buildpath}/ldc-bootstrap/bin/ldmd2
]
args << "-DCMAKE_INSTALL_RPATH=#{rpath};@loader_path/#{llvm.opt_lib.relative_path_from(lib)}" if OS.mac?
system "cmake", "-S", ".", "-B", "build", *std_cmake_args, *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