homebrew-core/Formula/mold.rb

99 lines
3.2 KiB
Ruby

class Mold < Formula
desc "Modern Linker"
homepage "https://github.com/rui314/mold"
url "https://github.com/rui314/mold/archive/v1.3.1.tar.gz"
sha256 "d436e2d4c1619a97aca0e28f26c4e79c0242d10ce24e829c1b43cfbdd196fd77"
license "AGPL-3.0-only"
head "https://github.com/rui314/mold.git", branch: "main"
bottle do
sha256 cellar: :any, arm64_monterey: "535645ac73281705d7bb5c3564c2864cc895d7bfc1e38729e2bd66c3cf109088"
sha256 cellar: :any, arm64_big_sur: "e51450fdc1d490b94da64c6a3312e406d3d9d9e0a994e42c75c9f1008c06c54e"
sha256 cellar: :any, monterey: "98e4fe39d91c35df6f5c42e0b6e49d8d3bc6378f835e9b4e03706d53155d3adb"
sha256 cellar: :any, big_sur: "a886cc4ef4785564ce08908b0bb8dee415b3eb5ce1a2b742e0ca44ae5d3fdbb1"
sha256 cellar: :any, catalina: "da3549514abf8a29e94939a79ffa3eba4d13677032bd3cce1f8c73fa5376faf4"
sha256 x86_64_linux: "294c9348f55e8661bb25f5f4824857ab4a1d5755381a42759430e5f7b08e533c"
end
depends_on "tbb"
uses_from_macos "zlib"
on_macos do
depends_on "llvm" => [:build, :test] if DevelopmentTools.clang_build_version <= 1200
end
on_linux do
depends_on "gcc"
depends_on "mimalloc"
depends_on "openssl@1.1" # Uses CommonCrypto on macOS
end
fails_with :clang do
build 1200
cause "Requires C++20"
end
# Requires C++20
fails_with gcc: "5"
fails_with gcc: "6"
fails_with gcc: "7"
def install
ENV.remove "HOMEBREW_LIBRARY_PATHS", Formula["llvm"].opt_lib
ENV.llvm_clang if OS.mac? && (DevelopmentTools.clang_build_version <= 1200)
args = %W[
PREFIX=#{prefix}
LTO=1
SYSTEM_MIMALLOC=1
SYSTEM_TBB=1
]
args << "STRIP=true" if OS.mac?
system "make", *args, "install"
inreplace buildpath.glob("test/macho/*.sh"), "./ld64", bin/"ld64.mold", false
inreplace buildpath.glob("test/elf/*.sh") do |s|
s.gsub!(%r{(\.|`pwd`)/mold }, "#{bin}/mold ", false)
s.gsub!(%r{(`pwd`/)?mold-wrapper}, lib/"mold/mold-wrapper", false)
end
pkgshare.install "test"
end
test do
# Avoid use of the `llvm_clang` shim.
if OS.mac? && (DevelopmentTools.clang_build_version <= 1200)
ENV.clang
ENV.prepend_path "PATH", Formula["llvm"].opt_bin
end
(testpath/"test.c").write <<~EOS
int main(void) { return 0; }
EOS
# GCC 12.1.0+ can also use `-fuse-ld=mold`
linker_flag = case ENV.compiler
when :clang then "-fuse-ld=mold"
when /^gcc(-\d+)?$/ then "-B#{libexec}/mold"
else raise "unexpected compiler"
end
system ENV.cc, linker_flag, "test.c"
system "./a.out"
# Lots of tests fail on ARM Big Sur for some reason.
return if MacOS.version == :big_sur && Hardware::CPU.arm?
if OS.mac?
cp_r pkgshare/"test", testpath
# Remove some failing tests.
untested = %w[headerpad* pagezero-size basic response-file]
homebrew_clang = Utils.safe_popen_read("clang", "--version").include?("Homebrew")
untested << "syslibroot" if homebrew_clang
testpath.glob("test/macho/{#{untested.join(",")}}.sh").map(&:unlink)
(testpath/"test/macho").children.each { |t| system t }
else
system bin/"mold", "-run", ENV.cc, "test.c", "-o", "test"
system "./test"
end
end
end