Merge remote-tracking branch 'master' into core-updates.
[jackhill/guix/guix.git] / gnu / packages / llvm.scm
index 054b42d..ae5fe72 100644 (file)
@@ -6,11 +6,14 @@
 ;;; Copyright © 2016, 2018, 2019 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2017 Roel Janssen <roel@gnu.org>
 ;;; Copyright © 2018, 2019 Marius Bakke <mbakke@fastmail.com>
-;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
+;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;; Copyright © 2018 Efraim Flashner <efraim@flashner.co.il>
 ;;; Copyright © 2018 Tim Gesthuizen <tim.gesthuizen@yahoo.de>
 ;;; Copyright © 2018 Pierre Neidhardt <mail@ambrevar.xyz>
 ;;; Copyright © 2019 Rutger Helling <rhelling@mykolab.com>
+;;; Copyright © 2019 Arm Ltd <David.Truby@arm.com>
+;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
+;;; Copyright © 2019 Brett Gilio <brettg@gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
   #:use-module (guix packages)
   #:use-module ((guix licenses) #:prefix license:)
   #:use-module (guix download)
+  #:use-module (guix git-download)
   #:use-module (guix utils)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system cmake)
   #:use-module (guix build-system emacs)
   #:use-module (guix build-system python)
+  #:use-module (guix build-system trivial)
   #:use-module (gnu packages)
+  #:use-module (gnu packages base)
   #:use-module (gnu packages gcc)
   #:use-module (gnu packages bootstrap)           ;glibc-dynamic-linker
   #:use-module (gnu packages compression)
   #:use-module (gnu packages perl)
   #:use-module (gnu packages pkg-config)
   #:use-module (gnu packages python)
-  #:use-module (gnu packages xml))
-
-(define-public llvm
+  #:use-module (gnu packages xml)
+  #:export (system->llvm-target))
+
+(define* (system->llvm-target #:optional
+                              (system (or (and=> (%current-target-system)
+                                                 gnu-triplet->nix-system)
+                                          (%current-system))))
+  "Return the LLVM target name that corresponds to SYSTEM, a system type such
+as \"x86_64-linux\"."
+  ;; See the 'lib/Target' directory of LLVM for a list of supported targets.
+  (letrec-syntax ((matches (syntax-rules (=>)
+                             ((_ (system-prefix => target) rest ...)
+                              (if (string-prefix? system-prefix system)
+                                  target
+                                  (matches rest ...)))
+                             ((_)
+                              (error "LLVM target for system is unknown" system)))))
+    (matches ("aarch64"     => "AArch64")
+             ("armhf"       => "ARM")
+             ("mips64el"    => "Mips")
+             ("powerpc"     => "PowerPC")
+             ("riscv"       => "RISCV")
+             ("x86_64"      => "X86")
+             ("i686"        => "X86"))))
+
+(define-public llvm-8
   (package
     (name "llvm")
     (version "8.0.0")
@@ -60,6 +89,7 @@
        (base32
         "0k124sxkfhfi1rca6kzkdraf4axhx99x3cw2rk55056628dvwwl8"))))
     (build-system cmake-build-system)
