Subject: [bug#50217] [PATCH v3] gnu: Add c2ffi.

From: Attila Lendvai <[email-masked]>
Date: Wed, 12 Jan 2022 18:13:31 +0100

Orignial work by muradm <[email-masked]>, fixes by Attila Lendvai.

* gnu/packages/cpp.scm (c2ffi): New variable.
---

v3 converts the input lists to the new format.

 gnu/packages/cpp.scm | 47 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
index 718fb20652..d7e2ff49e5 100644
--- a/gnu/packages/cpp.scm
+++ b/gnu/packages/cpp.scm
@@ -22,6 +22,8 @@
 ;;; Copyright © 2021 Nicolò Balzarotti <[email-masked]>
 ;;; Copyright © 2021 Guillaume Le Vaillant <[email-masked]>
 ;;; Copyright © 2021 Nikolay Korotkiy <[email-masked]>
+;;; Copyright © 2021 muradm <[email-masked]>
+;;; Copyright © 2021 Attila Lendvai <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1452,3 +1454,48 @@ (define-public simdjson
 validation.")
     (home-page "https://github.com/simdjson/simdjson")
     (license license:asl2.0)))
+
+(define-public c2ffi
+  (let ((commit "f50243926a0afb589de1078a073ac08910599582")
+        (revision "1"))
+    (package
+      (name "c2ffi")
+      (home-page "https://github.com/rpav/c2ffi")
+      ;; Upstream has no releases, only one branch per LLVM release. Let's put
+      ;; the LLVM version into the version string, use a revision as a
+      ;; human-readable differentiation of the versions that gets imported
+      ;; into Guix, and also use the commit hash to be specific.
+      (version (git-version "11.0.0" revision commit))
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference (url home-page) (commit commit)))
+                (file-name (git-file-name name version))
+                (sha256 (base32 "17j73yb6v3lfvwwicl2f3yg141iz2dk1rf874qzqs5bkq64ldjsj"))
+                (modules '((guix build utils)))
+                (snippet
+                 '(substitute* "CMakeLists.txt"
+                    ;; guix seems to be packaging LLVM libs separately
+                    ;; thus -lLLVM is not working, every used library should
+                    ;; be specified explicitly
+                    (("c2ffi PUBLIC clang-cpp LLVM")
+                     "c2ffi PUBLIC clang-cpp LLVMCore LLVMSupport LLVMMCParser \
+LLVMOption LLVMBitReader LLVMProfileData")))))
+      (build-system cmake-build-system)
+      (arguments
+       '(;; llvm-11 at least seems to be built without RTTI
+         ;; llvm-12 on the other hand specifies -DLLVM_REQUIRES_RTTI=1
+         ;; may fail with this flag when c2ffi for llvm-12 released
+         ;; https://stackoverflow.com/q/11904519
+         #:configure-flags '("-DCMAKE_CXX_FLAGS=-fno-rtti")
+         ;; Upstream has no tests.
+         #:tests? #f))
+      (native-inputs
+       (list clang-11 llvm-11))
+      (inputs
+       (list clang-11 llvm-11))
+      (synopsis "Clang-based FFI wrapper generator")
+      (description "@code{c2ffi} is a tool for extracting definitions from C, C++, and
+Objective C headers for use with foreign function call interfaces.  It uses the
+@code{Clang/LLVM} infrastructure to extract the data, and emits it in various formats,
+including @code{json}.")
+      (license license:gpl2+))))
-- 
2.34.0