Skip to content

Commit 886a5f6

Browse files
committed
add llvm-13
v13.0.1
1 parent d011a0d commit 886a5f6

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed

Formula/llvm-13.rb

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
class Llvm13 < Formula
2+
desc "Next-gen compiler infrastructure"
3+
homepage "http://llvm.org/"
4+
# The LLVM Project is under the Apache License v2.0 with LLVM Exceptions
5+
license "Apache-2.0" => { with: "LLVM-exception" }
6+
# revision 1
7+
8+
stable do
9+
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/llvm-project-13.0.1.src.tar.xz"
10+
sha256 "326335a830f2e32d06d0a36393b5455d17dc73e0bd1211065227ee014f92cbf8"
11+
end
12+
13+
bottle do
14+
end
15+
16+
# Clang cannot find system headers if Xcode CLT is not installed
17+
pour_bottle? do
18+
on_macos do
19+
reason "The bottle needs the Xcode CLT to be installed."
20+
satisfy { MacOS::CLT.installed? }
21+
end
22+
end
23+
24+
# http://releases.llvm.org/13.0.0/docs/GettingStarted.html#requirements
25+
depends_on "cmake" => :build
26+
27+
uses_from_macos "libedit"
28+
uses_from_macos "libffi", since: :catalina
29+
uses_from_macos "libxml2"
30+
uses_from_macos "ncurses"
31+
uses_from_macos "zlib"
32+
33+
# version suffix
34+
def version
35+
"13"
36+
end
37+
38+
# http://releases.llvm.org/13.0.0/docs/CMake.html
39+
def install
40+
projects = %w[
41+
clang
42+
clang-tools-extra
43+
compiler-rt
44+
libcxx
45+
libcxxabi
46+
libunwind
47+
lld
48+
lldb
49+
mlir
50+
openmp
51+
polly
52+
]
53+
runtimes = %w[
54+
]
55+
56+
# Apple's libstdc++ is too old to build LLVM
57+
ENV.libcxx if ENV.compiler == :clang
58+
59+
# compiler-rt has some iOS simulator features that require i386 symbols. I'm
60+
# assuming the rest of clang also needs support for 32-bit compilation to
61+
# work correctly, but if not, perhaps universal binaries could be limited to
62+
# compiler-rt. LLVM makes this somewhat easier because compiler-rt can
63+
# almost be treated as an entirely different build from LLVM.
64+
ENV.permit_arch_flags
65+
66+
install_prefix = lib/"llvm-#{version}"
67+
68+
args = %W[
69+
-DCMAKE_BUILD_TYPE=Release
70+
-DCMAKE_INSTALL_PREFIX=#{install_prefix}
71+
-DLLVM_ENABLE_PROJECTS=#{projects.join(";")}
72+
-DLLVM_ENABLE_RUNTIMES=#{runtimes.join(";")}
73+
-DLLVM_TARGETS_TO_BUILD=all
74+
-DLLVM_ENABLE_ASSERTIONS=ON
75+
-DLLVM_OPTIMIZED_TABLEGEN=ON
76+
-DLLVM_INCLUDE_DOCS=OFF
77+
-DLLVM_INCLUDE_TESTS=OFF
78+
-DLLVM_ENABLE_RTTI=ON
79+
-DLLVM_ENABLE_EH=ON
80+
-DLLVM_INSTALL_UTILS=ON
81+
-DLLVM_ENABLE_Z3_SOLVER=OFF
82+
-DLLVM_BUILD_EXTERNAL_COMPILER_RT=ON
83+
-DLLVM_BUILD_LLVM_C_DYLIB=ON
84+
-DLLVM_LINK_LLVM_DYLIB=ON
85+
-DLLVM_ENABLE_LIBCXX=ON
86+
-DLLVM_ENABLE_FFI=ON
87+
-DLLVM_CREATE_XCODE_TOOLCHAIN=ON
88+
-DLLVM_CREATE_XCODE_TOOLCHAIN=#{MacOS::Xcode.installed? ? "ON" : "OFF"}
89+
-DLLDB_USE_SYSTEM_DEBUGSERVER=ON
90+
]
91+
92+
if MacOS.version >= :catalina
93+
args << "-DFFI_INCLUDE_DIR=#{MacOS.sdk_path}/usr/include/ffi"
94+
args << "-DFFI_LIBRARY_DIR=#{MacOS.sdk_path}/usr/lib"
95+
else
96+
args << "-DFFI_INCLUDE_DIR=#{Formula["libffi"].opt_include}"
97+
args << "-DFFI_LIBRARY_DIR=#{Formula["libffi"].opt_lib}"
98+
end
99+
100+
sdk = MacOS.sdk_path_if_needed
101+
args << "-DDEFAULT_SYSROOT=#{sdk}" if sdk
102+
103+
if MacOS.version == :mojave && MacOS::CLT.installed?
104+
# Mojave CLT linker via software update is older than Xcode.
105+
# Use it to retain compatibility.
106+
args << "-DCMAKE_LINKER=/Library/Developer/CommandLineTools/usr/bin/ld"
107+
end
108+
109+
llvmpath = buildpath/"llvm"
110+
mkdir llvmpath/"build" do
111+
system "cmake", "-G", "Unix Makefiles", "..", *(std_cmake_args + args)
112+
system "cmake", "--build", "."
113+
system "cmake", "--build", ".", "--target", "install"
114+
system "cmake", "--build", ".", "--target", "install-xcode-toolchain" if MacOS::Xcode.installed?
115+
end
116+
117+
# replace the existing "clang -> clang-13" symlink
118+
rm install_prefix/"bin/clang"
119+
mv install_prefix/"bin/clang-#{version}", install_prefix/"bin/clang"
120+
121+
# These versioned .dylib symlinks are missing for some reason
122+
# Note that we use relative symlinks
123+
ln_s "libLLVM.dylib", install_prefix/"lib/libLLVM-#{version}.dylib"
124+
125+
Dir.glob(install_prefix/"bin/*") do |exec_path|
126+
basename = File.basename(exec_path)
127+
bin.install_symlink exec_path => "#{basename}-#{version}"
128+
end
129+
130+
Dir.glob(install_prefix/"share/man/man1/*") do |manpage|
131+
basename = File.basename(manpage, ".1")
132+
man1.install_symlink manpage => "#{basename}-#{version}.1"
133+
end
134+
end
135+
136+
def caveats
137+
<<~EOS
138+
Extra tools are installed in #{opt_share}/clang-#{version}
139+
140+
To link to libc++, something like the following is required:
141+
CXX="clang++-#{version} -stdlib=libc++"
142+
CXXFLAGS="$CXXFLAGS -nostdinc++ -I#{opt_lib}/llvm-#{version}/include/c++/v1"
143+
LDFLAGS="$LDFLAGS -L#{opt_lib}/llvm-#{version}/lib"
144+
EOS
145+
end
146+
147+
test do
148+
assert_equal prefix.to_s, shell_output("#{bin}/llvm-config-#{version} --prefix").chomp
149+
150+
# test for sed errors since some llvm makefiles assume that sed
151+
# understands '\n' which is true for gnu sed and not for bsd sed.
152+
assert_no_match(/PATH\)n/, (lib/"llvm-#{version}/share/llvm/cmake/LLVMConfig.cmake").read)
153+
system "#{bin}/llvm-config-#{version}", "--version"
154+
end
155+
end
156+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ It currently provides:
1818
* llvm-10
1919
* llvm-11
2020
* llvm-12
21+
* llvm-13
2122

2223

2324
## Quickstart

0 commit comments

Comments
 (0)