Subject: [bug#59237] [PATCH 3/3] gnu: Add clang-15.

From: Maxim Cournoyer <[email-masked]>
Date: Sun, 13 Nov 2022 00:02:00 -0500

* gnu/packages/llvm.scm (clang-from-llvm*): New helper.
(clang-15): New variable.
---
 gnu/packages/llvm.scm | 61 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index d7b6207dc4..12e1e642c6 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -422,6 +422,43 @@ (define* (clang-from-llvm llvm clang-runtime
                  license:asl2.0         ;with LLVM exceptions
                  license:ncsa))))
 
+;;; TODO: Integrate into original on core-updates, perhaps with an extra
+;;; option such as #:build-shared-libs? documented as a legacy feature.
+(define* (clang-from-llvm* llvm clang-runtime
+                           #:optional hash
+                           #:key (patches '()) tools-extra
+                           (properties
+                            (append `((release-monitoring-url
+                                       . ,%llvm-release-monitoring-url))
+                                    (clang-properties (package-version llvm)))))
+  "Produce Clang with dependencies on LLVM and CLANG-RUNTIME, and applying the
+given PATCHES.  When TOOLS-EXTRA is given, it must point to the
+'clang-tools-extra' tarball, which contains code for 'clang-tidy', 'pp-trace',
+'modularize', and other tools."
+  (let ((base (clang-from-llvm llvm clang-runtime hash
+                               #:patches patches #:tools-extra tools-extra
+                               #:properties properties)))
+    (package
+      (inherit base)
+      (arguments
+       (substitute-keyword-arguments (package-arguments base)
+         ((#:phases phases ''%standard-phases)
+          #~(modify-phases #$phases
+              ;; Like the original, sans BUILD_SHARED_LIBS patching.
+              #$@(if tools-extra
+                     #~((replace 'add-tools-extra
+                          (lambda* (#:key inputs #:allow-other-keys)
+                            ;; Unpack the 'clang-tools-extra' tarball under
+                            ;; tools/.
+                            (let ((extra (assoc-ref inputs "clang-tools-extra")))
+                              (invoke "tar" "xf" extra)
+                              (rename-file #$(string-append
+                                              "clang-tools-extra-"
+                                              (string-delete #\- (package-version llvm))
+                                              ".src")
+                                           "tools/extra")))))
+                     #~()))))))))
+
 (define (clang-properties version)
   "Return package properties for Clang VERSION."
   `((compiler-cpu-architectures
@@ -729,6 +766,30 @@ (define-public clang-runtime-14
          ("gcc" ,gcc-11)
          ,@(package-native-inputs template))))))
 
+(define-public clang-15
+  (let ((template
+         (clang-from-llvm*
+          llvm-15 clang-runtime-15
+          #:tools-extra
+          (origin
+            (method url-fetch)
+            (uri (llvm-uri "clang-tools-extra"
+                           (package-version llvm-15)))
+            (sha256
+             (base32
+              "03adxlh84if9p53m6izjsql500rjza9rng8akab2pdqibgrg73rh"))))))
+    (package
+      (inherit template)
+      (arguments
+       (substitute-keyword-arguments (package-arguments template)
+         ((#:configure-flags flags ''())
+          #~(cons "-DCLANG_LINK_CLANG_DYLIB=ON" #$flags))
+         ((#:phases phases '%standard-phases)
+          #~(modify-phases #$phases
+              (add-after 'unpack 'change-directory
+                (lambda _
+                  (chdir "clang"))))))))))
+
 (define-public clang-14
   (let ((template
          (clang-from-llvm llvm-14 clang-runtime-14
-- 
2.38.1