From 41c85063304b49751987554b433da45b318498ad Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Sun, 22 Sep 2024 01:10:02 +0900 Subject: gnu: cling: Wrap with GCC include paths. (cling) [phases] : Do not patch CLING_CXX_RLTV anymore; this is now handled more correctly by wrapping the 'cling' executable. Adjust file name of clang lib directory. : New phases. [inputs]: Add gcc-toolchain*, a delayed version of gcc-toolchain, used in the wrap phase. Fixes: https://issues.guix.gnu.org/57116 Change-Id: I29f9eee8f4a0e91eadc2eeff2a70d58db3ed0a26 --- gnu/packages/llvm.scm | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm index 6c1d5bc372..f199472455 100644 --- a/gnu/packages/llvm.scm +++ b/gnu/packages/llvm.scm @@ -2390,12 +2390,6 @@ LLVM bitcode files.") (substitute* "lib/Interpreter/CIFactory.cpp" (("\\bsed\\b") (which "sed")) - ;; This ensures that the default C++ library used by Cling is - ;; that of the compiler that was used to build it, rather - ;; than that of whatever g++ happens to be on PATH. - (("ReadCompilerIncludePaths\\(CLING_CXX_RLTV") - (format #f "ReadCompilerIncludePaths(~s" - (search-input-file inputs "bin/g++"))) ;; Cling uses libclang's CompilerInvocation::GetResourcesPath ;; to resolve Clang's library prefix, but this fails on Guix ;; because it is relative to the output of cling rather than @@ -2427,9 +2421,28 @@ LLVM bitcode files.") (add-after 'install 'delete-static-libraries ;; This reduces the size from 17 MiB to 5.4 MiB. (lambda _ - (for-each delete-file (find-files #$output "\\.a$"))))))) + (for-each delete-file (find-files #$output "\\.a$")))) + (add-after 'install 'wrap-with-include-paths + ;; Cling is sensitive to miss-matched include directives; ensure + ;; the GCC includes used match that of the GCC used to build + ;; Cling. + (lambda* (#:key inputs #:allow-other-keys) + (let ((gcc-toolchain #$(this-package-input "gcc-toolchain"))) + (wrap-program (string-append #$output "/bin/cling") + `("C_INCLUDE_PATH" prefix + (,(string-append gcc-toolchain "/include"))) + `("CPLUS_INCLUDE_PATH" prefix + (,(string-append gcc-toolchain "/include/c++") + ,(string-append gcc-toolchain "/include"))))))) + (add-after 'wrap-with-include-paths 'fix-wrapper + (lambda _ + ;; When -a $0 is used, the cling executable segfauts (see: + ;; https://issues.guix.gnu.org/73405). + (substitute* (string-append #$output "/bin/cling") + (("\"\\$0\"") + "\"${0##*/}\""))))))) (native-inputs (list python python-lit)) - (inputs (list clang-cling llvm-cling libxcrypt)) + (inputs (list clang-cling (force gcc-toolchain*) llvm-cling libxcrypt)) (home-page "https://root.cern/cling/") (synopsis "Interactive C++ interpreter") (description "Cling is an interactive C++17 standard compliant -- cgit v1.2.3