+    (outputs '("out" "opt-viewer"))
     (native-inputs
      `(("python" ,python-2) ;bytes->str conversion in clang>=3.7 needs python-2
        ("perl"   ,perl)))
 
        ;; Don't use '-g' during the build, to save space.
        #:build-type "Release"
-       #:phases (modify-phases %standard-phases
-                  (add-before 'build 'shared-lib-workaround
-                    ;; Even with CMAKE_SKIP_BUILD_RPATH=FALSE, llvm-tblgen
-                    ;; doesn't seem to get the correct rpath to be able to run
-                    ;; from the build directory.  Set LD_LIBRARY_PATH as a
-                    ;; workaround.
-                    (lambda _
-                      (setenv "LD_LIBRARY_PATH"
-                              (string-append (getcwd) "/lib"))
-                      #t)))))
+       #:phases
+       (modify-phases %standard-phases
+         (add-before 'build 'shared-lib-workaround
+           ;; Even with CMAKE_SKIP_BUILD_RPATH=FALSE, llvm-tblgen
+           ;; doesn't seem to get the correct rpath to be able to run
+           ;; from the build directory.  Set LD_LIBRARY_PATH as a
+           ;; workaround.
+           (lambda _
+             (setenv "LD_LIBRARY_PATH"
+                     (string-append (getcwd) "/lib"))
+             #t))
+         (add-after 'install 'install-opt-viewer
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (opt-viewer-out (assoc-ref outputs "opt-viewer"))
+                    (opt-viewer-share-dir (string-append opt-viewer-out "/share"))
+                    (opt-viewer-dir (string-append opt-viewer-share-dir "/opt-viewer")))
+               (mkdir-p opt-viewer-share-dir)
+               (rename-file (string-append out "/share/opt-viewer")
+                            opt-viewer-dir))
+             #t)))))
     (home-page "https://www.llvm.org")
     (synopsis "Optimizing compiler infrastructure")
     (description
@@ -98,6 +139,8 @@ languages is in development.  The compiler infrastructure includes mirror sets
 of programming tools as well as libraries with equivalent functionality.")
     (license license:ncsa)))
 
+(define-public llvm llvm-8)
+
 (define* (clang-runtime-from-llvm llvm hash
                                   #:optional (patches '()))
   (package
@@ -175,10 +218,13 @@ compiler.  In LLVM this library is called \"compiler-rt\".")
                    'unpack 'set-glibc-file-names
                    (lambda* (#:key inputs #:allow-other-keys)
                      (let ((libc (assoc-ref inputs "libc"))
-                           (compiler-rt (assoc-ref inputs "clang-runtime")))
-                       (case (string->number ,(version-major
-                                               (package-version clang-runtime)))
-                         ((or 6 7)
+                           (compiler-rt (assoc-ref inputs "clang-runtime"))
+                           (gcc (assoc-ref inputs "gcc"))
+                           (version
+                            (string->number
+                             ,(version-major (package-version clang-runtime)))))
+                       (cond
+                         ((> version 3)
                           ;; Link to libclang_rt files from clang-runtime.
                           (substitute* "lib/Driver/ToolChain.cpp"
                             (("getDriver\\(\\)\\.ResourceDir")
@@ -190,11 +236,17 @@ compiler.  In LLVM this library is called \"compiler-rt\".")
                             (("(^[[:blank:]]+LibDir = ).*" _ declaration)
                              (string-append declaration "\"" libc "/lib\";\n"))
 
+                            ;; Make clang look for libstdc++ in the right
+                            ;; location.
+                            (("LibStdCXXIncludePathCandidates\\[\\] = \\{")
+                             (string-append
+                              "LibStdCXXIncludePathCandidates[] = { \"" gcc "/include/c++\","))
+
                             ;; Make sure libc's libdir is on the search path, to
                             ;; allow crt1.o & co. to be found.
                             (("@GLIBC_LIBDIR@")
                              (string-append libc "/lib"))))
-                         ((3)
+                         (else
                           (substitute* "lib/Driver/Tools.cpp"
                             ;; Patch the 'getLinuxDynamicLinker' function so that
                             ;; it uses the right dynamic linker file name.
@@ -262,6 +314,51 @@ project includes the Clang front end, the Clang static analyzer, and several
 code analysis tools.")
     (license license:ncsa)))
 
+(define (make-clang-toolchain clang)
+  (package
+    (name (string-append (package-name clang) "-toolchain"))
+    (version (package-version clang))
+    (source #f)
+    (build-system trivial-build-system)
+    (arguments
+     '(#:modules ((guix build union))
+       #:builder (begin
+                   (use-modules (ice-9 match)
+                                (srfi srfi-26)
+                                (guix build union))
+
+                   (let ((out (assoc-ref %outputs "out")))
+
+                     (match %build-inputs
+                       (((names . directories) ...)
+                        (union-build out directories)))
+
+                     (union-build (assoc-ref %outputs "debug")
+                                  (list (assoc-ref %build-inputs
+                                                   "libc-debug")))
+                     (union-build (assoc-ref %outputs "static")
+                                  (list (assoc-ref %build-inputs
+                                                   "libc-static")))
+                     #t))))
+
+    (native-search-paths (package-native-search-paths clang))
+    (search-paths (package-search-paths clang))
+
+    (license (package-license clang))
+    (home-page "https://clang.llvm.org")
+    (synopsis "Complete Clang toolchain for C/C++ development")
+    (description "This package provides a complete Clang toolchain for C/C++
+development to be installed in user profiles.  This includes Clang, as well as
+libc (headers and binaries, plus debugging symbols in the @code{debug}
+output), and Binutils.")
+    (outputs '("out" "debug" "static"))
+    (inputs `(("clang" ,clang)
+              ("ld-wrapper" ,(car (assoc-ref (%final-inputs) "ld-wrapper")))
+              ("binutils" ,binutils)
+              ("libc" ,glibc)
+              ("libc-debug" ,glibc "debug")
+              ("libc-static" ,glibc "static")))))
+
 (define-public libcxx
   (package
     (name "libcxx")
@@ -285,18 +382,57 @@ code analysis tools.")
 use with Clang, targeting C++11, C++14 and above.")
     (license license:expat)))
 
