-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
220 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
class Llvm10 < Formula | ||
desc "Next-gen compiler infrastructure" | ||
homepage "http://llvm.org/" | ||
|
||
version = "10.0.0" | ||
|
||
stable do | ||
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-#{version}/llvm-#{version}.src.tar.xz" | ||
sha256 "df83a44b3a9a71029049ec101fb0077ecbbdf5fe41e395215025779099a98fdf" | ||
|
||
resource "clang" do | ||
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-#{version}/clang-#{version}.src.tar.xz" | ||
sha256 "885b062b00e903df72631c5f98b9579ed1ed2790f74e5646b4234fa084eacb21" | ||
end | ||
|
||
resource "clang-tools-extra" do | ||
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-#{version}/clang-tools-extra-#{version}.src.tar.xz" | ||
sha256 "acdf8cf6574b40e6b1dabc93e76debb84a9feb6f22970126b04d4ba18b92911c" | ||
end | ||
|
||
resource "compiler-rt" do | ||
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-#{version}/compiler-rt-#{version}.src.tar.xz" | ||
sha256 "6a7da64d3a0a7320577b68b9ca4933bdcab676e898b759850e827333c3282c75" | ||
end | ||
|
||
resource "polly" do | ||
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-#{version}/polly-#{version}.src.tar.xz" | ||
sha256 "35fba6ed628896fe529be4c10407f1b1c8a7264d40c76bced212180e701b4d97" | ||
end | ||
|
||
resource "lld" do | ||
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-#{version}/lld-#{version}.src.tar.xz" | ||
sha256 "b9a0d7c576eeef05bc06d6e954938a01c5396cee1d1e985891e0b1cf16e3d708" | ||
end | ||
|
||
resource "openmp" do | ||
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-#{version}/openmp-#{version}.src.tar.xz" | ||
sha256 "3b9ff29a45d0509a1e9667a0feb43538ef402ea8cfc7df3758a01f20df08adfa" | ||
end | ||
|
||
resource "libcxx" do | ||
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-#{version}/libcxx-#{version}.src.tar.xz" | ||
sha256 "270f8a3f176f1981b0f6ab8aa556720988872ec2b48ed3b605d0ced8d09156c7" | ||
end | ||
|
||
resource "libunwind" do | ||
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-#{version}/libunwind-#{version}.src.tar.xz" | ||
sha256 "09dc5ecc4714809ecf62908ae8fe8635ab476880455287036a2730966833c626" | ||
end | ||
end | ||
|
||
bottle do | ||
end | ||
|
||
head do | ||
url "https://git.llvm.org/git/llvm.git" | ||
|
||
resource "clang" do | ||
url "https://git.llvm.org/git/clang.git" | ||
end | ||
|
||
resource "clang-extra-tools" do | ||
url "https://git.llvm.org/git/clang-tools-extra.git" | ||
end | ||
|
||
resource "compiler-rt" do | ||
url "https://git.llvm.org/git/compiler-rt.git" | ||
end | ||
|
||
resource "libcxx" do | ||
url "https://git.llvm.org/git/libcxx.git" | ||
end | ||
|
||
resource "libunwind" do | ||
url "https://git.llvm.org/git/libunwind.git" | ||
end | ||
|
||
resource "lld" do | ||
url "https://git.llvm.org/git/lld.git" | ||
end | ||
|
||
resource "lldb" do | ||
url "https://git.llvm.org/git/lldb.git" | ||
end | ||
|
||
resource "openmp" do | ||
url "https://git.llvm.org/git/openmp.git" | ||
end | ||
|
||
resource "polly" do | ||
url "https://git.llvm.org/git/polly.git" | ||
end | ||
end | ||
|
||
# http://releases.llvm.org/10.0.0/docs/GettingStarted.html#requirements | ||
depends_on "libffi" | ||
depends_on "cmake" => :build | ||
depends_on :xcode => :build | ||
|
||
# version suffix | ||
def ver | ||
"10" | ||
end | ||
|
||
# http://releases.llvm.org/10.0.0/docs/CMake.html | ||
def install | ||
# 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 | ||
|
||
clang_buildpath = buildpath/"tools/clang" | ||
libcxx_buildpath = buildpath/"projects/libcxx" | ||
|
||
clang_buildpath.install resource("clang") | ||
libcxx_buildpath.install resource("libcxx") | ||
(buildpath/"tools/lld").install resource("lld") | ||
(buildpath/"tools/polly").install resource("polly") | ||
(buildpath/"tools/clang/tools/extra").install resource("clang-tools-extra") | ||
(buildpath/"projects/openmp").install resource("openmp") | ||
(buildpath/"projects/libunwind").install resource("libunwind") | ||
(buildpath/"projects/compiler-rt").install resource("compiler-rt") | ||
|
||
install_prefix = lib/"llvm-#{ver}" | ||
|
||
args = %W[ | ||
-DCMAKE_INSTALL_PREFIX=#{install_prefix} | ||
-DCMAKE_BUILD_TYPE=Release | ||
-DLLVM_ENABLE_ASSERTIONS=ON | ||
-DLLVM_OPTIMIZED_TABLEGEN=ON | ||
-DLLVM_INCLUDE_DOCS=OFF | ||
-DLLVM_ENABLE_RTTI=ON | ||
-DLLVM_ENABLE_EH=ON | ||
-DLLVM_INSTALL_UTILS=ON | ||
-DWITH_POLLY=ON | ||
-DLINK_POLLY_INTO_TOOLS=ON | ||
-DLLVM_TARGETS_TO_BUILD=all | ||
-DLIBOMP_ARCH=x86_64 | ||
-DLLVM_BUILD_EXTERNAL_COMPILER_RT=ON | ||
-DLLVM_BUILD_LLVM_DYLIB=ON | ||
-DLLVM_LINK_LLVM_DYLIB=ON | ||
-DLLVM_ENABLE_LIBCXX=ON | ||
-DLLVM_ENABLE_FFI=ON | ||
-DFFI_INCLUDE_DIR=#{Formula["libffi"].opt_lib}/libffi-#{Formula["libffi"].version}/include | ||
-DFFI_LIBRARY_DIR=#{Formula["libffi"].opt_lib} | ||
-DLLVM_CREATE_XCODE_TOOLCHAIN=ON | ||
] | ||
|
||
mkdir "build" do | ||
system "cmake", "-G", "Unix Makefiles", "..", *(std_cmake_args + args) | ||
system "make" | ||
system "make", "install" | ||
system "make", "install-xcode-toolchain" | ||
end | ||
|
||
(share/"clang-#{ver}/tools").install Dir["tools/clang/tools/scan-{build,view}"] | ||
inreplace share/"clang-#{ver}/tools/scan-build/bin/scan-build", "$RealBin/bin/clang", install_prefix/"bin/clang" | ||
(install_prefix/"bin").install_symlink share/"clang-#{ver}/tools/scan-view/bin/scan-view" | ||
(install_prefix/"bin").install_symlink share/"clang-#{ver}/tools/scan-build/bin/scan-build" | ||
(install_prefix/"share/man/man1").install_symlink share/"clang-#{ver}/tools/scan-build/scan-build.1" | ||
|
||
(lib/"python2.7/site-packages").install "bindings/python/llvm" => "llvm-#{ver}", | ||
clang_buildpath/"bindings/python/clang" => "clang-#{ver}" | ||
|
||
# replace the existing "clang -> clang-10" symlink | ||
rm install_prefix/"bin/clang" | ||
mv install_prefix/"bin/clang-#{ver}", 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-#{ver}.dylib" | ||
|
||
# Set LC_LOAD_DYLIB entries to absolute paths | ||
system "install_name_tool", "-change", "@rpath/libLLVM.dylib", install_prefix/"lib/libLLVM.dylib", install_prefix/"lib/libLTO.dylib" | ||
system "install_name_tool", "-change", "@rpath/libLLVM.dylib", install_prefix/"lib/libLLVM.dylib", install_prefix/"lib/libclang.dylib" | ||
|
||
# Set LC_ID_DYLIB entries to absolute paths | ||
system "install_name_tool", "-id", install_prefix/"lib/libLLVM.dylib", install_prefix/"lib/libLLVM.dylib" | ||
system "install_name_tool", "-id", install_prefix/"lib/libLTO.dylib", install_prefix/"lib/libLTO.dylib" | ||
system "install_name_tool", "-id", install_prefix/"lib/libc++.1.0.dylib", install_prefix/"lib/libc++.1.0.dylib" | ||
system "install_name_tool", "-id", install_prefix/"lib/libclang.dylib", install_prefix/"lib/libclang.dylib" | ||
system "install_name_tool", "-id", install_prefix/"lib/libomp.dylib", install_prefix/"lib/libomp.dylib" | ||
system "install_name_tool", "-id", install_prefix/"lib/libunwind.1.0.dylib", install_prefix/"lib/libunwind.1.0.dylib" | ||
|
||
Dir.glob(install_prefix/"bin/*") do |exec_path| | ||
basename = File.basename(exec_path) | ||
bin.install_symlink exec_path => "#{basename}-#{ver}" | ||
end | ||
|
||
Dir.glob(install_prefix/"share/man/man1/*") do |manpage| | ||
basename = File.basename(manpage, ".1") | ||
man1.install_symlink manpage => "#{basename}-#{ver}.1" | ||
end | ||
end | ||
|
||
def caveats; <<~EOS | ||
Extra tools are installed in #{opt_share}/clang-#{ver} | ||
To link to libc++, something like the following is required: | ||
CXX="clang++-#{ver} -stdlib=libc++" | ||
CXXFLAGS="$CXXFLAGS -nostdinc++ -I#{opt_lib}/llvm-#{ver}/include/c++/v1" | ||
LDFLAGS="$LDFLAGS -L#{opt_lib}/llvm-#{ver}/lib" | ||
EOS | ||
end | ||
|
||
test do | ||
assert_equal prefix.to_s, shell_output("#{bin}/llvm-config-#{ver} --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-#{ver}/share/llvm/cmake/LLVMConfig.cmake").read | ||
system "#{bin}/llvm-config-#{ver}", "--version" | ||
end | ||
end | ||
|