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.9.0.tar.gz"
sha256 "faf381ba268e714bec7f872de0dd6ea9187ae20b4e12c434a67ac92854701280"
license "AGPL-3.0-only"
head "https://github.com/rui314/mold.git", branch: "main"
bottle do
sha256 cellar: :any, arm64_ventura: "3442e57a91ae0af551479f1f8790c83877fb955d2491e4b4ee681002dda1ee06"
sha256 cellar: :any, arm64_monterey: "313dd3345e75ba5ebf9f9cf3240556222bc7305688b0f36c8c28b20fce4da186"
sha256 cellar: :any, arm64_big_sur: "8f91804c4cce8ffc31c5e98b9ecd110faaf5a6132a4fdd0cb29c4733e86fa59e"
sha256 cellar: :any, ventura: "92219fb96541e7376c9f3473b8bd3e2266cec4e475a58ca28c9aff3ef21a17e9"
sha256 cellar: :any, monterey: "7c42c20f814d72ddc41d62c0e4a2b14c3037c841f4260f022bd63b622e3a4efc"
sha256 cellar: :any, big_sur: "aa96462ca9ffb19d0d57ef173d5decc96ba8c3633cfa2199bf972bab94697e40"
sha256 cellar: :any_skip_relocation, x86_64_linux: "f0ea60dcfa4fe095ef0038132178568dd0034b6122ab546efe694cef25f6f84d"
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