+(define-public libclc
+  (package
+    (name "libclc")
+    (version (package-version llvm))
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/llvm/llvm-project.git")
+             (commit (string-append "llvmorg-" version))))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32
+         "052h16wjcnqginzp7ki4il2xmm25v9nyk0wcz7cg03gbryhl7aqa"))))
+    (build-system cmake-build-system)
+    (arguments
+     `(#:configure-flags
+       (list (string-append "-DLLVM_CLANG="
+                            (assoc-ref %build-inputs "clang")
+                            "/bin/clang")
+             (string-append "-DPYTHON="
+                            (assoc-ref %build-inputs "python")
+                            "/bin/python3"))
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'chdir
+           (lambda _ (chdir "libclc") #t)))))
+    (native-inputs
+     `(("clang" ,clang)
+       ("llvm" ,llvm)
+       ("python" ,python)))
+    (home-page "https://libclc.llvm.org")
+    (synopsis "Libraries for the OpenCL programming language")
+    (description
+     "This package provides an implementation of the OpenCL library
+requirements according to version 1.1 of the OpenCL specification.")
+    ;; Apache license 2.0 with LLVM exception
+    (license license:asl2.0)))
+
 (define-public libomp
   (package
     (name "libomp")
     (version (package-version llvm))
     (source (origin
               (method url-fetch)
-              (uri (string-append "http://releases.llvm.org/"
+              (uri (string-append "https://releases.llvm.org/"
                                   version  "/openmp-" version
                                   ".src.tar.xz"))
               (sha256
                (base32
-                "030dkg5cypd7j9hq0mcqb5gs31lxwmzfq52j81l7v9ldcy5bf5mz"))
+                "1mf9cpgvix34xlpv0inkgl3qmdvgvp96f7sksqizri0n5xfp1cgp"))
               (file-name (string-append "libomp-" version ".tar.xz"))))
     (build-system cmake-build-system)
     ;; XXX: Note this gets built with GCC because building with Clang itself
@@ -305,7 +441,7 @@ use with Clang, targeting C++11, C++14 and above.")
      '(#:configure-flags '("-DLIBOMP_USE_HWLOC=ON"
                            "-DOPENMP_TEST_C_COMPILER=clang"
                            "-DOPENMP_TEST_CXX_COMPILER=clang++")
-       #:test-target "check-libomptarget"))
+       #:test-target "check-libomp"))
     (native-inputs
      `(("clang" ,clang)
        ("llvm" ,llvm)
@@ -332,6 +468,59 @@ with that of libgomp, the GNU Offloading and Multi Processing Library.")
                    "0svk1f70hvpwrjp6x5i9kqwrqwxnmcrw5s7f4cxyd100mdd12k08"
                    #:patches '("clang-7.0-libc-search-path.patch")))
 
+(define-public clang-toolchain
+  (make-clang-toolchain clang))
+
+(define-public llvm-9
+  (package
+    (inherit llvm)
+    (version "9.0.0")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append "https://llvm.org/releases/"
+                                  version "/llvm-" version ".src.tar.xz"))
+              (sha256
+               (base32
+                "117ymdz1by2nkfq1c2p9m4050dp848kbjbiv6nsfj8hzy9f5d86n"))))
+    (license license:asl2.0)))
+
+(define-public clang-runtime-9
+  (clang-runtime-from-llvm
+   llvm-9
+   "03ni43lbkp63lr3p6sc94dphqmvnz5av5mml0xmk930xvnbcvr2n"))
+
+(define-public clang-9
+  (clang-from-llvm llvm-9 clang-runtime-9
+                   "0426ma80i41qsgzm1qdz81mjskck426diygxi2k5vji2gkpixa3v"))
+
+(define-public clang-toolchain-9
+  (make-clang-toolchain clang-9))
+
+(define-public llvm-7
+  (package
+    (inherit llvm)
+    (version "7.0.1")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append "https://llvm.org/releases/"
+                                  version "/llvm-" version ".src.tar.xz"))
+              (sha256
+               (base32
+                "16s196wqzdw4pmri15hadzqgdi926zln3an2viwyq0kini6zr3d3"))))))
+
+(define-public clang-runtime-7
+  (clang-runtime-from-llvm
+   llvm-7
+   "065ybd8fsc4h2hikbdyricj6pyv4r7r7kpcikhb2y5zf370xybkq"))
+
+(define-public clang-7
+  (clang-from-llvm llvm-7 clang-runtime
+                   "067lwggnbg0w1dfrps790r5l6k8n5zwhlsw7zb6zvmfpwpfn4nx4"
+                   #:patches '("clang-7.0-libc-search-path.patch")))
+
+(define-public clang-toolchain-7
+  (make-clang-toolchain clang-7))
+
 (define-public llvm-6
   (package
     (inherit llvm)
@@ -354,6 +543,26 @@ with that of libgomp, the GNU Offloading and Multi Processing Library.")
                    "0rxn4rh7rrnsqbdgp4gzc8ishbkryhpl1kd3mpnxzpxxhla3y93w"
                    #:patches '("clang-6.0-libc-search-path.patch")))
 
+(define-public clang-toolchain-6
+  (make-clang-toolchain clang-6))
+
+;; Libcxx files specifically used by PySide2.
+(define-public libcxx-6
+  (package
+    (inherit libcxx)
+    (version (package-version llvm-6))
+    (source
+     (origin
+       (inherit (package-source libcxx))
+       (uri (string-append "http://llvm.org/releases/"
+                           version "/libcxx-" version ".src.tar.xz"))
+       (sha256
+        (base32
+         "0rzw4qvxp6qx4l4h9amrq02gp7hbg8lw4m0sy3k60f50234gnm3n"))))
+    (native-inputs
+     `(("clang" ,clang-6)
+       ("llvm" ,llvm-6)))))
+
 (define-public llvm-3.9.1
   (package (inherit llvm)
     (name "llvm")
@@ -491,21 +700,25 @@ with that of libgomp, the GNU Offloading and Multi Processing Library.")
 (define-public python-llvmlite
   (package
     (name "python-llvmlite")
-    (version "0.27.1")
+    (version "0.30.0")
     (source
      (origin
        (method url-fetch)
        (uri (pypi-uri "llvmlite" version))
        (sha256
         (base32
-         "1aq003zbyjnz4q1118h6qx5lfimc8s5fvgskl75j12gxd6pc78a8"))))
+         "01wspdc0xhnydl66jyhyr4ii16h3fnw6mjihiwnnxdxg9j6kkajf"))))
     (build-system python-build-system)
+    (arguments
+     ;; FIXME: One test fails unable to find libm.so
+     ;; https://github.com/numba/llvmlite/issues/537
+     `(#:tests? #f))
     (inputs
      `(("llvm"
         ,(package
-           (inherit llvm)
+           (inherit llvm-7)
            (source (origin
-                     (inherit (package-source llvm))
+                     (inherit (package-source llvm-7))
                      (patches
                       (list
                        (origin