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

From: Attila Lendvai <[email-masked]>
Date: Mon, 14 Feb 2022 13:31:13 +0100

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

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

new in v4:
 - rebase to master
 - upstream introduced releases, so let's use git tags
 - use LLVM 12
 - add a trivial test that invokes c2ffi --help

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

diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
index 86138531c0..b394c8e515 100644
--- a/gnu/packages/cpp.scm
+++ b/gnu/packages/cpp.scm
@@ -25,6 +25,8 @@
 ;;; Copyright © 2021 jgart <[email-masked]>
 ;;; Copyright © 2021 Julien Lepiller <[email-masked]>
 ;;; Copyright © 2021 Disseminate Dissent <[email-masked]>
+;;; Copyright © 2021 muradm <[email-masked]>
+;;; Copyright © 2021 Attila Lendvai <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1717,3 +1719,48 @@ (define-public bloomberg-bde
 multi-threaded applications and network applications.")
       (home-page "https://github.com/bloomberg/bde")
       (license license:asl2.0))))
+
+(define-public c2ffi
+  (let ((git-tag "12.0.0.0"))
+    (package
+      (name "c2ffi")
+      (home-page "https://github.com/rpav/c2ffi")
+      (version (string-append "v" git-tag))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (url home-page)
+               (commit version)))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "1qq8dfismd20d9kfxpfvwz07v9mfvd0y7p5r3c92mk2pm4xnmzfy"))
+         (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
+       '(;; If LLVM was built without RTTI, we need to also be built without
+         ;; it.  See: https://stackoverflow.com/q/11904519
+         #:configure-flags '("-DCMAKE_CXX_FLAGS=-fno-rtti")
+         #:phases
+         (modify-phases %standard-phases
+           (replace 'check
+             (lambda _
+               (invoke "./bin/c2ffi" "--help"))))))
+      (native-inputs
+       (list clang-12 llvm-12))
+      (inputs
+       (list clang-12 llvm-12))
+      (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