class Lld < Formula desc "LLVM Project Linker" homepage "https://lld.llvm.org/" url "https://github.com/llvm/llvm-project/releases/download/llvmorg-21.1.8/llvm-project-21.1.8.src.tar.xz" sha256 "4633a23617fa31a3ea51242586ea7fb1da7140e426bd62fc164261fe036aa142" # The LLVM Project is under the Apache License v2.0 with LLVM Exceptions license "Apache-2.0" => { with: "LLVM-exception" } head "https://github.com/llvm/llvm-project.git", branch: "main" livecheck do formula "llvm" end bottle do sha256 cellar: :any, arm64_tahoe: "ae7611ba868e1264da2f9ada062e53f2edd59fdc420f63804b1e031dcc4a1e26" sha256 cellar: :any, arm64_sequoia: "bc9304083889749dcd2d1b7e9b1598c6865232b93d40c94cab0ee3154a947900" sha256 cellar: :any, arm64_sonoma: "e3e0fc1342ec796f2e0fa868b2f14e52e3a28ed7fedbeae9e62cb37c830ae535" sha256 cellar: :any, sonoma: "e6d9522e1166ba1b77991c7a3e4d94b1f0a8f064d4b0299300bec8f36e15e477" sha256 cellar: :any_skip_relocation, arm64_linux: "2da9a79ec226755d411db0595b0cfb9d509ac71a5c99c72fc4cf957b4fbf86b3" sha256 cellar: :any_skip_relocation, x86_64_linux: "5fc5f9590f7ba31ae3a110b3275c779dc8fa5cea1e25449a69a3f0a25e72131c" end depends_on "cmake" => :build depends_on "llvm" depends_on "zstd" uses_from_macos "zlib" # These used to be part of LLVM. link_overwrite "bin/lld", "bin/ld64.lld", "bin/ld.lld", "bin/lld-link", "bin/wasm-ld" link_overwrite "include/lld/*", "lib/cmake/lld/*" def install system "cmake", "-S", "lld", "-B", "build", "-DBUILD_SHARED_LIBS=ON", "-DCMAKE_INSTALL_RPATH=#{rpath}", "-DLLD_BUILT_STANDALONE=ON", "-DLLD_VENDOR=#{tap&.user}", "-DLLVM_ENABLE_LTO=ON", "-DLLVM_INCLUDE_TESTS=OFF", "-DLLVM_USE_SYMLINKS=ON", *std_cmake_args system "cmake", "--build", "build" system "cmake", "--install", "build" end test do (testpath/"bin/lld").write <<~BASH #!/bin/bash exit 1 BASH chmod "+x", "bin/lld" (testpath/"bin").install_symlink "lld" => "ld64.lld" (testpath/"bin").install_symlink "lld" => "ld.lld" (testpath/"test.c").write <<~C #include int main() { printf("hello, world!"); return 0; } C error_message = case ENV.compiler when /^gcc(-\d+)?$/ then "ld returned 1 exit status" when :clang then "linker command failed" else odie "unexpected compiler" end # Check that the `-fuse-ld=lld` flag actually picks up LLD from PATH. with_env(PATH: "#{testpath}/bin:#{ENV["PATH"]}") do assert_match error_message, shell_output("#{ENV.cc} -v -fuse-ld=lld test.c 2>&1", 1) end system ENV.cc, "-v", "-fuse-ld=lld", "test.c", "-o", "test" assert_match "hello, world!", shell_output("./test") end end