llvm.scm 60 KB

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