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