all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludovic.courtes@inria.fr>
To: Efraim Flashner <efraim@flashner.co.il>
Cc: guix-devel <guix-devel@gnu.org>
Subject: Re: Packaging ‘clang-tools-extra’ (‘clang-tidy’, etc.)
Date: Tue, 05 May 2020 12:21:21 +0200	[thread overview]
Message-ID: <87v9lalm1q.fsf@inria.fr> (raw)
In-Reply-To: <20200427085041.GI5243@E5400> (Efraim Flashner's message of "Mon,  27 Apr 2020 11:50:41 +0300")

[-- Attachment #1: Type: text/plain, Size: 526 bytes --]

Hello!

Clang-tools-extra is really meant to built within the Clang tree.
Attach is an attempt to build it out-of-tree but so far it fails with
undefined references for Clang libraries and the obvious solution of
adding ‘-l’ flags until it’s happy doesn’t work.

In my original attempt, the ‘clang-tidy’ binary is 40 MiB, and 32 MiB
are text.  This prolly comes from the fact that many Clang libraries
(libclang[A-Z]*.a) are statically linked in each of these programs.

Ideas welcome!

Ludo’.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 4041 bytes --]

diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index 33d863ae11..896b7afb47 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -382,6 +382,52 @@ output), and Binutils.")
 (define-public clang-toolchain-10
   (make-clang-toolchain clang-10))
 
+(define (make-clang-tools-extra clang)
+  ;; XXX: An attempt to build clang-tools-extra outside the Clang tree.
+  (package
+    (inherit clang)
+    (name "clang-tools-extra")
+    (source (origin
+              (method url-fetch)
+              (uri (llvm-download-uri "clang-tools-extra"
+                                      (package-version llvm-10)))
+              (sha256
+               (base32
+                "074ija5s2jsdn0k035r2dzmryjmqxdnyg4xwvaqych2bazv8rpxc"))
+              (patches (search-patches "clang-tools-extra-cmake.patch"))))
+    (arguments
+     '(#:build-type "Release"
+       #:phases (modify-phases %standard-phases
+                  (add-before 'configure 'copy-clang-cmake-module
+                    (lambda* (#:key inputs #:allow-other-keys)
+                      (let ((clang-source (assoc-ref inputs "clang-source")))
+                        (mkdir "../clang-source")
+                        (with-directory-excursion "../clang-source"
+                          (invoke "tar" "xf" clang-source))
+
+                        ;; 'cmake/modules' is in the search path of the
+                        ;; top-level 'CMakeLists.txt', so copy it there.
+                        (install-file (car (find-files "../clang-source"
+                                                       "^AddClang\\.cmake$"))
+                                      "cmake/modules")
+                        #t)))
+                  (add-before 'build 'augment-header-path
+                    (lambda _
+                      (let ((context-h (car (find-files "../clang-source"
+                                                        "^Context\\.h$"))))
+                        (setenv "CPATH"
+                                (string-append (dirname
+                                                (canonicalize-path context-h))
+                                               ":" (getenv "CPATH")))
+                        #t))))))
+    (inputs
+     `(("clang" ,clang)
+       ("clang-source", (package-source clang))
+       ,@(package-inputs clang)))))
+
+(define-public clang-tools-extra-10
+  (make-clang-tools-extra clang-10))
+
 (define-public llvm-9
   (package
     (inherit llvm-10)
diff --git a/gnu/packages/patches/clang-tools-extra-cmake.patch b/gnu/packages/patches/clang-tools-extra-cmake.patch
new file mode 100644
index 0000000000..96672bb2dd
--- /dev/null
+++ b/gnu/packages/patches/clang-tools-extra-cmake.patch
@@ -0,0 +1,38 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 57bb970..6e5de7c 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -1,3 +1,33 @@
++cmake_minimum_required(VERSION 3.4.3)
++
++project(Clang-Tools-Extra)
++
++find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_PATH}")
++list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR})
++
++# This is the place where we put Clang's 'AddClang.cmake'.
++list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
++
++set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin")
++set(LLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "Path to llvm/lib")
++set(LLVM_MAIN_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Path to llvm/include")
++set(LLVM_BINARY_DIR ${LLVM_OBJ_ROOT} CACHE PATH "Path to LLVM build tree")
++set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
++
++set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
++
++include(AddClang)
++include(AddLLVM)
++include(TableGen)
++include(HandleLLVMOptions)
++include(VersionFromVCS)
++include(LLVMDistributionSupport)
++
++# Dummy targets to appease CMake.  These are normally found in the
++# Clang tree.
++add_custom_target(clang-resource-headers)
++add_custom_target(ClangSACheckers)
++
+ include(CMakeDependentOption)
+ 
+ add_subdirectory(clang-apply-replacements)

  parent reply	other threads:[~2020-05-05 10:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-24 13:36 Packaging ‘clang-tools-extra’ (‘clang-tidy’, etc.) Ludovic Courtès
2020-04-24 17:07 ` Nikita Gillmann
2020-04-27  7:31   ` Ludovic Courtès
2020-04-27  8:50     ` Efraim Flashner
2020-04-27 11:23       ` Nikita Gillmann
2020-05-05 10:21       ` Ludovic Courtès [this message]
2020-05-29 16:57 ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v9lalm1q.fsf@inria.fr \
    --to=ludovic.courtes@inria.fr \
    --cc=efraim@flashner.co.il \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.