llvm.scm 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014, 2016, 2018 Eric Bavier <bavier@member.fsf.org>
  3. ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
  4. ;;; Copyright © 2015, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
  5. ;;; Copyright © 2016 Dennis Mungai <dmngaie@gmail.com>
  6. ;;; Copyright © 2016, 2018, 2019, 2020, 2021 Ricardo Wurmus <rekado@elephly.net>
  7. ;;; Copyright © 2017 Roel Janssen <roel@gnu.org>
  8. ;;; Copyright © 2018, 2019, 2020 Marius Bakke <mbakke@fastmail.com>
  9. ;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
  10. ;;; Copyright © 2018, 2021 Efraim Flashner <efraim@flashner.co.il>
  11. ;;; Copyright © 2018 Tim Gesthuizen <tim.gesthuizen@yahoo.de>
  12. ;;; Copyright © 2018 Pierre Neidhardt <mail@ambrevar.xyz>
  13. ;;; Copyright © 2019 Rutger Helling <rhelling@mykolab.com>
  14. ;;; Copyright © 2019 Arm Ltd <David.Truby@arm.com>
  15. ;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
  16. ;;; Copyright © 2019 Brett Gilio <brettg@gnu.org>
  17. ;;; Copyright © 2020 Giacomo Leidi <goodoldpaul@autistici.org>
  18. ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
  19. ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
  20. ;;; Copyright © 2021 Julien Lepiller <julien@lepiller.eu>
  21. ;;; Copyright © 2021 Lars-Dominik Braun <lars@6xq.net>
  22. ;;;
  23. ;;; This file is part of GNU Guix.
  24. ;;;
  25. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  26. ;;; under the terms of the GNU General Public License as published by
  27. ;;; the Free Software Foundation; either version 3 of the License, or (at
  28. ;;; your option) any later version.
  29. ;;;
  30. ;;; GNU Guix is distributed in the hope that it will be useful, but
  31. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  32. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. ;;; GNU General Public License for more details.
  34. ;;;
  35. ;;; You should have received a copy of the GNU General Public License
  36. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  37. (define-module (gnu packages llvm)
  38. #:use-module (guix packages)
  39. #:use-module ((guix licenses) #:prefix license:)
  40. #:use-module (guix download)
  41. #:use-module (guix git-download)
  42. #:use-module (guix memoization)
  43. #:use-module (guix utils)
  44. #:use-module (guix build-system gnu)
  45. #:use-module (guix build-system cmake)
  46. #:use-module (guix build-system emacs)
  47. #:use-module (guix build-system python)
  48. #:use-module (guix build-system trivial)
  49. #:use-module (gnu packages)
  50. #:use-module (gnu packages base)
  51. #:use-module (gnu packages gcc)
  52. #:use-module (gnu packages bootstrap) ;glibc-dynamic-linker
  53. #:use-module (gnu packages compression)
  54. #:use-module (gnu packages libedit)
  55. #:use-module (gnu packages libffi)
  56. #:use-module (gnu packages lua)
  57. #:use-module (gnu packages mpi)
  58. #:use-module (gnu packages ncurses)
  59. #:use-module (gnu packages ocaml)
  60. #:use-module (gnu packages onc-rpc)
  61. #:use-module (gnu packages perl)
  62. #:use-module (gnu packages pkg-config)
  63. #:use-module (gnu packages python)
  64. #:use-module (gnu packages swig)
  65. #:use-module (gnu packages xml)
  66. #:export (system->llvm-target))
  67. (define* (system->llvm-target #:optional
  68. (system (or (and=> (%current-target-system)
  69. gnu-triplet->nix-system)
  70. (%current-system))))
  71. "Return the LLVM target name that corresponds to SYSTEM, a system type such
  72. as \"x86_64-linux\"."
  73. ;; See the 'lib/Target' directory of LLVM for a list of supported targets.
  74. (letrec-syntax ((matches (syntax-rules (=>)
  75. ((_ (system-prefix => target) rest ...)
  76. (if (string-prefix? system-prefix system)
  77. target
  78. (matches rest ...)))
  79. ((_)
  80. (error "LLVM target for system is unknown" system)))))
  81. (matches ("aarch64" => "AArch64")
  82. ("armhf" => "ARM")
  83. ("mips64el" => "Mips")
  84. ("powerpc" => "PowerPC")
  85. ("riscv" => "RISCV")
  86. ("x86_64" => "X86")
  87. ("i686" => "X86")
  88. ("i586" => "X86"))))
  89. (define (llvm-uri component version)
  90. (string-append "https://github.com/llvm/llvm-project/releases/download"
  91. "/llvmorg-" version "/" component "-" version ".src.tar.xz"))
  92. (define* (clang-runtime-from-llvm llvm hash
  93. #:optional (patches '()))
  94. (package
  95. (name "clang-runtime")
  96. (version (package-version llvm))
  97. (source
  98. (origin
  99. (method url-fetch)
  100. (uri (llvm-uri "compiler-rt" version))
  101. (sha256 (base32 hash))
  102. (patches (map search-patch patches))))
  103. (build-system cmake-build-system)
  104. (native-inputs (package-native-inputs llvm))
  105. (inputs
  106. `(("llvm" ,llvm)))
  107. (arguments
  108. `(;; Don't use '-g' during the build to save space.
  109. #:build-type "Release"
  110. #:tests? #f ; Tests require gtest
  111. #:modules ((srfi srfi-1)
  112. (ice-9 match)
  113. ,@%cmake-build-system-modules)
  114. #:phases (modify-phases (@ (guix build cmake-build-system) %standard-phases)
  115. (add-after 'set-paths 'hide-glibc
  116. ;; Work around https://issues.guix.info/issue/36882. We need to
  117. ;; remove glibc from CPLUS_INCLUDE_PATH so that the one hardcoded
  118. ;; in GCC, at the bottom of GCC include search-path is used.
  119. (lambda* (#:key inputs #:allow-other-keys)
  120. (let* ((filters '("libc"))
  121. (input-directories
  122. (filter-map (lambda (input)
  123. (match input
  124. ((name . dir)
  125. (and (not (member name filters))
  126. dir))))
  127. inputs)))
  128. (set-path-environment-variable "CPLUS_INCLUDE_PATH"
  129. '("include")
  130. input-directories)
  131. #t))))))
  132. (home-page "https://compiler-rt.llvm.org")
  133. (synopsis "Runtime library for Clang/LLVM")
  134. (description
  135. "The \"clang-runtime\" library provides the implementations of run-time
  136. functions for C and C++ programs. It also provides header files that allow C
  137. and C++ source code to interface with the \"sanitization\" passes of the clang
  138. compiler. In LLVM this library is called \"compiler-rt\".")
  139. (license (package-license llvm))
  140. ;; <https://compiler-rt.llvm.org/> doesn't list MIPS as supported.
  141. (supported-systems (delete "mips64el-linux" %supported-systems))))
  142. (define* (clang-from-llvm llvm clang-runtime hash
  143. #:key (patches '()) tools-extra)
  144. "Produce Clang with dependencies on LLVM and CLANG-RUNTIME, and applying the
  145. given PATCHES. When TOOLS-EXTRA is given, it must point to the
  146. 'clang-tools-extra' tarball, which contains code for 'clang-tidy', 'pp-trace',
  147. 'modularize', and other tools."
  148. (package
  149. (name "clang")
  150. (version (package-version llvm))
  151. (source
  152. (origin
  153. (method url-fetch)
  154. (uri (llvm-uri (if (version>=? version "9.0.1")
  155. "clang"
  156. "cfe")
  157. version))
  158. (sha256 (base32 hash))
  159. (patches (map search-patch patches))))
  160. ;; Using cmake allows us to treat llvm as an external library. There
  161. ;; doesn't seem to be any way to do this with clang's autotools-based
  162. ;; build system.
  163. (build-system cmake-build-system)
  164. (outputs (if tools-extra '("out" "extra") '("out")))
  165. (native-inputs (package-native-inputs llvm))
  166. (inputs
  167. `(("libxml2" ,libxml2)
  168. ("gcc-lib" ,gcc "lib")
  169. ,@(package-inputs llvm)
  170. ,@(if tools-extra
  171. `(("clang-tools-extra" ,tools-extra))
  172. '())))
  173. (propagated-inputs
  174. `(("llvm" ,llvm)
  175. ("clang-runtime" ,clang-runtime)))
  176. (arguments
  177. `(#:configure-flags
  178. (list "-DCLANG_INCLUDE_TESTS=True"
  179. ;; Find libgcc_s, crtbegin.o, and crtend.o.
  180. (string-append "-DGCC_INSTALL_PREFIX="
  181. (assoc-ref %build-inputs "gcc-lib"))
  182. ;; Use a sane default include directory.
  183. (string-append "-DC_INCLUDE_DIRS="
  184. (assoc-ref %build-inputs "libc")
  185. "/include"))
  186. ;; Don't use '-g' during the build to save space.
  187. #:build-type "Release"
  188. #:phases (modify-phases %standard-phases
  189. ,@(if tools-extra
  190. `((add-after 'unpack 'add-tools-extra
  191. (lambda* (#:key inputs #:allow-other-keys)
  192. ;; Unpack the 'clang-tools-extra' tarball under
  193. ;; tools/.
  194. (let ((extra (assoc-ref inputs
  195. "clang-tools-extra")))
  196. (invoke "tar" "xf" extra)
  197. (rename-file ,(string-append
  198. "clang-tools-extra-"
  199. (package-version llvm)
  200. ".src")
  201. "tools/extra")
  202. #t)))
  203. (add-after 'install 'move-extra-tools
  204. (lambda* (#:key outputs #:allow-other-keys)
  205. ;; Move the extra tools to the "extra" output.
  206. ;; These programs alone weigh in at 296 MiB,
  207. ;; because they statically-link a whole bunch of
  208. ;; Clang libraries.
  209. (let* ((out (assoc-ref outputs "out"))
  210. (extra (assoc-ref outputs "extra"))
  211. (bin (string-append out "/bin"))
  212. (bin* (string-append extra "/bin"))
  213. (lib (string-append out "/lib")))
  214. (define (move program)
  215. (rename-file (string-append bin "/" program)
  216. (string-append bin* "/"
  217. program)))
  218. (mkdir-p bin*)
  219. (for-each move
  220. '("clang-apply-replacements"
  221. "clang-change-namespace"
  222. "clangd"
  223. "clang-doc"
  224. "clang-include-fixer"
  225. "clang-move"
  226. "clang-query"
  227. "clang-reorder-fields"
  228. "clang-tidy"
  229. "find-all-symbols"
  230. "modularize"
  231. "pp-trace"))
  232. ;; Remove MiBs of .a files coming from
  233. ;; 'clang-tools-extra'.
  234. (for-each (lambda (component)
  235. (delete-file
  236. (string-append lib "/libclang"
  237. component ".a")))
  238. '("ApplyReplacements"
  239. "ChangeNamespace"
  240. "Daemon"
  241. "DaemonTweaks"
  242. "Doc"
  243. "IncludeFixer"
  244. "IncludeFixerPlugin"
  245. "Move"))
  246. (for-each delete-file
  247. (find-files
  248. lib
  249. "^(libfindAllSymbols|libclangTidy)"))
  250. #t))))
  251. '())
  252. (add-after 'unpack 'add-missing-triplets
  253. (lambda _
  254. ;; Clang iterates through known triplets to search for
  255. ;; GCC's headers, but does not recognize some of the
  256. ;; triplets that are used in Guix.
  257. (substitute* ,@(if (version>=? version "6.0")
  258. '("lib/Driver/ToolChains/Gnu.cpp")
  259. '("lib/Driver/ToolChains.cpp"))
  260. (("\"aarch64-linux-gnu\"," all)
  261. (string-append "\"aarch64-unknown-linux-gnu\", "
  262. all))
  263. (("\"arm-linux-gnueabihf\"," all)
  264. (string-append all
  265. " \"arm-unknown-linux-gnueabihf\","))
  266. (("\"i686-pc-linux-gnu\"," all)
  267. (string-append "\"i686-unknown-linux-gnu\", "
  268. all)))
  269. #t))
  270. (add-after 'unpack 'set-glibc-file-names
  271. (lambda* (#:key inputs #:allow-other-keys)
  272. (let ((libc (assoc-ref inputs "libc"))
  273. (compiler-rt (assoc-ref inputs "clang-runtime"))
  274. (gcc (assoc-ref inputs "gcc")))
  275. ,@(cond
  276. ((version>=? version "6.0")
  277. `(;; Link to libclang_rt files from clang-runtime.
  278. (substitute* "lib/Driver/ToolChain.cpp"
  279. (("getDriver\\(\\)\\.ResourceDir")
  280. (string-append "\"" compiler-rt "\"")))
  281. ;; Make "LibDir" refer to <glibc>/lib so that it
  282. ;; uses the right dynamic linker file name.
  283. (substitute* "lib/Driver/ToolChains/Linux.cpp"
  284. (("(^[[:blank:]]+LibDir = ).*" _ declaration)
  285. (string-append declaration "\"" libc "/lib\";\n"))
  286. ;; Make clang look for libstdc++ in the right
  287. ;; location.
  288. (("LibStdCXXIncludePathCandidates\\[\\] = \\{")
  289. (string-append
  290. "LibStdCXXIncludePathCandidates[] = { \"" gcc
  291. "/include/c++\","))
  292. ;; Make sure libc's libdir is on the search path, to
  293. ;; allow crt1.o & co. to be found.
  294. (("@GLIBC_LIBDIR@")
  295. (string-append libc "/lib")))))
  296. (else
  297. `((substitute* "lib/Driver/Tools.cpp"
  298. ;; Patch the 'getLinuxDynamicLinker' function so that
  299. ;; it uses the right dynamic linker file name.
  300. (("/lib64/ld-linux-x86-64.so.2")
  301. (string-append libc
  302. ,(glibc-dynamic-linker))))
  303. ;; Link to libclang_rt files from clang-runtime.
  304. ;; This substitution needed slight adjustment in 3.8.
  305. ,@(if (version>=? version "3.8")
  306. '((substitute* "lib/Driver/Tools.cpp"
  307. (("TC\\.getDriver\\(\\)\\.ResourceDir")
  308. (string-append "\"" compiler-rt "\""))))
  309. '((substitute* "lib/Driver/ToolChain.cpp"
  310. (("getDriver\\(\\)\\.ResourceDir")
  311. (string-append "\"" compiler-rt "\"")))))
  312. ;; Make sure libc's libdir is on the search path, to
  313. ;; allow crt1.o & co. to be found.
  314. (substitute* "lib/Driver/ToolChains.cpp"
  315. (("@GLIBC_LIBDIR@")
  316. (string-append libc "/lib"))))))
  317. #t)))
  318. ,@(if (version>=? version "10")
  319. `((add-after 'install 'adjust-cmake-file
  320. (lambda* (#:key outputs #:allow-other-keys)
  321. (let ((out (assoc-ref outputs "out")))
  322. ;; Clang generates a CMake file with "targets"
  323. ;; for each installed library file. Downstream
  324. ;; consumers of the CMake interface can use this
  325. ;; to get absolute library locations. Including
  326. ;; this file will needlessly assert that _all_
  327. ;; libraries are available, which causes problems
  328. ;; in Guix because some are removed (see the
  329. ;; move-extra-tools phase). Thus, remove the
  330. ;; asserts so that the main functionality works.
  331. (substitute*
  332. (string-append
  333. out
  334. "/lib/cmake/clang/ClangTargets-release.cmake")
  335. (("list\\(APPEND _IMPORT_CHECK_TARGETS.*" all)
  336. (string-append "# Disabled by Guix.\n#" all)))
  337. #t))))
  338. '())
  339. ,@(if (version>? version "3.8")
  340. `((add-after 'install 'symlink-cfi_blacklist
  341. (lambda* (#:key inputs outputs #:allow-other-keys)
  342. (let* ((out (assoc-ref outputs "out"))
  343. (lib-share (string-append out "/lib/clang/"
  344. ,version "/share"))
  345. (compiler-rt (assoc-ref inputs "clang-runtime"))
  346. ;; The location varies between Clang versions.
  347. (cfi-blacklist
  348. (cond
  349. ((file-exists?
  350. (string-append compiler-rt "/cfi_blacklist.txt"))
  351. (string-append compiler-rt "/cfi_blacklist.txt"))
  352. (else (string-append compiler-rt
  353. "/share/cfi_blacklist.txt")))))
  354. (mkdir-p lib-share)
  355. ;; Symlink cfi_blacklist.txt to where Clang expects
  356. ;; to find it.
  357. (symlink cfi-blacklist
  358. (string-append lib-share "/cfi_blacklist.txt"))
  359. #t))))
  360. '())
  361. (add-after 'install 'install-clean-up-/share/clang
  362. (lambda* (#:key outputs #:allow-other-keys)
  363. (let* ((out (assoc-ref outputs "out"))
  364. (compl-dir (string-append
  365. out "/etc/bash_completion.d")))
  366. (with-directory-excursion (string-append out
  367. "/share/clang")
  368. (for-each
  369. (lambda (file)
  370. (when (file-exists? file)
  371. (delete-file file)))
  372. ;; Delete extensions for proprietary text editors.
  373. '("clang-format-bbedit.applescript"
  374. "clang-format-sublime.py"
  375. ;; Delete Emacs extensions: see their respective Emacs
  376. ;; Guix package instead.
  377. "clang-rename.el" "clang-format.el"))
  378. ;; Install bash completion.
  379. (when (file-exists? "bash-autocomplete.sh")
  380. (mkdir-p compl-dir)
  381. (rename-file "bash-autocomplete.sh"
  382. (string-append compl-dir "/clang")))))
  383. #t)))))
  384. ;; Clang supports the same environment variables as GCC.
  385. (native-search-paths
  386. (list (search-path-specification
  387. (variable "C_INCLUDE_PATH")
  388. (files '("include")))
  389. (search-path-specification
  390. (variable "CPLUS_INCLUDE_PATH")
  391. (files '("include/c++" "include")))
  392. (search-path-specification
  393. (variable "LIBRARY_PATH")
  394. (files '("lib" "lib64")))))
  395. (home-page "https://clang.llvm.org")
  396. (synopsis "C language family frontend for LLVM")
  397. (description
  398. "Clang is a compiler front end for the C, C++, Objective-C and
  399. Objective-C++ programming languages. It uses LLVM as its back end. The Clang
  400. project includes the Clang front end, the Clang static analyzer, and several
  401. code analysis tools.")
  402. (license (if (version>=? version "9.0")
  403. license:asl2.0 ;with LLVM exceptions
  404. license:ncsa))))
  405. (define (make-clang-toolchain clang)
  406. (package
  407. (name (string-append (package-name clang) "-toolchain"))
  408. (version (package-version clang))
  409. (source #f)
  410. (build-system trivial-build-system)
  411. (arguments
  412. '(#:modules ((guix build union))
  413. #:builder (begin
  414. (use-modules (ice-9 match)
  415. (srfi srfi-26)
  416. (guix build union))
  417. (let ((out (assoc-ref %outputs "out")))
  418. (match %build-inputs
  419. (((names . directories) ...)
  420. (union-build out directories)))
  421. ;; Create 'cc' and 'c++' so that one can use it as a
  422. ;; drop-in replacement for the default tool chain and
  423. ;; have configure scripts find the compiler.
  424. (symlink "clang" (string-append out "/bin/cc"))
  425. (symlink "clang++" (string-append out "/bin/c++"))
  426. (union-build (assoc-ref %outputs "debug")
  427. (list (assoc-ref %build-inputs
  428. "libc-debug")))
  429. (union-build (assoc-ref %outputs "static")
  430. (list (assoc-ref %build-inputs
  431. "libc-static")))
  432. #t))))
  433. (native-search-paths
  434. (append (package-native-search-paths clang)
  435. (list (search-path-specification ;copied from glibc
  436. (variable "GUIX_LOCPATH")
  437. (files '("lib/locale"))))))
  438. (search-paths (package-search-paths clang))
  439. (license (package-license clang))
  440. (home-page "https://clang.llvm.org")
  441. (synopsis "Complete Clang toolchain for C/C++ development")
  442. (description "This package provides a complete Clang toolchain for C/C++
  443. development to be installed in user profiles. This includes Clang, as well as
  444. libc (headers and binaries, plus debugging symbols in the @code{debug}
  445. output), and Binutils.")
  446. (outputs '("out" "debug" "static"))
  447. (inputs `(("clang" ,clang)
  448. ("ld-wrapper" ,(car (assoc-ref (%final-inputs) "ld-wrapper")))
  449. ("binutils" ,binutils)
  450. ("libc" ,glibc)
  451. ("libc-debug" ,glibc "debug")
  452. ("libc-static" ,glibc "static")))))
  453. (define-public llvm-12
  454. (package
  455. (name "llvm")
  456. (version "12.0.0")
  457. (source
  458. (origin
  459. (method url-fetch)
  460. (uri (llvm-uri "llvm" version))
  461. (sha256
  462. (base32
  463. "0l4b79gwfvxild974aigcq1yigypjsk2j5p59syhl6ksd744gp29"))))
  464. (build-system cmake-build-system)
  465. (outputs '("out" "opt-viewer"))
  466. (native-inputs
  467. `(("python" ,python-wrapper)
  468. ("perl" ,perl)))
  469. (inputs
  470. `(("libffi" ,libffi)))
  471. (propagated-inputs
  472. `(("zlib" ,zlib))) ;to use output from llvm-config
  473. (arguments
  474. `(#:configure-flags '("-DCMAKE_SKIP_BUILD_RPATH=FALSE"
  475. "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
  476. "-DBUILD_SHARED_LIBS:BOOL=TRUE"
  477. "-DLLVM_ENABLE_FFI:BOOL=TRUE"
  478. "-DLLVM_REQUIRES_RTTI=1" ; For some third-party utilities
  479. "-DLLVM_INSTALL_UTILS=ON") ; Needed for rustc.
  480. ;; Don't use '-g' during the build, to save space.
  481. #:build-type "Release"
  482. #:phases
  483. (modify-phases %standard-phases
  484. (add-before 'build 'shared-lib-workaround
  485. ;; Even with CMAKE_SKIP_BUILD_RPATH=FALSE, llvm-tblgen
  486. ;; doesn't seem to get the correct rpath to be able to run
  487. ;; from the build directory. Set LD_LIBRARY_PATH as a
  488. ;; workaround.
  489. (lambda _
  490. (setenv "LD_LIBRARY_PATH"
  491. (string-append (getcwd) "/lib"))
  492. #t))
  493. (add-after 'install 'install-opt-viewer
  494. (lambda* (#:key outputs #:allow-other-keys)
  495. (let* ((out (assoc-ref outputs "out"))
  496. (opt-viewer-out (assoc-ref outputs "opt-viewer"))
  497. (opt-viewer-share-dir (string-append opt-viewer-out "/share"))
  498. (opt-viewer-dir (string-append opt-viewer-share-dir "/opt-viewer")))
  499. (mkdir-p opt-viewer-share-dir)
  500. (rename-file (string-append out "/share/opt-viewer")
  501. opt-viewer-dir))
  502. #t)))))
  503. (home-page "https://www.llvm.org")
  504. (synopsis "Optimizing compiler infrastructure")
  505. (description
  506. "LLVM is a compiler infrastructure designed for compile-time, link-time,
  507. runtime, and idle-time optimization of programs from arbitrary programming
  508. languages. It currently supports compilation of C and C++ programs, using
  509. front-ends derived from GCC 4.0.1. A new front-end for the C family of
  510. languages is in development. The compiler infrastructure includes mirror sets
  511. of programming tools as well as libraries with equivalent functionality.")
  512. (license license:asl2.0))) ;with LLVM exceptions, see LICENSE.txt
  513. (define-public clang-runtime-12
  514. (clang-runtime-from-llvm
  515. llvm-12
  516. "0d444qihq9jhqnfv003cr704v363va72zl6qaw2algj1c85cva45"))
  517. (define-public clang-12
  518. (clang-from-llvm llvm-12 clang-runtime-12
  519. "1vd9rhhrd8ghdg111lac7w8by71y9l14yh5zxfijsm6lj4p4avp2"
  520. #:patches '("clang-11.0-libc-search-path.patch")
  521. #:tools-extra
  522. (origin
  523. (method url-fetch)
  524. (uri (llvm-uri "clang-tools-extra"
  525. (package-version llvm-12)))
  526. (patches
  527. (search-patches "clang-12-tools-extra-directory.patch"))
  528. (sha256
  529. (base32
  530. "0p3dzr0qa7mar83y66xa5m5apynf6ia0lsdsq6axwnm64ysy0hdd")))))
  531. (define-public clang-toolchain-12
  532. (make-clang-toolchain clang-12))
  533. (define-public llvm-11
  534. (package
  535. (inherit llvm-12)
  536. (version "11.0.0")
  537. (source
  538. (origin
  539. (method url-fetch)
  540. (uri (llvm-uri "llvm" version))
  541. (sha256
  542. (base32
  543. "0s94lwil98w7zb7cjrbnxli0z7gklb312pkw74xs1d6zk346hgwi"))))))
  544. (define-public clang-runtime-11
  545. (clang-runtime-from-llvm
  546. llvm-11
  547. "0d5j5l8phwqjjscmk8rmqn0i2i0abl537gdbkagl8fjpzy1gyjip"))
  548. (define-public clang-11
  549. (clang-from-llvm llvm-11 clang-runtime-11
  550. "02ajkij85966vd150iy246mv16dsaph1kfi0y8wnncp8w6nar5hg"
  551. #:patches '("clang-11.0-libc-search-path.patch")
  552. #:tools-extra
  553. (origin
  554. (method url-fetch)
  555. (uri (llvm-uri "clang-tools-extra"
  556. (package-version llvm-11)))
  557. (sha256
  558. (base32
  559. "02bcwwn54661madhq4nxc069s7p7pj5gpqi8ww50w3anbpviilzy")))))
  560. (define-public clang-toolchain-11
  561. (make-clang-toolchain clang-11))
  562. (define-public llvm-10
  563. (package
  564. (inherit llvm-11)
  565. (version "10.0.1")
  566. (source
  567. (origin
  568. (method url-fetch)
  569. (uri (llvm-uri "llvm" version))
  570. (sha256
  571. (base32
  572. "1wydhbp9kyjp5y0rc627imxgkgqiv3dfirbqil9dgpnbaw5y7n65"))))))
  573. (define-public clang-runtime-10
  574. (clang-runtime-from-llvm
  575. llvm-10
  576. "1yjqjri753w0fzmxcyz687nvd97sbc9rsqrxzpq720na47hwh3fr"))
  577. (define-public clang-10
  578. (clang-from-llvm llvm-10 clang-runtime-10
  579. "091bvcny2lh32zy8f3m9viayyhb2zannrndni7325rl85cwgr6pr"
  580. #:patches '("clang-10.0-libc-search-path.patch")
  581. #:tools-extra
  582. (origin
  583. (method url-fetch)
  584. (uri (llvm-uri "clang-tools-extra"
  585. (package-version llvm-10)))
  586. (sha256
  587. (base32
  588. "06n1yp638rh24xdxv9v2df0qajxbjz4w59b7dd4ky36drwmpi4yh")))))
  589. (define-public clang-toolchain-10
  590. (make-clang-toolchain clang-10))
  591. (define-public llvm-9
  592. (package
  593. (inherit llvm-10)
  594. (version "9.0.1")
  595. (source
  596. (origin
  597. (method url-fetch)
  598. (uri (llvm-uri "llvm" version))
  599. (sha256
  600. (base32
  601. "16hwp3qa54c3a3v7h8nlw0fh5criqh0hlr1skybyk0cz70gyx880"))
  602. (patches (search-patches
  603. "llvm-9-fix-bitcast-miscompilation.patch"
  604. "llvm-9-fix-scev-miscompilation.patch"
  605. "llvm-9-fix-lpad-miscompilation.patch"))))))
  606. (define-public clang-runtime-9
  607. (clang-runtime-from-llvm
  608. llvm-9
  609. "0xwh79g3zggdabxgnd0bphry75asm1qz7mv3hcqihqwqr6aspgy2"
  610. '("clang-runtime-9-libsanitizer-mode-field.patch")))
  611. (define-public clang-9
  612. (clang-from-llvm llvm-9 clang-runtime-9
  613. "0ls2h3iv4finqyflyhry21qhc9cm9ga7g1zq21020p065qmm2y2p"
  614. #:patches '("clang-9.0-libc-search-path.patch")))
  615. (define-public clang-toolchain-9
  616. (make-clang-toolchain clang-9))
  617. (define-public llvm-8
  618. (package
  619. (inherit llvm-9)
  620. (version "8.0.0")
  621. (source (origin
  622. (method url-fetch)
  623. (uri (llvm-uri "llvm" version))
  624. (sha256
  625. (base32
  626. "0k124sxkfhfi1rca6kzkdraf4axhx99x3cw2rk55056628dvwwl8"))))
  627. (license license:ncsa)))
  628. (define-public clang-runtime-8
  629. (clang-runtime-from-llvm
  630. llvm-8
  631. "1c919wsm17xnv7lr8bhpq2wkq8113lzlw6hzhfr737j59x3wfddl"
  632. '("clang-runtime-9-libsanitizer-mode-field.patch")))
  633. (define-public clang-8
  634. (clang-from-llvm llvm-8 clang-runtime-8
  635. "0svk1f70hvpwrjp6x5i9kqwrqwxnmcrw5s7f4cxyd100mdd12k08"
  636. #:patches '("clang-7.0-libc-search-path.patch")))
  637. (define-public clang-toolchain-8
  638. (make-clang-toolchain clang-8))
  639. (define-public llvm-7
  640. (package
  641. (inherit llvm-8)
  642. (version "7.1.0")
  643. (source (origin
  644. (method url-fetch)
  645. (uri (llvm-uri "llvm" version))
  646. (sha256
  647. (base32
  648. "0r1p5didv4rkgxyvbkyz671xddg6i3dxvbpsi1xxipkla0l9pk0v"))))))
  649. (define-public clang-runtime-7
  650. (clang-runtime-from-llvm
  651. llvm-7
  652. "1n48p8gjarihkws0i2bay5w9bdwyxyxxbpwyng7ba58jb30dlyq5"
  653. '("clang-runtime-9-libsanitizer-mode-field.patch")))
  654. (define-public clang-7
  655. (clang-from-llvm llvm-7 clang-runtime-7
  656. "0vc4i87qwxnw9lci4ayws9spakg0z6w5w670snj9f8g5m9rc8zg9"
  657. #:patches '("clang-7.0-libc-search-path.patch")))
  658. (define-public clang-toolchain-7
  659. (make-clang-toolchain clang-7))
  660. (define-public llvm-6
  661. (package
  662. (inherit llvm-7)
  663. (version "6.0.1")
  664. (source (origin
  665. (method url-fetch)
  666. (uri (llvm-uri "llvm" version))
  667. (sha256
  668. (base32
  669. "1qpls3vk85lydi5b4axl0809fv932qgsqgdgrk098567z4jc7mmn"))))))
  670. (define-public clang-runtime-6
  671. (clang-runtime-from-llvm
  672. llvm-6
  673. "1fcr3jn24yr8lh36nc0c4ikli4744i2q9m1ik67p1jymwwaixkgl"
  674. '("clang-runtime-9-libsanitizer-mode-field.patch")))
  675. (define-public clang-6
  676. (clang-from-llvm llvm-6 clang-runtime-6
  677. "0rxn4rh7rrnsqbdgp4gzc8ishbkryhpl1kd3mpnxzpxxhla3y93w"
  678. #:patches '("clang-6.0-libc-search-path.patch")))
  679. (define-public clang-toolchain-6
  680. (make-clang-toolchain clang-6))
  681. (define-public llvm-3.9.1
  682. (package (inherit llvm-6)
  683. (name "llvm")
  684. (version "3.9.1")
  685. (source
  686. (origin
  687. (method url-fetch)
  688. (uri (llvm-uri "llvm" version))
  689. (sha256
  690. (base32
  691. "1vi9sf7rx1q04wj479rsvxayb6z740iaz3qniwp266fgp5a07n8z"))))
  692. (outputs '("out"))
  693. (arguments
  694. (substitute-keyword-arguments (package-arguments llvm)
  695. ((#:phases phases)
  696. `(modify-phases ,phases
  697. (delete 'install-opt-viewer)))))))
  698. (define-public clang-runtime-3.9.1
  699. (clang-runtime-from-llvm
  700. llvm-3.9.1
  701. "16gc2gdmp5c800qvydrdhsp0bzb97s8wrakl6i8a4lgslnqnf2fk"
  702. '("clang-runtime-3.9-libsanitizer-mode-field.patch"
  703. "clang-runtime-asan-build-fixes.patch"
  704. "clang-runtime-esan-build-fixes.patch"
  705. "clang-3.5-libsanitizer-ustat-fix.patch")))
  706. (define-public clang-3.9.1
  707. (clang-from-llvm llvm-3.9.1 clang-runtime-3.9.1
  708. "0qsyyb40iwifhhlx9a3drf8z6ni6zwyk3bvh0kx2gs6yjsxwxi76"
  709. #:patches '("clang-3.8-libc-search-path.patch")))
  710. (define-public llvm-3.8
  711. (package (inherit llvm-3.9.1)
  712. (name "llvm")
  713. (version "3.8.1")
  714. (source
  715. (origin
  716. (method url-fetch)
  717. (uri (llvm-uri "llvm" version))
  718. (sha256
  719. (base32
  720. "1ybmnid4pw2hxn12ax5qa5kl1ldfns0njg8533y3mzslvd5cx0kf"))))))
  721. (define-public clang-runtime-3.8
  722. (clang-runtime-from-llvm
  723. llvm-3.8
  724. "0p0y85c7izndbpg2l816z7z7558axq11d5pwkm4h11sdw7d13w0d"
  725. '("clang-runtime-asan-build-fixes.patch"
  726. "clang-runtime-3.8-libsanitizer-mode-field.patch"
  727. "clang-3.5-libsanitizer-ustat-fix.patch")))
  728. (define-public clang-3.8
  729. (clang-from-llvm llvm-3.8 clang-runtime-3.8
  730. "1prc72xmkgx8wrzmrr337776676nhsp1qd3mw2bvb22bzdnq7lsc"
  731. #:patches '("clang-3.8-libc-search-path.patch")))
  732. (define-public llvm-3.7
  733. (package (inherit llvm-3.8)
  734. (version "3.7.1")
  735. (source
  736. (origin
  737. (method url-fetch)
  738. (uri (llvm-uri "llvm" version))
  739. (sha256
  740. (base32
  741. "1masakdp9g2dan1yrazg7md5am2vacbkb3nahb3dchpc1knr8xxy"))))))
  742. (define-public clang-runtime-3.7
  743. (clang-runtime-from-llvm
  744. llvm-3.7
  745. "10c1mz2q4bdq9bqfgr3dirc6hz1h3sq8573srd5q5lr7m7j6jiwx"
  746. '("clang-runtime-asan-build-fixes.patch"
  747. "clang-runtime-3.8-libsanitizer-mode-field.patch"
  748. "clang-3.5-libsanitizer-ustat-fix.patch")))
  749. (define-public clang-3.7
  750. (clang-from-llvm llvm-3.7 clang-runtime-3.7
  751. "0x065d0w9b51xvdjxwfzjxng0gzpbx45fgiaxpap45ragi61dqjn"
  752. #:patches '("clang-3.5-libc-search-path.patch")))
  753. (define-public llvm-3.6
  754. (package (inherit llvm-3.7)
  755. (version "3.6.2")
  756. (source
  757. (origin
  758. (method url-fetch)
  759. (uri (llvm-uri "llvm" version))
  760. (sha256
  761. (base32
  762. "153vcvj8gvgwakzr4j0kndc0b7wn91c2g1vy2vg24s6spxcc23gn"))))))
  763. (define-public llvm-3.5
  764. (package (inherit llvm-3.6)
  765. (version "3.5.2")
  766. (source
  767. (origin
  768. (method url-fetch)
  769. (uri (llvm-uri "llvm" version))
  770. (patches
  771. (search-patches "llvm-3.5-fix-clang-build-with-gcc5.patch"))
  772. (sha256
  773. (base32
  774. "0xf5q17kkxsrm2gsi93h4pwlv663kji73r2g4asb97klsmb626a4"))))))
  775. (define-public clang-runtime-3.5
  776. (let ((runtime (clang-runtime-from-llvm
  777. llvm-3.5
  778. "1hsdnzzdr5kglz6fnv3lcsjs222zjsy14y8ax9dy6zqysanplbal"
  779. '("clang-runtime-asan-build-fixes.patch"
  780. "clang-runtime-3.5-libsanitizer-mode-field.patch"
  781. "clang-3.5-libsanitizer-ustat-fix.patch"))))
  782. (package/inherit runtime
  783. (arguments
  784. (substitute-keyword-arguments (package-arguments runtime)
  785. ((#:phases phases '%standard-phases)
  786. `(modify-phases ,phases
  787. ;; glibc no longer includes rpc/xdr.h, so we use the headers from
  788. ;; libtirpc.
  789. (add-after 'unpack 'find-rpc-includes
  790. (lambda* (#:key inputs #:allow-other-keys)
  791. (setenv "CPATH"
  792. (string-append
  793. (search-input-directory inputs "/include/tirpc")
  794. ":" (or (getenv "CPATH") "")))
  795. (setenv "CPLUS_INCLUDE_PATH"
  796. (string-append
  797. (search-input-directory inputs "/include/tirpc")
  798. ":" (or (getenv "CPLUS_INCLUDE_PATH") "")))))))))
  799. (inputs
  800. `(("libtirpc" ,libtirpc)
  801. ("llvm" ,llvm-3.5))))))
  802. (define-public clang-3.5
  803. (clang-from-llvm llvm-3.5 clang-runtime-3.5
  804. "0846h8vn3zlc00jkmvrmy88gc6ql6014c02l4jv78fpvfigmgssg"
  805. #:patches '("clang-3.5-libc-search-path.patch")))
  806. ;; Default LLVM and Clang version.
  807. (define-public llvm llvm-9)
  808. (define-public clang-runtime clang-runtime-9)
  809. (define-public clang clang-9)
  810. (define-public clang-toolchain clang-toolchain-9)
  811. (define-public llvm-for-rocm
  812. (package
  813. ;; Actually based on LLVM 13 as of v4.3, but llvm-12 works just fine.
  814. (inherit llvm-12)
  815. (name "llvm-for-rocm")
  816. (version "4.3.0") ;this must match '%rocm-version'
  817. (source (origin
  818. (method git-fetch)
  819. (uri (git-reference
  820. (url "https://github.com/RadeonOpenCompute/llvm-project.git")
  821. (commit (string-append "rocm-" version))))
  822. (file-name (git-file-name name version))
  823. (sha256
  824. (base32
  825. "0p75nr1qpmy6crymdax5hm40wkimman4lnglz4x5cnbiqindya7s"))
  826. (patches
  827. (search-patches "llvm-roc-4.2.0-add_Object.patch"
  828. "llvm-roc-3.0.0-add_libraries.patch"
  829. "llvm-roc-4.0.0-remove-isystem-usr-include.patch"))))
  830. (arguments
  831. (substitute-keyword-arguments (package-arguments llvm-12)
  832. ((#:phases phases '%standard-phases)
  833. `(modify-phases ,phases
  834. (add-after 'unpack 'chdir
  835. (lambda _
  836. (chdir "llvm")))))
  837. ((#:configure-flags flags)
  838. ''("-DLLVM_ENABLE_PROJECTS=llvm;clang;lld"
  839. "-DLLVM_TARGETS_TO_BUILD=AMDGPU;X86"
  840. "-DCMAKE_SKIP_BUILD_RPATH=FALSE"
  841. "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
  842. "-DBUILD_SHARED_LIBS:BOOL=TRUE"
  843. "-DLLVM_VERSION_SUFFIX="))))
  844. (properties `((hidden? . #t)
  845. ,@(package-properties llvm-12)))))
  846. (define-public lld
  847. (package
  848. (name "lld")
  849. (version "11.0.0")
  850. (source (origin
  851. (method url-fetch)
  852. (uri (llvm-uri "lld" version))
  853. (sha256
  854. (base32
  855. "077xyh7sij6mhp4dc4kdcmp9whrpz332fa12rwxnzp3wgd5bxrzg"))))
  856. (build-system cmake-build-system)
  857. (inputs
  858. `(("llvm" ,llvm-11)))
  859. (arguments
  860. `(#:build-type "Release"
  861. ;; TODO: Tests require the lit tool, which isn't installed by the LLVM
  862. ;; package.
  863. #:tests? #f))
  864. (home-page "https://lld.llvm.org/")
  865. (synopsis "Linker from the LLVM project")
  866. (description "LLD is a high-performance linker, built as a set of reusable
  867. components which highly leverage existing libraries in the larger LLVM Project.")
  868. (license license:asl2.0))) ; With LLVM exception
  869. (define-public lldb
  870. (package
  871. (name "lldb")
  872. (version "11.0.0")
  873. (source (origin
  874. (method url-fetch)
  875. (uri (llvm-uri "lldb" version))
  876. (sha256
  877. (base32
  878. "0wic9lyb2la9bkzdc13szkm4f793w1mddp50xvh237iraygw0w45"))))
  879. (build-system cmake-build-system)
  880. (arguments
  881. `(#:configure-flags '("-DCMAKE_CXX_COMPILER=clang++")))
  882. (native-inputs
  883. `(("pkg-config" ,pkg-config)
  884. ("swig" ,swig)))
  885. (inputs
  886. `(("clang" ,clang-11)
  887. ("llvm" ,llvm-11)
  888. ;; Optional (but recommended) inputs.
  889. ("curses" ,ncurses)
  890. ("editline" ,libedit)
  891. ("liblzma" ,xz)
  892. ("libxml2" ,libxml2)
  893. ("lua" ,lua)
  894. ("python" ,python)))
  895. (home-page "https://lldb.llvm.org/")
  896. (synopsis "Low level debugger")
  897. (description
  898. "LLDB is a high performance debugger built as a set of reusable components
  899. which highly leverage existing libraries in the larger LLVM project.")
  900. (license license:asl2.0))) ;with LLVM exceptions
  901. (define-public libcxx
  902. (package
  903. (name "libcxx")
  904. (version "9.0.1")
  905. (source
  906. (origin
  907. (method url-fetch)
  908. (uri (llvm-uri "libcxx" version))
  909. (sha256
  910. (base32
  911. "0d2bj5i6mk4caq7skd5nsdmz8c2m5w5anximl5wz3x32p08zz089"))))
  912. (build-system cmake-build-system)
  913. (arguments
  914. `(#:phases
  915. (modify-phases (@ (guix build cmake-build-system) %standard-phases)
  916. (add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
  917. (lambda* (#:key inputs #:allow-other-keys)
  918. (let ((gcc (assoc-ref inputs "gcc")))
  919. ;; Hide GCC's C++ headers so that they do not interfere with
  920. ;; the ones we are attempting to build.
  921. (setenv "CPLUS_INCLUDE_PATH"
  922. (string-join (delete (string-append gcc "/include/c++")
  923. (string-split (getenv "CPLUS_INCLUDE_PATH")
  924. #\:))
  925. ":"))
  926. (format #t
  927. "environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
  928. (getenv "CPLUS_INCLUDE_PATH"))
  929. #t))))))
  930. (native-inputs
  931. `(("clang" ,clang)
  932. ("llvm" ,llvm)))
  933. (home-page "https://libcxx.llvm.org")
  934. (synopsis "C++ standard library")
  935. (description
  936. "This package provides an implementation of the C++ standard library for
  937. use with Clang, targeting C++11, C++14 and above.")
  938. (license license:expat)))
  939. ;; Libcxx files specifically used by PySide2.
  940. (define-public libcxx-6
  941. (package
  942. (inherit libcxx)
  943. (version (package-version llvm-6))
  944. (source
  945. (origin
  946. (inherit (package-source libcxx))
  947. (uri (llvm-uri "libcxx" version))
  948. (sha256
  949. (base32
  950. "0rzw4qvxp6qx4l4h9amrq02gp7hbg8lw4m0sy3k60f50234gnm3n"))))
  951. (native-inputs
  952. `(("clang" ,clang-6)
  953. ("llvm" ,llvm-6)))))
  954. (define-public libcxxabi-6
  955. (package
  956. (name "libcxxabi")
  957. (version "6.0.1")
  958. (source
  959. (origin
  960. (method git-fetch)
  961. (uri (git-reference
  962. (url "https://github.com/llvm/llvm-project")
  963. (commit (string-append "llvmorg-" version))))
  964. (file-name (git-file-name name version))
  965. (sha256
  966. (base32
  967. "0ki6796b5z08kh3a3rbysr5wwb2dkl6wal5dzd03i4li5xfkvx1g"))))
  968. (build-system cmake-build-system)
  969. (arguments
  970. `(#:configure-flags
  971. (list (string-append "-DLIBCXXABI_LIBCXX_INCLUDES="
  972. (assoc-ref %build-inputs "libcxx")
  973. "/include")
  974. "-DCMAKE_C_COMPILER=clang"
  975. "-DCMAKE_CXX_COMPILER=clang++")
  976. #:phases
  977. (modify-phases (@ (guix build cmake-build-system) %standard-phases)
  978. (add-after 'unpack 'chdir
  979. (lambda _ (chdir "libcxxabi")))
  980. (add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
  981. (lambda* (#:key inputs #:allow-other-keys)
  982. (let ((gcc (assoc-ref inputs "gcc")))
  983. ;; Hide GCC's C++ headers so that they do not interfere with
  984. ;; the ones we are attempting to build.
  985. (setenv "CPLUS_INCLUDE_PATH"
  986. (string-join
  987. (cons (string-append
  988. (assoc-ref inputs "libcxx") "/include/c++/v1")
  989. (delete (string-append gcc "/include/c++")
  990. (string-split (getenv "CPLUS_INCLUDE_PATH")
  991. #\:)))
  992. ":"))
  993. (format #true
  994. "environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
  995. (getenv "CPLUS_INCLUDE_PATH")))))
  996. (add-after 'install 'install-headers
  997. (lambda* (#:key outputs #:allow-other-keys)
  998. (let ((include-dir (string-append
  999. (assoc-ref outputs "out") "/include")))
  1000. (install-file "../libcxxabi/include/__cxxabi_config.h" include-dir)
  1001. (install-file "../libcxxabi/include/cxxabi.h" include-dir)))))))
  1002. (native-inputs
  1003. `(("clang" ,clang-6)
  1004. ("llvm" ,llvm-6)
  1005. ("libcxx" ,libcxx-6)))
  1006. (home-page "https://libcxxabi.llvm.org")
  1007. (synopsis "C++ standard library support")
  1008. (description
  1009. "This package provides an implementation of low level support for a
  1010. standard C++ library.")
  1011. (license license:expat)))
  1012. (define-public libcxx+libcxxabi-6
  1013. (package
  1014. (inherit libcxx-6)
  1015. (name "libcxx+libcxxabi")
  1016. (version (package-version libcxx-6))
  1017. (arguments
  1018. `(#:configure-flags
  1019. (list "-DLIBCXX_CXX_ABI=libcxxabi"
  1020. (string-append "-DLIBCXX_CXX_ABI_INCLUDE_PATHS="
  1021. (assoc-ref %build-inputs "libcxxabi")
  1022. "/include"))
  1023. #:phases
  1024. (modify-phases (@ (guix build cmake-build-system) %standard-phases)
  1025. (add-after 'set-paths 'adjust-CPLUS_INCLUDE_PATH
  1026. (lambda* (#:key inputs #:allow-other-keys)
  1027. (let ((gcc (assoc-ref inputs "gcc")))
  1028. ;; Hide GCC's C++ headers so that they do not interfere with
  1029. ;; the ones we are attempting to build.
  1030. (setenv "CPLUS_INCLUDE_PATH"
  1031. (string-join
  1032. (delete (string-append gcc "/include/c++")
  1033. (string-split (getenv "CPLUS_INCLUDE_PATH")
  1034. #\:))
  1035. ":"))
  1036. (format #true
  1037. "environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
  1038. (getenv "CPLUS_INCLUDE_PATH"))))))))
  1039. (native-inputs
  1040. `(("clang" ,clang-6)
  1041. ("llvm" ,llvm-6)
  1042. ("libcxxabi" ,libcxxabi-6)))))
  1043. (define-public libclc
  1044. (package
  1045. (name "libclc")
  1046. (version "9.0.1")
  1047. (source
  1048. (origin
  1049. (method git-fetch)
  1050. (uri (git-reference
  1051. (url "https://github.com/llvm/llvm-project")
  1052. (commit (string-append "llvmorg-" version))))
  1053. (file-name (git-file-name name version))
  1054. (sha256
  1055. (base32
  1056. "1d1qayvrvvc1di7s7jfxnjvxq2az4lwq1sw1b2gq2ic0nksvajz0"))))
  1057. (build-system cmake-build-system)
  1058. (arguments
  1059. `(#:configure-flags
  1060. (list (string-append "-DLLVM_CLANG="
  1061. (assoc-ref %build-inputs "clang")
  1062. "/bin/clang")
  1063. (string-append "-DPYTHON="
  1064. (assoc-ref %build-inputs "python")
  1065. "/bin/python3"))
  1066. #:phases
  1067. (modify-phases %standard-phases
  1068. (add-after 'unpack 'chdir
  1069. (lambda _ (chdir "libclc") #t)))))
  1070. (native-inputs
  1071. `(("clang" ,clang)
  1072. ("llvm" ,llvm)
  1073. ("python" ,python)))
  1074. (home-page "https://libclc.llvm.org")
  1075. (synopsis "Libraries for the OpenCL programming language")
  1076. (description
  1077. "This package provides an implementation of the OpenCL library
  1078. requirements according to version 1.1 of the OpenCL specification.")
  1079. ;; Apache license 2.0 with LLVM exception
  1080. (license license:asl2.0)))
  1081. (define-public libomp
  1082. (package
  1083. (name "libomp")
  1084. (version "9.0.1")
  1085. (source (origin
  1086. (method url-fetch)
  1087. (uri (llvm-uri "openmp" version))
  1088. (sha256
  1089. (base32
  1090. "1knafnpp0f7hylx8q20lkd6g1sf0flly572dayc5d5kghh7hd52w"))
  1091. (file-name (string-append "libomp-" version ".tar.xz"))))
  1092. (build-system cmake-build-system)
  1093. ;; XXX: Note this gets built with GCC because building with Clang itself
  1094. ;; fails (missing <atomic>, even when libcxx is added as an input.)
  1095. (arguments
  1096. '(#:configure-flags '("-DLIBOMP_USE_HWLOC=ON"
  1097. "-DOPENMP_TEST_C_COMPILER=clang"
  1098. "-DOPENMP_TEST_CXX_COMPILER=clang++")
  1099. #:test-target "check-libomp"))
  1100. (native-inputs
  1101. `(("clang" ,clang)
  1102. ("llvm" ,llvm)
  1103. ("perl" ,perl)
  1104. ("pkg-config" ,pkg-config)))
  1105. (inputs
  1106. `(("hwloc" ,hwloc "lib")))
  1107. (home-page "https://openmp.llvm.org")
  1108. (synopsis "OpenMP run-time support library")
  1109. (description
  1110. "This package provides the run-time support library developed by the LLVM
  1111. project for the OpenMP multi-theaded programming extension. This package
  1112. notably provides @file{libgomp.so}, which is has a binary interface compatible
  1113. with that of libgomp, the GNU Offloading and Multi Processing Library.")
  1114. (license license:expat)))
  1115. (define-public python-llvmlite
  1116. (package
  1117. (name "python-llvmlite")
  1118. (version "0.34.0")
  1119. (source
  1120. (origin
  1121. (method url-fetch)
  1122. (uri (pypi-uri "llvmlite" version))
  1123. (sha256
  1124. (base32
  1125. "0qqzs6h34002ig2jn31vk08q9hh5kn84lhmv4bljz3yakg8y0gph"))))
  1126. (build-system python-build-system)
  1127. (arguments
  1128. `(#:phases
  1129. (modify-phases %standard-phases
  1130. (add-after 'unpack 'patch-reference-to-llvmlite.so
  1131. ;; ctypes.CDLL uses dlopen to load libllvmlite.so, which
  1132. ;; fails, so locate it by its absolute path. Change it in
  1133. ;; ffi.py, not utils.py, because setup.py relies on the
  1134. ;; output of get_library_name for proper installation.
  1135. (lambda* (#:key outputs #:allow-other-keys)
  1136. (let* ((out (assoc-ref outputs "out"))
  1137. (libllvmlite.so (string-append out "/lib/python"
  1138. ,(version-major+minor
  1139. (package-version python))
  1140. "/site-packages/llvmlite/"
  1141. "binding/libllvmlite.so")))
  1142. (substitute* "llvmlite/binding/ffi.py"
  1143. (("_lib_name = get_library_name\\(\\)")
  1144. (format #f "_lib_name = ~s" libllvmlite.so)))
  1145. #t)))
  1146. (add-after 'unpack 'skip-failing-tests
  1147. (lambda _
  1148. (substitute* "llvmlite/tests/test_binding.py"
  1149. ((" def test_libm\\(self\\).*" all)
  1150. (string-append " @unittest.skip('Fails on Guix')\n" all)))
  1151. #t))
  1152. (add-before 'build 'set-compiler/linker-flags
  1153. (lambda* (#:key inputs #:allow-other-keys)
  1154. (let ((llvm (assoc-ref inputs "llvm")))
  1155. ;; Refer to ffi/Makefile.linux.
  1156. (setenv "CPPFLAGS" "-fPIC")
  1157. (setenv "LDFLAGS" (string-append "-Wl,-rpath="
  1158. llvm "/lib"))
  1159. #t))))))
  1160. (inputs
  1161. `(("llvm"
  1162. ,(let* ((patches-commit "061ab39e1d4591f3aa842458252a19ad01858167")
  1163. (patch-uri (lambda (name)
  1164. (string-append
  1165. "https://raw.githubusercontent.com/numba/"
  1166. "llvmlite/" patches-commit "/conda-recipes/"
  1167. name)))
  1168. (patch-origin (lambda (name hash)
  1169. (origin
  1170. (method url-fetch)
  1171. (uri (patch-uri name))
  1172. (sha256 (base32 hash)))))
  1173. (arch-independent-patches
  1174. (list
  1175. (patch-origin
  1176. "partial-testing.patch"
  1177. "1cwy4jsmijd838q0bylxl77vrwrb7ksijfly5062ay32303jmj86")
  1178. (patch-origin
  1179. "0001-Revert-Limit-size-of-non-GlobalValue-name.patch"
  1180. "0n4k7za0smx6qwdipsh6x5lm7bfvzzb3p9r8q1zq1dqi4na21295"))))
  1181. (if (string=? "aarch64-linux" (%current-system))
  1182. (package
  1183. (inherit llvm-9)
  1184. (source
  1185. (origin
  1186. (inherit (package-source llvm-9))
  1187. (patches
  1188. `(,(patch-origin
  1189. "intel-D47188-svml-VF_LLVM9.patch"
  1190. "1f9ld7wc8bn4gbvdsmk07w1rq371h42vy05rxsq9a22f57rljqbd")
  1191. ,@arch-independent-patches
  1192. ,@(origin-patches (package-source llvm-9)))))))
  1193. (package
  1194. (inherit llvm-10)
  1195. (source
  1196. (origin
  1197. (inherit (package-source llvm-10))
  1198. (patches
  1199. `(,(patch-origin
  1200. "intel-D47188-svml-VF.patch"
  1201. "0n46qjwfl7i12bl7wp0cyxl277axfvaaz5lxx5kdlgwjcpa582dg")
  1202. ,(patch-origin
  1203. "expect-fastmath-entrypoints-in-add-TLI-mappings.ll.patch"
  1204. "0jxhjkkwwi1cy898l2n57l73ckpw0v73lqnrifp7r1mwpsh624nv")
  1205. ,@arch-independent-patches
  1206. ,@(origin-patches (package-source llvm-10))))))))))))
  1207. (home-page "https://llvmlite.pydata.org")
  1208. (synopsis "Wrapper around basic LLVM functionality")
  1209. (description
  1210. "This package provides a Python binding to LLVM for use in Numba.")
  1211. (license license:bsd-3)))
  1212. (define-public (clang-python-bindings clang)
  1213. "Return a package for the Python bindings of CLANG."
  1214. (package
  1215. (inherit clang)
  1216. (name "python-clang")
  1217. (build-system python-build-system)
  1218. (outputs '("out"))
  1219. (arguments
  1220. '(#:phases (modify-phases %standard-phases
  1221. (add-before 'build 'change-directory
  1222. (lambda _
  1223. (chdir "bindings/python")))
  1224. (add-before 'build 'create-setup-py
  1225. (lambda _
  1226. ;; Generate a basic "setup.py", enough so it can be
  1227. ;; built and installed.
  1228. (with-output-to-file "setup.py"
  1229. (lambda ()
  1230. (display "from setuptools import setup
  1231. setup(name=\"clang\", packages=[\"clang\"])\n")))))
  1232. (add-before 'build 'set-libclang-file-name
  1233. (lambda* (#:key inputs #:allow-other-keys)
  1234. ;; Record the absolute file name of libclang.so.
  1235. (let ((clang (assoc-ref inputs "clang")))
  1236. (substitute* "clang/cindex.py"
  1237. (("libclang\\.so")
  1238. (string-append clang "/lib/libclang.so")))))))))
  1239. (inputs `(("clang" ,clang)))
  1240. (synopsis "Python bindings to libclang")))
  1241. (define-public python-clang-10
  1242. (clang-python-bindings clang-10))
  1243. (define-public python-clang-11
  1244. (clang-python-bindings clang-11))
  1245. (define-public python-clang-12
  1246. (clang-python-bindings clang-12))
  1247. (define-public emacs-clang-format
  1248. (package
  1249. (inherit clang)
  1250. (name "emacs-clang-format")
  1251. (build-system emacs-build-system)
  1252. (inputs
  1253. `(("clang" ,clang)))
  1254. (arguments
  1255. `(#:phases
  1256. (modify-phases %standard-phases
  1257. (add-after 'unpack 'configure
  1258. (lambda* (#:key inputs #:allow-other-keys)
  1259. (let ((clang (assoc-ref inputs "clang")))
  1260. (copy-file "tools/clang-format/clang-format.el" "clang-format.el")
  1261. (emacs-substitute-variables "clang-format.el"
  1262. ("clang-format-executable"
  1263. (string-append clang "/bin/clang-format"))))
  1264. #t)))))
  1265. (synopsis "Format code using clang-format")
  1266. (description "This package filters code through @code{clang-format}
  1267. to fix its formatting. @code{clang-format} is a tool that formats
  1268. C/C++/Obj-C code according to a set of style options, see
  1269. @url{https://clang.llvm.org/docs/ClangFormatStyleOptions.html}.")))
  1270. (define-public emacs-clang-rename
  1271. (package
  1272. (inherit clang)
  1273. (name "emacs-clang-rename")
  1274. (build-system emacs-build-system)
  1275. (inputs
  1276. `(("clang" ,clang)))
  1277. (arguments
  1278. `(#:phases
  1279. (modify-phases %standard-phases
  1280. (add-after 'unpack 'configure
  1281. (lambda* (#:key inputs #:allow-other-keys)
  1282. (let ((clang (assoc-ref inputs "clang")))
  1283. (copy-file "tools/clang-rename/clang-rename.el" "clang-rename.el")
  1284. (emacs-substitute-variables "clang-rename.el"
  1285. ("clang-rename-binary"
  1286. (string-append clang "/bin/clang-rename"))))
  1287. #t)))))
  1288. (synopsis "Rename every occurrence of a symbol using clang-rename")
  1289. (description "This package renames every occurrence of a symbol at point
  1290. using @code{clang-rename}.")))
  1291. (define make-ocaml-llvm
  1292. ;; Make it a memoizing procedure so its callers below don't end up defining
  1293. ;; two equal-but-not-eq "ocaml-llvm" packages for the default LLVM.
  1294. (mlambdaq (llvm)
  1295. (package
  1296. (inherit llvm)
  1297. (name "ocaml-llvm")
  1298. (outputs '("out"))
  1299. (arguments
  1300. `(#:configure-flags
  1301. (list
  1302. (string-append "-DLLVM_OCAML_EXTERNAL_LLVM_LIBDIR="
  1303. (assoc-ref %build-inputs "llvm") "/lib")
  1304. "-DBUILD_SHARED_LIBS=TRUE"
  1305. "-DLLVM_OCAML_OUT_OF_TREE=TRUE"
  1306. (string-append "-DLLVM_OCAML_INSTALL_PATH="
  1307. (assoc-ref %outputs "out") "/lib/ocaml/site-lib"))
  1308. #:phases
  1309. (modify-phases %standard-phases
  1310. (replace 'build
  1311. (lambda _
  1312. (invoke "make" "ocaml_all")))
  1313. (replace 'install
  1314. (lambda _
  1315. (invoke "cmake" "-P" "bindings/ocaml/cmake_install.cmake"))))))
  1316. (inputs
  1317. `(("llvm" ,llvm)))
  1318. (native-inputs
  1319. `(("ocaml" ,ocaml)
  1320. ("ocaml-findlib" ,ocaml-findlib)
  1321. ("ocaml-ounit" ,ocaml-ounit)
  1322. ("python" ,python)))
  1323. (propagated-inputs
  1324. `(("ocaml-integers" ,ocaml-integers)
  1325. ("ocaml-ctypes" ,ocaml-ctypes)))
  1326. (synopsis "OCaml bindings to LLVM")
  1327. (description "This package contains the OCaml bindings distributed with
  1328. LLVM."))))
  1329. (define-public ocaml-llvm (make-ocaml-llvm llvm))
  1330. (define-public ocaml-llvm-9 (make-ocaml-llvm llvm-9))
  1331. (define-public ocaml-llvm-10 (make-ocaml-llvm llvm-10))
  1332. (define-public ocaml-llvm-11 (make-ocaml-llvm llvm-11))