homebrew-core/Formula/mold.rb

114 lines
3.8 KiB
Ruby

class Mold < Formula
desc "Modern Linker"
homepage "https://github.com/rui314/mold"
url "https://github.com/rui314/mold/archive/v1.8.0.tar.gz"
sha256 "7210225478796c2528aae30320232a5a3b93a640292575a8c55aa2b140041b5c"
license "AGPL-3.0-only"
head "https://github.com/rui314/mold.git", branch: "main"
bottle do
sha256 cellar: :any, arm64_ventura: "c5f868748e217f0465ed54bf2eea9ffe031d8512bd2e7197ce7da5461b920efc"
sha256 cellar: :any, arm64_monterey: "16cf4f718fed009e62f43a84371850a65a446155b249fbf11d74a1ff5e259aa4"
sha256 cellar: :any, arm64_big_sur: "aaff376d5f0867844a02cb25ed76f4c023fdefd97e026aae30508af4563c223a"
sha256 cellar: :any, ventura: "5523beb434fea0737e9ac73b90eca1351f3565046bdd014af99267c51773e0a5"
sha256 cellar: :any, monterey: "9b34fdfbcc9492d9ea0bb0724e717150af256d0bae24c75996b07f962b608134"
sha256 cellar: :any, big_sur: "179db3cf34862fde2b1999a4a1ef4c457bf1d837a99ae22e4453399ebeedb78a"
sha256 cellar: :any_skip_relocation, x86_64_linux: "5b4323c844302d0bba82dc13ea98524f53f7838ead2d2c0fe6dec5b9b4394388"
end
depends_on "cmake" => :build
depends_on "tbb"
depends_on "zstd"
uses_from_macos "zlib"
on_macos do
depends_on "llvm" => :build if DevelopmentTools.clang_build_version <= 1200
end
on_linux do
depends_on "mimalloc"
depends_on "openssl@3" # Uses CommonCrypto on macOS
end
fails_with :clang do
build 1200
cause "Requires C++20"
end
fails_with :gcc do
version "7"
cause "Requires C++20"
end
def install
ENV.llvm_clang if OS.mac? && (DevelopmentTools.clang_build_version <= 1200)
# Avoid embedding libdir in the binary.
# This helps make the bottle relocatable.
inreplace "config.h.in", "@CMAKE_INSTALL_FULL_LIBDIR@", ""
# Ensure we're using Homebrew-provided versions of these dependencies.
%w[mimalloc tbb zlib zstd].map { |dir| (buildpath/"third-party"/dir).rmtree }
args = %w[
-DMOLD_LTO=ON
-DMOLD_USE_MIMALLOC=ON
-DMOLD_USE_SYSTEM_MIMALLOC=ON
-DMOLD_USE_SYSTEM_TBB=ON
-DCMAKE_SKIP_INSTALL_RULES=OFF
]
system "cmake", "-S", ".", "-B", "build", *args, *std_cmake_args
system "cmake", "--build", "build"
system "cmake", "--install", "build"
pkgshare.install "test"
end
def caveats
<<~EOS
Support for Mach-O targets has been removed.
See https://github.com/bluewhalesystems/sold for macOS/iOS support.
EOS
end
test do
(testpath/"test.c").write <<~EOS
int main(void) { return 0; }
EOS
linker_flag = case ENV.compiler
when /^gcc(-(\d|10|11))?$/ then "-B#{libexec}/mold"
when :clang, /^gcc-\d{2,}$/ then "-fuse-ld=mold"
else odie "unexpected compiler"
end
extra_flags = []
extra_flags += %w[--target=x86_64-unknown-linux-gnu -nostdlib] unless OS.linux?
system ENV.cc, linker_flag, *extra_flags, "test.c"
if OS.linux?
system "./a.out"
else
assert_match "ELF 64-bit LSB executable, x86-64", shell_output("file a.out")
end
return unless OS.linux?
cp_r pkgshare/"test", testpath
inreplace testpath.glob("test/elf/*.sh") do |s|
s.gsub!(%r{(\./|`pwd`/)?mold-wrapper}, lib/"mold/mold-wrapper", false)
s.gsub!(%r{(\.|`pwd`)/mold}, bin/"mold", false)
s.gsub!(/-B(\.|`pwd`)/, "-B#{libexec}/mold", false)
end
# The `inreplace` rules above do not work well on this test. To avoid adding
# too much complexity to the regex rules, it is manually tested below
# instead.
(testpath/"test/elf/mold-wrapper2.sh").unlink
assert_match "mold-wrapper.so",
shell_output("#{bin}/mold -run bash -c 'echo $LD_PRELOAD'")
# Run the remaining tests.
testpath.glob("test/elf/*.sh").each { |t| system "bash", t }
end
end