diff mbox series

[bug#50217,v4] gnu: Add c2ffi.

Message ID 20220214123112.20135-1-attila@lendvai.name
State Accepted
Headers show
Series [bug#50217,v4] gnu: Add c2ffi. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Attila Lendvai Feb. 14, 2022, 12:31 p.m. UTC
Orignial work by muradm <mail@muradm.net>, 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(+)

Comments

M Feb. 14, 2022, 3:30 p.m. UTC | #1
Attila Lendvai schreef op ma 14-02-2022 om 13:31 [+0100]:
> +           (replace 'check
> +             (lambda _
> +               (invoke "./bin/c2ffi" "--help"))))))

For cross-compiling c2ffi, this needs to respect #:tests?, because
tests cannot be run when cross-compiling.  This would be detected by
"./pre-inst-env guix lint".

Greetings,
Maxime.
M Feb. 14, 2022, 3:34 p.m. UTC | #2
Attila Lendvai schreef op ma 14-02-2022 om 13:31 [+0100]:
> +  (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)))

Isn't it the other way around?  Looking at the git repo, the git tag is
v12.0.0.0, not 12.0.0.0, and Guix strips version prefixes like "v", "V"
and "version-".  Also, IIUC, the current consensus is that home pages
and source git repos are separate things, even if sometimes their URL
coincides, so the URL may need to be copied into the 'url' field.

Greetings,
Maxime.
M Feb. 14, 2022, 3:41 p.m. UTC | #3
Attila Lendvai schreef op ma 14-02-2022 om 13:31 [+0100]:
> +      (native-inputs
> +       (list clang-12 llvm-12))

Is clang (the C compiler) required to compile c2fii, or would the usual
gcc suffice?  If the former, I would add a comment

  ;; only supports compilation with clang, gcc does not work here

or the like.  Is the version of clang and LLVM used for compiling c2ffi
important?  If not, I would write (native-inputs (list clang llvm))
such that the default clang and LLVM version in Guix is used.

Greetings,
Maxime.
diff mbox series

Patch

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 <jgart@dismail.de>
 ;;; Copyright © 2021 Julien Lepiller <julien@lepiller.eu>
 ;;; Copyright © 2021 Disseminate Dissent <disseminatedissent@protonmail.com>
+;;; Copyright © 2021 muradm <mail@muradm.net>
+;;; Copyright © 2021 Attila Lendvai <attila@lendvai.name>
 ;;;
 ;;; 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+))))