|
| 1 | +class Llvm8 < Formula |
| 2 | + desc "Next-gen compiler infrastructure" |
| 3 | + homepage "http://llvm.org/" |
| 4 | + |
| 5 | + version = "8.0.0" |
| 6 | + |
| 7 | + stable do |
| 8 | + url "http://releases.llvm.org/#{version}/llvm-#{version}.src.tar.xz" |
| 9 | + sha256 "8872be1b12c61450cacc82b3d153eab02be2546ef34fa3580ed14137bb26224c" |
| 10 | + |
| 11 | + resource "clang" do |
| 12 | + url "http://releases.llvm.org/#{version}/cfe-#{version}.src.tar.xz" |
| 13 | + sha256 "084c115aab0084e63b23eee8c233abb6739c399e29966eaeccfc6e088e0b736b" |
| 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 "4f00122be408a7482f2004bcf215720d2b88cf8dc78b824abb225da8ad359d4b" |
| 19 | + end |
| 20 | + |
| 21 | + resource "compiler-rt" do |
| 22 | + url "http://releases.llvm.org/#{version}/compiler-rt-#{version}.src.tar.xz" |
| 23 | + sha256 "b435c7474f459e71b2831f1a4e3f1d21203cb9c0172e94e9d9b69f50354f21b1" |
| 24 | + end |
| 25 | + |
| 26 | + resource "polly" do |
| 27 | + url "http://releases.llvm.org/#{version}/polly-#{version}.src.tar.xz" |
| 28 | + sha256 "e3f5a3d6794ef8233af302c45ceb464b74cdc369c1ac735b6b381b21e4d89df4" |
| 29 | + end |
| 30 | + |
| 31 | + resource "lld" do |
| 32 | + url "http://releases.llvm.org/#{version}/lld-#{version}.src.tar.xz" |
| 33 | + sha256 "9caec8ec922e32ffa130f0fb08e4c5a242d7e68ce757631e425e9eba2e1a6e37" |
| 34 | + end |
| 35 | + |
| 36 | + resource "openmp" do |
| 37 | + url "http://releases.llvm.org/#{version}/openmp-#{version}.src.tar.xz" |
| 38 | + sha256 "f7b1705d2f16c4fc23d6531f67d2dd6fb78a077dd346b02fed64f4b8df65c9d5" |
| 39 | + end |
| 40 | + |
| 41 | + resource "libcxx" do |
| 42 | + url "http://releases.llvm.org/#{version}/libcxx-#{version}.src.tar.xz" |
| 43 | + sha256 "c2902675e7c84324fb2c1e45489220f250ede016cc3117186785d9dc291f9de2" |
| 44 | + end |
| 45 | + |
| 46 | + resource "libunwind" do |
| 47 | + url "http://releases.llvm.org/#{version}/libunwind-#{version}.src.tar.xz" |
| 48 | + sha256 "ff243a669c9cef2e2537e4f697d6fb47764ea91949016f2d643cb5d8286df660" |
| 49 | + end |
| 50 | + end |
| 51 | + |
| 52 | + bottle do |
| 53 | + end |
| 54 | + |
| 55 | + head do |
| 56 | + url "http://llvm.org/git/llvm.git", :branch => "release_80" |
| 57 | + |
| 58 | + resource "clang" do |
| 59 | + url "http://llvm.org/git/clang.git", :branch => "release_80" |
| 60 | + end |
| 61 | + |
| 62 | + resource "clang-tools-extra" do |
| 63 | + url "http://llvm.org/git/clang-tools-extra.git", :branch => "release_80" |
| 64 | + end |
| 65 | + |
| 66 | + resource "compiler-rt" do |
| 67 | + url "http://llvm.org/git/compiler-rt.git", :branch => "release_80" |
| 68 | + end |
| 69 | + |
| 70 | + resource "polly" do |
| 71 | + url "http://llvm.org/git/polly.git", :branch => "release_80" |
| 72 | + end |
| 73 | + |
| 74 | + resource "lld" do |
| 75 | + url "http://llvm.org/git/lld.git", :branch => "release_80" |
| 76 | + end |
| 77 | + |
| 78 | + resource "openmp" do |
| 79 | + url "http://llvm.org/git/openmp.git", :branch => "release_80" |
| 80 | + end |
| 81 | + |
| 82 | + resource "libcxx" do |
| 83 | + url "http://llvm.org/git/libcxx.git", :branch => "release_80" |
| 84 | + end |
| 85 | + |
| 86 | + resource "libunwind" do |
| 87 | + url "http://llvm.org/git/libunwind.git", :branch => "release_80" |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 91 | + # http://releases.llvm.org/8.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 | + "8" |
| 99 | + end |
| 100 | + |
| 101 | + # http://releases.llvm.org/8.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-8" symlink |
| 167 | + rm install_prefix/"bin/clang" |
| 168 | + mv install_prefix/"bin/clang-8", 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-8.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