[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Packaging ‘clang-tools-extra’ (‘clang-tidy’, etc.)
From: |
Ludovic Courtès |
Subject: |
Re: Packaging ‘clang-tools-extra’ (‘clang-tidy’, etc.) |
Date: |
Tue, 05 May 2020 12:21:21 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) |
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’.
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)
- Re: Packaging ‘clang-tools-extra’ (‘clang-tidy’, etc.),
Ludovic Courtès <=