|
| 1 | +class Llvm12 < Formula |
| 2 | + desc "Next-gen compiler infrastructure" |
| 3 | + homepage "http://llvm.org/" |
| 4 | + # The LLVM Project is under the Apache License v2.0 with LLVM Exceptions |
| 5 | + license "Apache-2.0" => { with: "LLVM-exception" } |
| 6 | + revision 1 |
| 7 | + |
| 8 | + stable do |
| 9 | + url "https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.0/llvm-project-12.0.0.src.tar.xz" |
| 10 | + sha256 "9ed1688943a4402d7c904cc4515798cdb20080066efa010fe7e1f2551b423628" |
| 11 | + end |
| 12 | + |
| 13 | + # bottle do |
| 14 | + # root_url "https://github.com/llvm-hs/homebrew-llvm/releases/download/v12.0.0" |
| 15 | + # sha256 cellar: :any, big_sur: "" |
| 16 | + # end |
| 17 | + |
| 18 | + # Clang cannot find system headers if Xcode CLT is not installed |
| 19 | + pour_bottle? do |
| 20 | + on_macos do |
| 21 | + reason "The bottle needs the Xcode CLT to be installed." |
| 22 | + satisfy { MacOS::CLT.installed? } |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + # http://releases.llvm.org/12.0.0/docs/GettingStarted.html#requirements |
| 27 | + depends_on "cmake" => :build |
| 28 | + |
| 29 | + uses_from_macos "libedit" |
| 30 | + uses_from_macos "libffi", since: :catalina |
| 31 | + uses_from_macos "libxml2" |
| 32 | + uses_from_macos "ncurses" |
| 33 | + uses_from_macos "zlib" |
| 34 | + |
| 35 | + # version suffix |
| 36 | + def version |
| 37 | + "12" |
| 38 | + end |
| 39 | + |
| 40 | + # http://releases.llvm.org/12.0.0/docs/CMake.html |
| 41 | + def install |
| 42 | + projects = %w[ |
| 43 | + clang |
| 44 | + clang-tools-extra |
| 45 | + compiler-rt |
| 46 | + libcxx |
| 47 | + libcxxabi |
| 48 | + libunwind |
| 49 | + lld |
| 50 | + lldb |
| 51 | + mlir |
| 52 | + openmp |
| 53 | + polly |
| 54 | + ] |
| 55 | + runtimes = %w[ |
| 56 | + ] |
| 57 | + |
| 58 | + # Apple's libstdc++ is too old to build LLVM |
| 59 | + ENV.libcxx if ENV.compiler == :clang |
| 60 | + |
| 61 | + # compiler-rt has some iOS simulator features that require i386 symbols. I'm |
| 62 | + # assuming the rest of clang also needs support for 32-bit compilation to |
| 63 | + # work correctly, but if not, perhaps universal binaries could be limited to |
| 64 | + # compiler-rt. LLVM makes this somewhat easier because compiler-rt can |
| 65 | + # almost be treated as an entirely different build from LLVM. |
| 66 | + ENV.permit_arch_flags |
| 67 | + |
| 68 | + install_prefix = lib/"llvm-#{version}" |
| 69 | + |
| 70 | + args = %W[ |
| 71 | + -DCMAKE_BUILD_TYPE=Release |
| 72 | + -DCMAKE_INSTALL_PREFIX=#{install_prefix} |
| 73 | + -DLLVM_ENABLE_PROJECTS=#{projects.join(";")} |
| 74 | + -DLLVM_ENABLE_RUNTIMES=#{runtimes.join(";")} |
| 75 | + -DLLVM_TARGETS_TO_BUILD=all |
| 76 | + -DLLVM_ENABLE_ASSERTIONS=ON |
| 77 | + -DLLVM_OPTIMIZED_TABLEGEN=ON |
| 78 | + -DLLVM_INCLUDE_DOCS=OFF |
| 79 | + -DLLVM_INCLUDE_TESTS=OFF |
| 80 | + -DLLVM_ENABLE_RTTI=ON |
| 81 | + -DLLVM_ENABLE_EH=ON |
| 82 | + -DLLVM_INSTALL_UTILS=ON |
| 83 | + -DLLVM_ENABLE_Z3_SOLVER=OFF |
| 84 | + -DLLVM_BUILD_EXTERNAL_COMPILER_RT=ON |
| 85 | + -DLLVM_BUILD_LLVM_C_DYLIB=ON |
| 86 | + -DLLVM_LINK_LLVM_DYLIB=ON |
| 87 | + -DLLVM_ENABLE_LIBCXX=ON |
| 88 | + -DLLVM_ENABLE_FFI=ON |
| 89 | + -DLLVM_CREATE_XCODE_TOOLCHAIN=ON |
| 90 | + -DLLVM_CREATE_XCODE_TOOLCHAIN=#{MacOS::Xcode.installed? ? "ON" : "OFF"} |
| 91 | + -DLLDB_USE_SYSTEM_DEBUGSERVER=ON |
| 92 | + ] |
| 93 | + |
| 94 | + if MacOS.version >= :catalina |
| 95 | + args << "-DFFI_INCLUDE_DIR=#{MacOS.sdk_path}/usr/include/ffi" |
| 96 | + args << "-DFFI_LIBRARY_DIR=#{MacOS.sdk_path}/usr/lib" |
| 97 | + else |
| 98 | + args << "-DFFI_INCLUDE_DIR=#{Formula["libffi"].opt_include}" |
| 99 | + args << "-DFFI_LIBRARY_DIR=#{Formula["libffi"].opt_lib}" |
| 100 | + end |
| 101 | + |
| 102 | + sdk = MacOS.sdk_path_if_needed |
| 103 | + args << "-DDEFAULT_SYSROOT=#{sdk}" if sdk |
| 104 | + |
| 105 | + if MacOS.version == :mojave && MacOS::CLT.installed? |
| 106 | + # Mojave CLT linker via software update is older than Xcode. |
| 107 | + # Use it to retain compatibility. |
| 108 | + args << "-DCMAKE_LINKER=/Library/Developer/CommandLineTools/usr/bin/ld" |
| 109 | + end |
| 110 | + |
| 111 | + llvmpath = buildpath/"llvm" |
| 112 | + mkdir llvmpath/"build" do |
| 113 | + system "cmake", "-G", "Unix Makefiles", "..", *(std_cmake_args + args) |
| 114 | + system "cmake", "--build", "." |
| 115 | + system "cmake", "--build", ".", "--target", "install" |
| 116 | + system "cmake", "--build", ".", "--target", "install-xcode-toolchain" if MacOS::Xcode.installed? |
| 117 | + end |
| 118 | + |
| 119 | + # replace the existing "clang -> clang-12" symlink |
| 120 | + rm install_prefix/"bin/clang" |
| 121 | + mv install_prefix/"bin/clang-#{version}", install_prefix/"bin/clang" |
| 122 | + |
| 123 | + # These versioned .dylib symlinks are missing for some reason |
| 124 | + # Note that we use relative symlinks |
| 125 | + ln_s "libLLVM.dylib", install_prefix/"lib/libLLVM-#{version}.dylib" |
| 126 | + |
| 127 | + Dir.glob(install_prefix/"bin/*") do |exec_path| |
| 128 | + basename = File.basename(exec_path) |
| 129 | + bin.install_symlink exec_path => "#{basename}-#{version}" |
| 130 | + end |
| 131 | + |
| 132 | + Dir.glob(install_prefix/"share/man/man1/*") do |manpage| |
| 133 | + basename = File.basename(manpage, ".1") |
| 134 | + man1.install_symlink manpage => "#{basename}-#{version}.1" |
| 135 | + end |
| 136 | + end |
| 137 | + |
| 138 | + def caveats |
| 139 | + <<~EOS |
| 140 | + Extra tools are installed in #{opt_share}/clang-#{version} |
| 141 | +
|
| 142 | + To link to libc++, something like the following is required: |
| 143 | + CXX="clang++-#{version} -stdlib=libc++" |
| 144 | + CXXFLAGS="$CXXFLAGS -nostdinc++ -I#{opt_lib}/llvm-#{version}/include/c++/v1" |
| 145 | + LDFLAGS="$LDFLAGS -L#{opt_lib}/llvm-#{version}/lib" |
| 146 | + EOS |
| 147 | + end |
| 148 | + |
| 149 | + test do |
| 150 | + assert_equal prefix.to_s, shell_output("#{bin}/llvm-config-#{version} --prefix").chomp |
| 151 | + |
| 152 | + # test for sed errors since some llvm makefiles assume that sed |
| 153 | + # understands '\n' which is true for gnu sed and not for bsd sed. |
| 154 | + assert_no_match(/PATH\)n/, (lib/"llvm-#{version}/share/llvm/cmake/LLVMConfig.cmake").read) |
| 155 | + system "#{bin}/llvm-config-#{version}", "--version" |
| 156 | + end |
| 157 | +end |
| 158 | + |
0 commit comments