@@ -3,6 +3,7 @@ set_policy("compatibility.version", "3.0")
33add_requires (" llvm" , {
44 system = false ,
55 configs = {
6+ mode = get_config (" mode" ),
67 debug = is_mode (" debug" ),
78 shared = is_mode (" debug" ) and not is_plat (" windows" ),
89 },
@@ -14,21 +15,20 @@ local sparse_checkout_list = {
1415 " clang" ,
1516 " clang-tools-extra" ,
1617}
17- -- Enable asan
18- if is_mode (" debug" ) then
19- table.insert (sparse_checkout_list , " runtimes" )
20- table.insert (sparse_checkout_list , " compiler-rt" )
21- end
18+
19+ -- TODO: If we need compiler-rt builtin-headers, then we need to enable them.
20+ -- if is_mode("debug") then
21+ -- table.insert(sparse_checkout_list, "runtimes")
22+ -- table.insert(sparse_checkout_list, "compiler-rt")
23+ -- end
2224
2325package (" llvm" )
24- set_urls (" https://github.com/llvm/llvm-project/releases/download/llvmorg-$(version)/llvm-project-$(version).src.tar.xz" ,
25- " https://github.com/llvm/llvm-project.git" , {includes = sparse_checkout_list })
26+ add_urls (" https://github.com/llvm/llvm-project.git" , {alias = " git" , includes = sparse_checkout_list })
2627
27- add_versions (" 20.1.5" , " a069565cd1c6aee48ee0f36de300635b5781f355d7b3c96a28062d50d575fa3e" )
28+ add_versions (" git:21.1.4" , " llvmorg-21.1.4" )
29+ add_versions (" git:20.1.5" , " llvmorg-20.1.5" )
2830
29- if is_plat (" windows" ) then
30- add_configs (" debug" , {description = " Enable debug symbols." , default = false , type = " boolean" , readonly = true })
31- end
31+ add_configs (" mode" , {description = " Build type" , default = " releasedbg" , type = " string" , values = {" debug" , " release" , " releasedbg" }})
3232
3333 if is_plat (" windows" , " mingw" ) then
3434 add_syslinks (" version" , " ntdll" )
@@ -75,6 +75,7 @@ package("llvm")
7575 " -DLLVM_INCLUDE_BENCHMARKS=OFF" ,
7676
7777 -- "-DCLANG_BUILD_TOOLS=OFF",
78+ -- "-DLLVM_INCLUDE_TOOLS=OFF",
7879 " -DLLVM_BUILD_TOOLS=OFF" ,
7980 " -DLLVM_BUILD_UTILS=OFF" ,
8081 " -DCLANG_ENABLE_CLANGD=OFF" ,
@@ -86,34 +87,41 @@ package("llvm")
8687 " -DLLVM_LINK_LLVM_DYLIB=OFF" ,
8788 " -DLLVM_ENABLE_RTTI=OFF" ,
8889
89- -- "-DLLVM_ENABLE_PROJECTS=clang",
90+ " -DLLVM_PARALLEL_LINK_JOBS=1" ,
91+
92+ -- Build job and link job together will oom
93+ " -DCMAKE_JOB_POOL_LINK=console" ,
94+
95+ " -DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra" ,
96+
97+ -- Only build native target
98+ " -DLLVM_TARGETS_TO_BUILD=Native"
9099 }
91- table.insert (configs , " -DCMAKE_BUILD_TYPE=" .. (package :is_debug () and " Debug" or " Release" ))
100+
101+ local build_type = {
102+ [" debug" ] = " Debug" ,
103+ [" release" ] = " Release" ,
104+ [" releasedbg" ] = " RelWithDebInfo" ,
105+ }
106+ table.insert (configs , " -DCMAKE_BUILD_TYPE=" .. (build_type [package :config (" mode" )]))
92107 table.insert (configs , " -DBUILD_SHARED_LIBS=" .. (package :config (" shared" ) and " ON" or " OFF" ))
93108 table.insert (configs , " -DLLVM_ENABLE_LTO=" .. (package :config (" lto" ) and " ON" or " OFF" ))
94- if package :config (" lto" ) then
95- if package :is_plat (" linux" , " macosx" ) then
96- table.insert (configs , " -DLLVM_USE_LINKER=lld" )
97- end
109+
110+ if package :config (" mode" ) == " debug" then
111+ table.insert (configs , " -DLLVM_USE_SANITIZER=Address" )
98112 end
113+
99114 if package :is_plat (" windows" ) then
100115 table.insert (configs , " -DCMAKE_C_COMPILER=clang-cl" )
101116 table.insert (configs , " -DCMAKE_CXX_COMPILER=clang-cl" )
102- end
103- if package :is_debug () then
104- table.insert (configs , " -DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra" )
105- table.insert (configs , " -DLLVM_ENABLE_RUNTIMES=compiler-rt" )
106- table.insert (configs , " -DLLVM_USE_SANITIZER=Address" )
107- else
108- table.insert (configs , " -DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra" )
109- end
110-
111- if package :is_plat (" macosx" ) then
112- table.insert (configs , " -DLLVM_TARGETS_TO_BUILD=AArch64" )
117+ elseif package :is_plat (" linux" ) then
118+ table.insert (configs , " -DLLVM_USE_LINKER=lld" )
119+ -- table.insert(configs, "-DLLVM_USE_SPLIT_DWARF=ON")
120+ elseif package :is_plat (" macosx" ) then
113121 table.insert (configs , " -DCMAKE_OSX_ARCHITECTURES=arm64" )
114122 table.insert (configs , " -DCMAKE_LIBTOOL=/opt/homebrew/opt/llvm@20/bin/llvm-libtool-darwin" )
115- else
116- table.insert (configs , " -DLLVM_TARGETS_TO_BUILD=X86 " )
123+ table.insert ( configs , " -DLLVM_USE_LINKER=lld " )
124+ table.insert (configs , " -DLLVM_ENABLE_LIBCXX=ON " )
117125 end
118126
119127 local opt = {}
@@ -176,7 +184,7 @@ package("llvm")
176184 package :arch (),
177185 package :plat (),
178186 abi ,
179- package :is_debug () and " debug " or " release " ,
187+ package :config ( " mode " ) ,
180188 }, " -" )
181189
182190 if package :config (" lto" ) then
0 commit comments