2019-03-21 14:41:45 +00:00
|
|
|
class LlvmAT7 < Formula
|
|
|
|
desc "Next-gen compiler infrastructure"
|
|
|
|
homepage "https://llvm.org/"
|
2019-07-21 00:00:46 +00:00
|
|
|
url "https://releases.llvm.org/7.1.0/llvm-7.1.0.src.tar.xz"
|
|
|
|
sha256 "1bcc9b285074ded87b88faaedddb88e6b5d6c331dfcfb57d7f3393dd622b3764"
|
2019-03-21 14:41:45 +00:00
|
|
|
|
2019-03-22 00:59:06 +00:00
|
|
|
bottle do
|
|
|
|
cellar :any
|
2019-07-21 04:45:31 +00:00
|
|
|
sha256 "5140804e0811f7fd438e4f71f482b1009e59626704ed4c203180ddeeec4679de" => :mojave
|
|
|
|
sha256 "b5ea5a124052b61ae6209346ab7626c2042c0c697d67f4d3a1d2350abd72d24b" => :high_sierra
|
|
|
|
sha256 "7cf4cfc283d47db73b00b73a3ad50c058cc9abf897829db25bf1f83726f15e2d" => :sierra
|
2019-03-22 00:59:06 +00:00
|
|
|
end
|
|
|
|
|
2019-03-21 14:41:45 +00:00
|
|
|
# Clang cannot find system headers if Xcode CLT is not installed
|
|
|
|
pour_bottle? do
|
|
|
|
reason "The bottle needs the Xcode CLT to be installed."
|
|
|
|
satisfy { MacOS::CLT.installed? }
|
|
|
|
end
|
|
|
|
|
|
|
|
keg_only :versioned_formula
|
|
|
|
|
|
|
|
# https://llvm.org/docs/GettingStarted.html#requirement
|
|
|
|
depends_on "cmake" => :build
|
|
|
|
depends_on :xcode => :build
|
|
|
|
depends_on "libffi"
|
|
|
|
|
|
|
|
resource "clang" do
|
2019-07-21 00:00:46 +00:00
|
|
|
url "https://releases.llvm.org/7.1.0/cfe-7.1.0.src.tar.xz"
|
|
|
|
sha256 "e97dc472aae52197a4d5e0185eb8f9e04d7575d2dc2b12194ddc768e0f8a846d"
|
2019-03-21 14:41:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
resource "clang-extra-tools" do
|
2019-07-21 00:00:46 +00:00
|
|
|
url "https://releases.llvm.org/7.1.0/clang-tools-extra-7.1.0.src.tar.xz"
|
|
|
|
sha256 "1ce0042c48ecea839ce67b87e9739cf18e7a5c2b3b9a36d177d00979609b6451"
|
2019-03-21 14:41:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
resource "compiler-rt" do
|
2019-07-21 00:00:46 +00:00
|
|
|
url "https://releases.llvm.org/7.1.0/compiler-rt-7.1.0.src.tar.xz"
|
|
|
|
sha256 "057bdac0581215b5ceb39edfd5bbef9eb79578f16a8908349f3066251fba88d8"
|
2019-03-21 14:41:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
resource "libcxx" do
|
2019-07-21 00:00:46 +00:00
|
|
|
url "https://releases.llvm.org/7.1.0/libcxx-7.1.0.src.tar.xz"
|
|
|
|
sha256 "4442b408eaea3c1e4aa2cf21da38aba9f0856b4b522b1c3d555c3251af62b04e"
|
2019-03-21 14:41:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
resource "libunwind" do
|
2019-07-21 00:00:46 +00:00
|
|
|
url "https://releases.llvm.org/7.1.0/libunwind-7.1.0.src.tar.xz"
|
|
|
|
sha256 "174a7fc9eb7422c8ea96993649be0f80ca5937f3fe000c40c3d15b1074d7ad0c"
|
2019-03-21 14:41:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
resource "lld" do
|
2019-07-21 00:00:46 +00:00
|
|
|
url "https://releases.llvm.org/7.1.0/lld-7.1.0.src.tar.xz"
|
|
|
|
sha256 "a10f274a0a09408eaf9c088dec6fb2254f7d641221437763c94546cbfe595867"
|
2019-03-21 14:41:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
resource "openmp" do
|
2019-07-21 00:00:46 +00:00
|
|
|
url "https://releases.llvm.org/7.1.0/openmp-7.1.0.src.tar.xz"
|
|
|
|
sha256 "1ee73aa1eef4ef7f75c96b24bf02445440602064c0074891ca5344a63f1fe5b5"
|
2019-03-21 14:41:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
resource "polly" do
|
2019-07-21 00:00:46 +00:00
|
|
|
url "https://releases.llvm.org/7.1.0/polly-7.1.0.src.tar.xz"
|
|
|
|
sha256 "305454f72db5e30def3f48e2dc56ce62f9c52c3b9278b8f357a093a588b6139b"
|
2019-03-21 14:41:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def install
|
|
|
|
# Apple's libstdc++ is too old to build LLVM
|
|
|
|
ENV.libcxx if ENV.compiler == :clang
|
|
|
|
|
|
|
|
(buildpath/"tools/clang").install resource("clang")
|
|
|
|
(buildpath/"tools/clang/tools/extra").install resource("clang-extra-tools")
|
|
|
|
(buildpath/"projects/openmp").install resource("openmp")
|
|
|
|
(buildpath/"projects/libcxx").install resource("libcxx")
|
|
|
|
(buildpath/"projects/libunwind").install resource("libunwind")
|
|
|
|
(buildpath/"tools/lld").install resource("lld")
|
|
|
|
(buildpath/"tools/polly").install resource("polly")
|
|
|
|
(buildpath/"projects/compiler-rt").install resource("compiler-rt")
|
|
|
|
|
|
|
|
# compiler-rt has some iOS simulator features that require i386 symbols
|
|
|
|
# I'm assuming the rest of clang needs support too 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
|
|
|
|
|
|
|
|
args = %W[
|
|
|
|
-DLIBOMP_ARCH=x86_64
|
|
|
|
-DLINK_POLLY_INTO_TOOLS=ON
|
|
|
|
-DLLVM_BUILD_EXTERNAL_COMPILER_RT=ON
|
|
|
|
-DLLVM_BUILD_LLVM_DYLIB=ON
|
|
|
|
-DLLVM_ENABLE_EH=ON
|
|
|
|
-DLLVM_ENABLE_FFI=ON
|
|
|
|
-DLLVM_ENABLE_LIBCXX=ON
|
|
|
|
-DLLVM_ENABLE_RTTI=ON
|
|
|
|
-DLLVM_INCLUDE_DOCS=OFF
|
|
|
|
-DLLVM_INSTALL_UTILS=ON
|
|
|
|
-DLLVM_OPTIMIZED_TABLEGEN=ON
|
|
|
|
-DLLVM_TARGETS_TO_BUILD=all
|
|
|
|
-DWITH_POLLY=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/"cmake").install "cmake/modules"
|
|
|
|
(share/"clang/tools").install Dir["tools/clang/tools/scan-{build,view}"]
|
|
|
|
|
|
|
|
# scan-build is in Perl, so the @ in our path needs to be escaped
|
|
|
|
inreplace "#{share}/clang/tools/scan-build/bin/scan-build",
|
|
|
|
"$RealBin/bin/clang", "#{bin}/clang".gsub("@", "\\@")
|
|
|
|
|
|
|
|
bin.install_symlink share/"clang/tools/scan-build/bin/scan-build", share/"clang/tools/scan-view/bin/scan-view"
|
|
|
|
man1.install_symlink share/"clang/tools/scan-build/man/scan-build.1"
|
|
|
|
|
|
|
|
# install llvm python bindings
|
|
|
|
(lib/"python2.7/site-packages").install buildpath/"bindings/python/llvm"
|
|
|
|
(lib/"python2.7/site-packages").install buildpath/"tools/clang/bindings/python/clang"
|
|
|
|
end
|
|
|
|
|
|
|
|
def caveats; <<~EOS
|
|
|
|
To use the bundled libc++ please add the following LDFLAGS:
|
|
|
|
LDFLAGS="-L#{opt_lib} -Wl,-rpath,#{opt_lib}"
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
|
|
|
|
test do
|
|
|
|
assert_equal prefix.to_s, shell_output("#{bin}/llvm-config --prefix").chomp
|
|
|
|
|
|
|
|
(testpath/"omptest.c").write <<~EOS
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <omp.h>
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
#pragma omp parallel num_threads(4)
|
|
|
|
{
|
|
|
|
printf("Hello from thread %d, nthreads %d\\n", omp_get_thread_num(), omp_get_num_threads());
|
|
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
|
|
|
clean_version = version.to_s[/(\d+\.?)+/]
|
|
|
|
|
|
|
|
system "#{bin}/clang", "-L#{lib}", "-fopenmp", "-nobuiltininc",
|
|
|
|
"-I#{lib}/clang/#{clean_version}/include",
|
|
|
|
"omptest.c", "-o", "omptest"
|
|
|
|
testresult = shell_output("./omptest")
|
|
|
|
|
|
|
|
sorted_testresult = testresult.split("\n").sort.join("\n")
|
|
|
|
expected_result = <<~EOS
|
|
|
|
Hello from thread 0, nthreads 4
|
|
|
|
Hello from thread 1, nthreads 4
|
|
|
|
Hello from thread 2, nthreads 4
|
|
|
|
Hello from thread 3, nthreads 4
|
|
|
|
EOS
|
|
|
|
assert_equal expected_result.strip, sorted_testresult.strip
|
|
|
|
|
|
|
|
(testpath/"test.c").write <<~EOS
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
printf("Hello World!\\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
|
|
|
(testpath/"test.cpp").write <<~EOS
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
std::cout << "Hello World!" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
|
|
|
# Testing Command Line Tools
|
|
|
|
if MacOS::CLT.installed?
|
|
|
|
libclangclt = Dir["/Library/Developer/CommandLineTools/usr/lib/clang/#{MacOS::CLT.version.to_i}*"].last { |f| File.directory? f }
|
|
|
|
|
|
|
|
system "#{bin}/clang++", "-v", "-nostdinc",
|
|
|
|
"-I/Library/Developer/CommandLineTools/usr/include/c++/v1",
|
|
|
|
"-I#{libclangclt}/include",
|
|
|
|
"-I/usr/include", # need it because /Library/.../usr/include/c++/v1/iosfwd refers to <wchar.h>, which CLT installs to /usr/include
|
|
|
|
"test.cpp", "-o", "testCLT++"
|
|
|
|
assert_includes MachO::Tools.dylibs("testCLT++"), "/usr/lib/libc++.1.dylib"
|
|
|
|
assert_equal "Hello World!", shell_output("./testCLT++").chomp
|
|
|
|
|
|
|
|
system "#{bin}/clang", "-v", "-nostdinc",
|
|
|
|
"-I/usr/include", # this is where CLT installs stdio.h
|
|
|
|
"test.c", "-o", "testCLT"
|
|
|
|
assert_equal "Hello World!", shell_output("./testCLT").chomp
|
|
|
|
end
|
|
|
|
|
|
|
|
# Testing Xcode
|
|
|
|
if MacOS::Xcode.installed?
|
|
|
|
libclangxc = Dir["#{MacOS::Xcode.toolchain_path}/usr/lib/clang/#{DevelopmentTools.clang_version}*"].last { |f| File.directory? f }
|
|
|
|
|
|
|
|
system "#{bin}/clang++", "-v", "-nostdinc",
|
|
|
|
"-I#{MacOS::Xcode.toolchain_path}/usr/include/c++/v1",
|
|
|
|
"-I#{libclangxc}/include",
|
|
|
|
"-I#{MacOS.sdk_path}/usr/include",
|
|
|
|
"test.cpp", "-o", "testXC++"
|
|
|
|
assert_includes MachO::Tools.dylibs("testXC++"), "/usr/lib/libc++.1.dylib"
|
|
|
|
assert_equal "Hello World!", shell_output("./testXC++").chomp
|
|
|
|
|
|
|
|
system "#{bin}/clang", "-v", "-nostdinc",
|
|
|
|
"-I#{MacOS.sdk_path}/usr/include",
|
|
|
|
"test.c", "-o", "testXC"
|
|
|
|
assert_equal "Hello World!", shell_output("./testXC").chomp
|
|
|
|
end
|
|
|
|
|
|
|
|
# link against installed libc++
|
|
|
|
# related to https://github.com/Homebrew/legacy-homebrew/issues/47149
|
|
|
|
system "#{bin}/clang++", "-v", "-nostdinc",
|
|
|
|
"-std=c++11", "-stdlib=libc++",
|
|
|
|
"-I#{MacOS::Xcode.toolchain_path}/usr/include/c++/v1",
|
|
|
|
"-I#{libclangxc}/include",
|
|
|
|
"-I#{MacOS.sdk_path}/usr/include",
|
|
|
|
"-L#{lib}",
|
|
|
|
"-Wl,-rpath,#{lib}", "test.cpp", "-o", "test"
|
|
|
|
assert_includes MachO::Tools.dylibs("test"), "#{opt_lib}/libc++.1.dylib"
|
|
|
|
assert_equal "Hello World!", shell_output("./test").chomp
|
|
|
|
end
|
|
|
|
end
|