From 886a5f6ce5aae7149987404c3f879d2c93b79ae8 Mon Sep 17 00:00:00 2001 From: "Trevor L. McDonell" Date: Thu, 24 Feb 2022 18:30:21 +0100 Subject: [PATCH] add llvm-13 v13.0.1 --- Formula/llvm-13.rb | 156 +++++++++++++++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 157 insertions(+) create mode 100644 Formula/llvm-13.rb diff --git a/Formula/llvm-13.rb b/Formula/llvm-13.rb new file mode 100644 index 0000000..bca8463 --- /dev/null +++ b/Formula/llvm-13.rb @@ -0,0 +1,156 @@ +class Llvm13 < Formula + desc "Next-gen compiler infrastructure" + homepage "http://llvm.org/" + # The LLVM Project is under the Apache License v2.0 with LLVM Exceptions + license "Apache-2.0" => { with: "LLVM-exception" } + # revision 1 + + stable do + url "https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/llvm-project-13.0.1.src.tar.xz" + sha256 "326335a830f2e32d06d0a36393b5455d17dc73e0bd1211065227ee014f92cbf8" + end + + bottle do + end + + # Clang cannot find system headers if Xcode CLT is not installed + pour_bottle? do + on_macos do + reason "The bottle needs the Xcode CLT to be installed." + satisfy { MacOS::CLT.installed? } + end + end + + # http://releases.llvm.org/13.0.0/docs/GettingStarted.html#requirements + depends_on "cmake" => :build + + uses_from_macos "libedit" + uses_from_macos "libffi", since: :catalina + uses_from_macos "libxml2" + uses_from_macos "ncurses" + uses_from_macos "zlib" + + # version suffix + def version + "13" + end + + # http://releases.llvm.org/13.0.0/docs/CMake.html + def install + projects = %w[ + clang + clang-tools-extra + compiler-rt + libcxx + libcxxabi + libunwind + lld + lldb + mlir + openmp + polly + ] + runtimes = %w[ + ] + + # Apple's libstdc++ is too old to build LLVM + ENV.libcxx if ENV.compiler == :clang + + # compiler-rt has some iOS simulator features that require i386 symbols. I'm + # assuming the rest of clang also needs support for 32-bit compilation to + # work correctly, but if not, perhaps universal binaries could be limited to + # compiler-rt. LLVM makes this somewhat easier because compiler-rt can + # almost be treated as an entirely different build from LLVM. + ENV.permit_arch_flags + + install_prefix = lib/"llvm-#{version}" + + args = %W[ + -DCMAKE_BUILD_TYPE=Release + -DCMAKE_INSTALL_PREFIX=#{install_prefix} + -DLLVM_ENABLE_PROJECTS=#{projects.join(";")} + -DLLVM_ENABLE_RUNTIMES=#{runtimes.join(";")} + -DLLVM_TARGETS_TO_BUILD=all + -DLLVM_ENABLE_ASSERTIONS=ON + -DLLVM_OPTIMIZED_TABLEGEN=ON + -DLLVM_INCLUDE_DOCS=OFF + -DLLVM_INCLUDE_TESTS=OFF + -DLLVM_ENABLE_RTTI=ON + -DLLVM_ENABLE_EH=ON + -DLLVM_INSTALL_UTILS=ON + -DLLVM_ENABLE_Z3_SOLVER=OFF + -DLLVM_BUILD_EXTERNAL_COMPILER_RT=ON + -DLLVM_BUILD_LLVM_C_DYLIB=ON + -DLLVM_LINK_LLVM_DYLIB=ON + -DLLVM_ENABLE_LIBCXX=ON + -DLLVM_ENABLE_FFI=ON + -DLLVM_CREATE_XCODE_TOOLCHAIN=ON + -DLLVM_CREATE_XCODE_TOOLCHAIN=#{MacOS::Xcode.installed? ? "ON" : "OFF"} + -DLLDB_USE_SYSTEM_DEBUGSERVER=ON + ] + + if MacOS.version >= :catalina + args << "-DFFI_INCLUDE_DIR=#{MacOS.sdk_path}/usr/include/ffi" + args << "-DFFI_LIBRARY_DIR=#{MacOS.sdk_path}/usr/lib" + else + args << "-DFFI_INCLUDE_DIR=#{Formula["libffi"].opt_include}" + args << "-DFFI_LIBRARY_DIR=#{Formula["libffi"].opt_lib}" + end + + sdk = MacOS.sdk_path_if_needed + args << "-DDEFAULT_SYSROOT=#{sdk}" if sdk + + if MacOS.version == :mojave && MacOS::CLT.installed? + # Mojave CLT linker via software update is older than Xcode. + # Use it to retain compatibility. + args << "-DCMAKE_LINKER=/Library/Developer/CommandLineTools/usr/bin/ld" + end + + llvmpath = buildpath/"llvm" + mkdir llvmpath/"build" do + system "cmake", "-G", "Unix Makefiles", "..", *(std_cmake_args + args) + system "cmake", "--build", "." + system "cmake", "--build", ".", "--target", "install" + system "cmake", "--build", ".", "--target", "install-xcode-toolchain" if MacOS::Xcode.installed? + end + + # replace the existing "clang -> clang-13" symlink + rm install_prefix/"bin/clang" + mv install_prefix/"bin/clang-#{version}", install_prefix/"bin/clang" + + # These versioned .dylib symlinks are missing for some reason + # Note that we use relative symlinks + ln_s "libLLVM.dylib", install_prefix/"lib/libLLVM-#{version}.dylib" + + Dir.glob(install_prefix/"bin/*") do |exec_path| + basename = File.basename(exec_path) + bin.install_symlink exec_path => "#{basename}-#{version}" + end + + Dir.glob(install_prefix/"share/man/man1/*") do |manpage| + basename = File.basename(manpage, ".1") + man1.install_symlink manpage => "#{basename}-#{version}.1" + end + end + + def caveats + <<~EOS + Extra tools are installed in #{opt_share}/clang-#{version} + + To link to libc++, something like the following is required: + CXX="clang++-#{version} -stdlib=libc++" + CXXFLAGS="$CXXFLAGS -nostdinc++ -I#{opt_lib}/llvm-#{version}/include/c++/v1" + LDFLAGS="$LDFLAGS -L#{opt_lib}/llvm-#{version}/lib" + EOS + end + + test do + assert_equal prefix.to_s, shell_output("#{bin}/llvm-config-#{version} --prefix").chomp + + # test for sed errors since some llvm makefiles assume that sed + # understands '\n' which is true for gnu sed and not for bsd sed. + assert_no_match(/PATH\)n/, (lib/"llvm-#{version}/share/llvm/cmake/LLVMConfig.cmake").read) + system "#{bin}/llvm-config-#{version}", "--version" + end +end + diff --git a/README.md b/README.md index f011fd4..da34c53 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ It currently provides: * llvm-10 * llvm-11 * llvm-12 + * llvm-13 ## Quickstart