|
| 1 | +class Llvm9 < Formula |
| 2 | + desc "Next-gen compiler infrastructure" |
| 3 | + homepage "http://llvm.org/" |
| 4 | + |
| 5 | + version = "9.0.0" |
| 6 | + |
| 7 | + stable do |
| 8 | + url "http://releases.llvm.org/#{version}/llvm-#{version}.src.tar.xz" |
| 9 | + sha256 "d6a0565cf21f22e9b4353b2eb92622e8365000a9e90a16b09b56f8157eabfe84" |
| 10 | + |
| 11 | + resource "clang" do |
| 12 | + url "http://releases.llvm.org/#{version}/cfe-#{version}.src.tar.xz" |
| 13 | + sha256 "7ba81eef7c22ca5da688fdf9d88c20934d2d6b40bfe150ffd338900890aa4610" |
| 14 | + end |
| 15 | + |
| 16 | + resource "clang-tools-extra" do |
| 17 | + url "http://releases.llvm.org/#{version}/clang-tools-extra-#{version}.src.tar.xz" |
| 18 | + sha256 "ea1c86ce352992d7b6f6649bc622f6a2707b9f8b7153e9f9181a35c76aa3ac10" |
| 19 | + end |
| 20 | + |
| 21 | + resource "compiler-rt" do |
| 22 | + url "http://releases.llvm.org/#{version}/compiler-rt-#{version}.src.tar.xz" |
| 23 | + sha256 "56e4cd96dd1d8c346b07b4d6b255f976570c6f2389697347a6c3dcb9e820d10e" |
| 24 | + end |
| 25 | + |
| 26 | + resource "polly" do |
| 27 | + url "http://releases.llvm.org/#{version}/polly-#{version}.src.tar.xz" |
| 28 | + sha256 "a4fa92283de725399323d07f18995911158c1c5838703f37862db815f513d433" |
| 29 | + end |
| 30 | + |
| 31 | + resource "lld" do |
| 32 | + url "http://releases.llvm.org/#{version}/lld-#{version}.src.tar.xz" |
| 33 | + sha256 "31c6748b235d09723fb73fea0c816ed5a3fab0f96b66f8fbc546a0fcc8688f91" |
| 34 | + end |
| 35 | + |
| 36 | + resource "openmp" do |
| 37 | + url "http://releases.llvm.org/#{version}/openmp-#{version}.src.tar.xz" |
| 38 | + sha256 "9979eb1133066376cc0be29d1682bc0b0e7fb541075b391061679111ae4d3b5b" |
| 39 | + end |
| 40 | + |
| 41 | + resource "libcxx" do |
| 42 | + url "http://releases.llvm.org/#{version}/libcxx-#{version}.src.tar.xz" |
| 43 | + sha256 "3c4162972b5d3204ba47ac384aa456855a17b5e97422723d4758251acf1ed28c" |
| 44 | + end |
| 45 | + |
| 46 | + resource "libunwind" do |
| 47 | + url "http://releases.llvm.org/#{version}/libunwind-#{version}.src.tar.xz" |
| 48 | + sha256 "976a8d09e1424fb843210eecec00a506b956e6c31adda3b0d199e945be0d0db2" |
| 49 | + end |
| 50 | + end |
| 51 | + |
| 52 | + bottle do |
| 53 | + end |
| 54 | + |
| 55 | + head do |
| 56 | + url "http://llvm.org/git/llvm.git", :branch => "release_90" |
| 57 | + |
| 58 | + resource "clang" do |
| 59 | + url "http://llvm.org/git/clang.git", :branch => "release_90" |
| 60 | + end |
| 61 | + |
| 62 | + resource "clang-tools-extra" do |
| 63 | + url "http://llvm.org/git/clang-tools-extra.git", :branch => "release_90" |
| 64 | + end |
| 65 | + |
| 66 | + resource "compiler-rt" do |
| 67 | + url "http://llvm.org/git/compiler-rt.git", :branch => "release_90" |
| 68 | + end |
| 69 | + |
| 70 | + resource "polly" do |
| 71 | + url "http://llvm.org/git/polly.git", :branch => "release_90" |
| 72 | + end |
| 73 | + |
| 74 | + resource "lld" do |
| 75 | + url "http://llvm.org/git/lld.git", :branch => "release_90" |
| 76 | + end |
| 77 | + |
| 78 | + resource "openmp" do |
| 79 | + url "http://llvm.org/git/openmp.git", :branch => "release_90" |
| 80 | + end |
| 81 | + |
| 82 | + resource "libcxx" do |
| 83 | + url "http://llvm.org/git/libcxx.git", :branch => "release_90" |
| 84 | + end |
| 85 | + |
| 86 | + resource "libunwind" do |
| 87 | + url "http://llvm.org/git/libunwind.git", :branch => "release_90" |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 91 | + # http://releases.llvm.org/9.0.0/docs/GettingStarted.html#requirements |
| 92 | + depends_on "libffi" |
| 93 | + depends_on "cmake" => :build |
| 94 | + depends_on :xcode => :build |
| 95 | + |
| 96 | + # version suffix |
| 97 | + def ver |
| 98 | + "9" |
| 99 | + end |
| 100 | + |
| 101 | + # http://releases.llvm.org/9.0.0/docs/CMake.html |
| 102 | + def install |
| 103 | + # Apple's libstdc++ is too old to build LLVM |
| 104 | + ENV.libcxx if ENV.compiler == :clang |
| 105 | + |
| 106 | + # compiler-rt has some iOS simulator features that require i386 symbols. I'm |
| 107 | + # assuming the rest of clang also needs support for 32-bit compilation to |
| 108 | + # work correctly, but if not, perhaps universal binaries could be limited to |
| 109 | + # compiler-rt. LLVM makes this somewhat easier because compiler-rt can |
| 110 | + # almost be treated as an entirely different build from LLVM. |
| 111 | + ENV.permit_arch_flags |
| 112 | + |
| 113 | + clang_buildpath = buildpath/"tools/clang" |
| 114 | + libcxx_buildpath = buildpath/"projects/libcxx" |
| 115 | + |
| 116 | + clang_buildpath.install resource("clang") |
| 117 | + libcxx_buildpath.install resource("libcxx") |
| 118 | + (buildpath/"tools/lld").install resource("lld") |
| 119 | + (buildpath/"tools/polly").install resource("polly") |
| 120 | + (buildpath/"tools/clang/tools/extra").install resource("clang-tools-extra") |
| 121 | + (buildpath/"projects/openmp").install resource("openmp") |
| 122 | + (buildpath/"projects/libunwind").install resource("libunwind") |
| 123 | + (buildpath/"projects/compiler-rt").install resource("compiler-rt") |
| 124 | + |
| 125 | + install_prefix = lib/"llvm-#{ver}" |
| 126 | + |
| 127 | + args = %W[ |
| 128 | + -DCMAKE_INSTALL_PREFIX=#{install_prefix} |
| 129 | + -DCMAKE_BUILD_TYPE=Release |
| 130 | + -DLLVM_ENABLE_ASSERTIONS=ON |
| 131 | + -DLLVM_OPTIMIZED_TABLEGEN=ON |
| 132 | + -DLLVM_INCLUDE_DOCS=OFF |
| 133 | + -DLLVM_ENABLE_RTTI=ON |
| 134 | + -DLLVM_ENABLE_EH=ON |
| 135 | + -DLLVM_INSTALL_UTILS=ON |
| 136 | + -DWITH_POLLY=ON |
| 137 | + -DLINK_POLLY_INTO_TOOLS=ON |
| 138 | + -DLLVM_TARGETS_TO_BUILD=all |
| 139 | + -DLIBOMP_ARCH=x86_64 |
| 140 | + -DLLVM_BUILD_EXTERNAL_COMPILER_RT=ON |
| 141 | + -DLLVM_BUILD_LLVM_DYLIB=ON |
| 142 | + -DLLVM_LINK_LLVM_DYLIB=ON |
| 143 | + -DLLVM_ENABLE_LIBCXX=ON |
| 144 | + -DLLVM_ENABLE_FFI=ON |
| 145 | + -DFFI_INCLUDE_DIR=#{Formula["libffi"].opt_lib}/libffi-#{Formula["libffi"].version}/include |
| 146 | + -DFFI_LIBRARY_DIR=#{Formula["libffi"].opt_lib} |
| 147 | + -DLLVM_CREATE_XCODE_TOOLCHAIN=ON |
| 148 | + ] |
| 149 | + |
| 150 | + mkdir "build" do |
| 151 | + system "cmake", "-G", "Unix Makefiles", "..", *(std_cmake_args + args) |
| 152 | + system "make" |
| 153 | + system "make", "install" |
| 154 | + system "make", "install-xcode-toolchain" |
| 155 | + end |
| 156 | + |
| 157 | + (share/"clang-#{ver}/tools").install Dir["tools/clang/tools/scan-{build,view}"] |
| 158 | + inreplace share/"clang-#{ver}/tools/scan-build/bin/scan-build", "$RealBin/bin/clang", install_prefix/"bin/clang" |
| 159 | + (install_prefix/"bin").install_symlink share/"clang-#{ver}/tools/scan-view/bin/scan-view" |
| 160 | + (install_prefix/"bin").install_symlink share/"clang-#{ver}/tools/scan-build/bin/scan-build" |
| 161 | + (install_prefix/"share/man/man1").install_symlink share/"clang-#{ver}/tools/scan-build/scan-build.1" |
| 162 | + |
| 163 | + (lib/"python2.7/site-packages").install "bindings/python/llvm" => "llvm-#{ver}", |
| 164 | + clang_buildpath/"bindings/python/clang" => "clang-#{ver}" |
| 165 | + |
| 166 | + # replace the existing "clang -> clang-9" symlink |
| 167 | + rm install_prefix/"bin/clang" |
| 168 | + mv install_prefix/"bin/clang-9", install_prefix/"bin/clang" |
| 169 | + |
| 170 | + # These versioned .dylib symlinks are missing for some reason |
| 171 | + # Note that we use relative symlinks |
| 172 | + ln_s "libLLVM.dylib", install_prefix/"lib/libLLVM-9.dylib" |
| 173 | + |
| 174 | + # Set LC_LOAD_DYLIB entries to absolute paths |
| 175 | + system "install_name_tool", "-change", "@rpath/libLLVM.dylib", install_prefix/"lib/libLLVM.dylib", install_prefix/"lib/libLTO.dylib" |
| 176 | + system "install_name_tool", "-change", "@rpath/libLLVM.dylib", install_prefix/"lib/libLLVM.dylib", install_prefix/"lib/libclang.dylib" |
| 177 | + |
| 178 | + # Set LC_ID_DYLIB entries to absolute paths |
| 179 | + system "install_name_tool", "-id", install_prefix/"lib/libLLVM.dylib", install_prefix/"lib/libLLVM.dylib" |
| 180 | + system "install_name_tool", "-id", install_prefix/"lib/libLTO.dylib", install_prefix/"lib/libLTO.dylib" |
| 181 | + system "install_name_tool", "-id", install_prefix/"lib/libc++.1.0.dylib", install_prefix/"lib/libc++.1.0.dylib" |
| 182 | + system "install_name_tool", "-id", install_prefix/"lib/libclang.dylib", install_prefix/"lib/libclang.dylib" |
| 183 | + system "install_name_tool", "-id", install_prefix/"lib/libomp.dylib", install_prefix/"lib/libomp.dylib" |
| 184 | + system "install_name_tool", "-id", install_prefix/"lib/libunwind.1.0.dylib", install_prefix/"lib/libunwind.1.0.dylib" |
| 185 | + |
| 186 | + Dir.glob(install_prefix/"bin/*") do |exec_path| |
| 187 | + basename = File.basename(exec_path) |
| 188 | + bin.install_symlink exec_path => "#{basename}-#{ver}" |
| 189 | + end |
| 190 | + |
| 191 | + Dir.glob(install_prefix/"share/man/man1/*") do |manpage| |
| 192 | + basename = File.basename(manpage, ".1") |
| 193 | + man1.install_symlink manpage => "#{basename}-#{ver}.1" |
| 194 | + end |
| 195 | + end |
| 196 | + |
| 197 | + def caveats; <<~EOS |
| 198 | + Extra tools are installed in #{opt_share}/clang-#{ver} |
| 199 | +
|
| 200 | + To link to libc++, something like the following is required: |
| 201 | + CXX="clang++-#{ver} -stdlib=libc++" |
| 202 | + CXXFLAGS="$CXXFLAGS -nostdinc++ -I#{opt_lib}/llvm-#{ver}/include/c++/v1" |
| 203 | + LDFLAGS="$LDFLAGS -L#{opt_lib}/llvm-#{ver}/lib" |
| 204 | + EOS |
| 205 | + end |
| 206 | + |
| 207 | + test do |
| 208 | + assert_equal prefix.to_s, shell_output("#{bin}/llvm-config-#{ver} --prefix").chomp |
| 209 | + |
| 210 | + # test for sed errors since some llvm makefiles assume that sed |
| 211 | + # understands '\n' which is true for gnu sed and not for bsd sed. |
| 212 | + assert_no_match /PATH\)n/, (lib/"llvm-#{ver}/share/llvm/cmake/LLVMConfig.cmake").read |
| 213 | + system "#{bin}/llvm-config-#{ver}", "--version" |
| 214 | + end |
| 215 | +end |
| 216 | + |
0 commit comments