|
| 1 | +class Llvm11 < Formula |
| 2 | + desc "Next-gen compiler infrastructure" |
| 3 | + homepage "http://llvm.org/" |
| 4 | + |
| 5 | + version = "11.1.0" |
| 6 | + |
| 7 | + url "https://github.com/llvm/llvm-project/releases/download/llvmorg-#{version}/llvm-project-#{version}.src.tar.xz" |
| 8 | + sha256 "74d2529159fd118c3eac6f90107b5611bccc6f647fdea104024183e8d5e25831" |
| 9 | + |
| 10 | + bottle do |
| 11 | + root_url "https://github.com/llvm-hs/homebrew-llvm/releases/download/v11.1.0" |
| 12 | + sha256 cellar :any, big_sur: "" |
| 13 | + end |
| 14 | + |
| 15 | + # http://releases.llvm.org/11.0.0/docs/GettingStarted.html#requirements |
| 16 | + depends_on "cmake" => :build |
| 17 | + |
| 18 | + uses_from_macos "libedit" |
| 19 | + uses_from_macos "libffi", since: catalina |
| 20 | + uses_from_macos "libxml2" |
| 21 | + uses_from_macos "ncurses" |
| 22 | + uses_from_macos "zlib" |
| 23 | + |
| 24 | + # version suffix |
| 25 | + def ver |
| 26 | + "11" |
| 27 | + end |
| 28 | + |
| 29 | + # http://releases.llvm.org/11.0.0/docs/CMake.html |
| 30 | + def install |
| 31 | + # Apple's libstdc++ is too old to build LLVM |
| 32 | + ENV.libcxx if ENV.compiler == :clang |
| 33 | + |
| 34 | + # compiler-rt has some iOS simulator features that require i386 symbols. I'm |
| 35 | + # assuming the rest of clang also needs support for 32-bit compilation to |
| 36 | + # work correctly, but if not, perhaps universal binaries could be limited to |
| 37 | + # compiler-rt. LLVM makes this somewhat easier because compiler-rt can |
| 38 | + # almost be treated as an entirely different build from LLVM. |
| 39 | + ENV.permit_arch_flags |
| 40 | + |
| 41 | + projects = %w[ |
| 42 | + clang |
| 43 | + clang-tools-extra |
| 44 | + lld |
| 45 | + lldb |
| 46 | + openmp |
| 47 | + polly |
| 48 | + mlir |
| 49 | + ] |
| 50 | + runtimes = %w[ |
| 51 | + compiler-rt |
| 52 | + libcxx |
| 53 | + libcxxabi |
| 54 | + libunwind |
| 55 | + ] |
| 56 | + |
| 57 | + clang_buildpath = buildpath/"tools/clang" |
| 58 | + libcxx_buildpath = buildpath/"projects/libcxx" |
| 59 | + |
| 60 | + clang_buildpath.install resource("clang") |
| 61 | + libcxx_buildpath.install resource("libcxx") |
| 62 | + (buildpath/"tools/lld").install resource("lld") |
| 63 | + (buildpath/"tools/polly").install resource("polly") |
| 64 | + (buildpath/"tools/clang/tools/extra").install resource("clang-tools-extra") |
| 65 | + (buildpath/"projects/openmp").install resource("openmp") |
| 66 | + (buildpath/"projects/libunwind").install resource("libunwind") |
| 67 | + (buildpath/"projects/compiler-rt").install resource("compiler-rt") |
| 68 | + |
| 69 | + install_prefix = lib/"llvm-#{ver}" |
| 70 | + |
| 71 | + args = %W[ |
| 72 | + -DCMAKE_BUILD_TYPE=Release |
| 73 | + -DCMAKE_INSTALL_PREFIX=#{install_prefix} |
| 74 | + -DLLVM_ENABLE_PROJECTS=#{projects.join(";")} |
| 75 | + -DLLVM_ENABLE_RUNTIMES=#{runtimes.join(";")} |
| 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 | + -DWITH_POLLY=ON |
| 85 | + -DLINK_POLLY_INTO_TOOLS=ON |
| 86 | + -DLLVM_TARGETS_TO_BUILD=all |
| 87 | + -DLIBOMP_ARCH=x86_64 |
| 88 | + -DLLVM_BUILD_EXTERNAL_COMPILER_RT=ON |
| 89 | + -DLLVM_BUILD_LLVM_C_DYLIB=ON |
| 90 | + -DLLVM_LINK_LLVM_DYLIB=ON |
| 91 | + -DLLVM_ENABLE_LIBCXX=ON |
| 92 | + -DLLVM_ENABLE_FFI=ON |
| 93 | + -DLLVM_CREATE_XCODE_TOOLCHAIN=ON |
| 94 | + -DLLVM_CREATE_XCODE_TOOLCHAIN=#{MacOS::Xcode.installed? ? "ON" : "OFF"} |
| 95 | + -DRUNTIMES_CMAKE_ARGS="-DCMAKE_INSTALL_RPATH=@loader_path/../lib" |
| 96 | + ] |
| 97 | + |
| 98 | + if MacOS.version >= :catalina |
| 99 | + args << "-DFFI_INCLUDE_DIR=#{MacOS.sdk_path}/usr/include/ffi" |
| 100 | + args << "-DFFI_LIBRARY_DIR=#{MacOS.sdk_path}/usr/lib" |
| 101 | + else |
| 102 | + args << "-DFFI_INCLUDE_DIR=#{Formula["libffi"].opt_include}" |
| 103 | + args << "-DFFI_LIBRARY_DIR=#{Formula["libffi"].opt_lib}" |
| 104 | + end |
| 105 | + |
| 106 | + mkdir "build" do |
| 107 | + system "cmake", "-G", "Unix Makefiles", "..", *(std_cmake_args + args) |
| 108 | + system "cmake", "--build", "." |
| 109 | + system "cmake", "--build", ".", "--target", "install" |
| 110 | + system "cmake", "--build", ".", "--target", "install-xcode-toolchain" if MacOS::Xcode.installed? |
| 111 | + end |
| 112 | + |
| 113 | + (share/"clang-#{ver}/tools").install Dir["tools/clang/tools/scan-{build,view}"] |
| 114 | + inreplace share/"clang-#{ver}/tools/scan-build/bin/scan-build", "$RealBin/bin/clang", install_prefix/"bin/clang" |
| 115 | + (install_prefix/"bin").install_symlink share/"clang-#{ver}/tools/scan-view/bin/scan-view" |
| 116 | + (install_prefix/"bin").install_symlink share/"clang-#{ver}/tools/scan-build/bin/scan-build" |
| 117 | + (install_prefix/"share/man/man1").install_symlink share/"clang-#{ver}/tools/scan-build/scan-build.1" |
| 118 | + |
| 119 | + (lib/"python2.7/site-packages").install "bindings/python/llvm" => "llvm-#{ver}", |
| 120 | + clang_buildpath/"bindings/python/clang" => "clang-#{ver}" |
| 121 | + |
| 122 | + # replace the existing "clang -> clang-11" symlink |
| 123 | + rm install_prefix/"bin/clang" |
| 124 | + mv install_prefix/"bin/clang-#{ver}", install_prefix/"bin/clang" |
| 125 | + |
| 126 | + # These versioned .dylib symlinks are missing for some reason |
| 127 | + # Note that we use relative symlinks |
| 128 | + ln_s "libLLVM.dylib", install_prefix/"lib/libLLVM-#{ver}.dylib" |
| 129 | + |
| 130 | + # Set LC_LOAD_DYLIB entries to absolute paths |
| 131 | + system "install_name_tool", "-change", "@rpath/libLLVM.dylib", install_prefix/"lib/libLLVM.dylib", install_prefix/"lib/libLTO.dylib" |
| 132 | + system "install_name_tool", "-change", "@rpath/libLLVM.dylib", install_prefix/"lib/libLLVM.dylib", install_prefix/"lib/libclang.dylib" |
| 133 | + |
| 134 | + # Set LC_ID_DYLIB entries to absolute paths |
| 135 | + system "install_name_tool", "-id", install_prefix/"lib/libLLVM.dylib", install_prefix/"lib/libLLVM.dylib" |
| 136 | + system "install_name_tool", "-id", install_prefix/"lib/libLTO.dylib", install_prefix/"lib/libLTO.dylib" |
| 137 | + system "install_name_tool", "-id", install_prefix/"lib/libc++.1.0.dylib", install_prefix/"lib/libc++.1.0.dylib" |
| 138 | + system "install_name_tool", "-id", install_prefix/"lib/libclang.dylib", install_prefix/"lib/libclang.dylib" |
| 139 | + system "install_name_tool", "-id", install_prefix/"lib/libomp.dylib", install_prefix/"lib/libomp.dylib" |
| 140 | + system "install_name_tool", "-id", install_prefix/"lib/libunwind.1.0.dylib", install_prefix/"lib/libunwind.1.0.dylib" |
| 141 | + |
| 142 | + Dir.glob(install_prefix/"bin/*") do |exec_path| |
| 143 | + basename = File.basename(exec_path) |
| 144 | + bin.install_symlink exec_path => "#{basename}-#{ver}" |
| 145 | + end |
| 146 | + |
| 147 | + Dir.glob(install_prefix/"share/man/man1/*") do |manpage| |
| 148 | + basename = File.basename(manpage, ".1") |
| 149 | + man1.install_symlink manpage => "#{basename}-#{ver}.1" |
| 150 | + end |
| 151 | + end |
| 152 | + |
| 153 | + def caveats; <<~EOS |
| 154 | + Extra tools are installed in #{opt_share}/clang-#{ver} |
| 155 | +
|
| 156 | + To link to libc++, something like the following is required: |
| 157 | + CXX="clang++-#{ver} -stdlib=libc++" |
| 158 | + CXXFLAGS="$CXXFLAGS -nostdinc++ -I#{opt_lib}/llvm-#{ver}/include/c++/v1" |
| 159 | + LDFLAGS="$LDFLAGS -L#{opt_lib}/llvm-#{ver}/lib" |
| 160 | + EOS |
| 161 | + end |
| 162 | + |
| 163 | + test do |
| 164 | + assert_equal prefix.to_s, shell_output("#{bin}/llvm-config-#{ver} --prefix").chomp |
| 165 | + |
| 166 | + # test for sed errors since some llvm makefiles assume that sed |
| 167 | + # understands '\n' which is true for gnu sed and not for bsd sed. |
| 168 | + assert_no_match /PATH\)n/, (lib/"llvm-#{ver}/share/llvm/cmake/LLVMConfig.cmake").read |
| 169 | + system "#{bin}/llvm-config-#{ver}", "--version" |
| 170 | + end |
| 171 | +end |
| 172 | + |
0 commit comments