Subject: [bug#54581] Add emacs-sqlite3-api package

From: Roman Scherer <[email-masked]>
Date: Fri, 01 Apr 2022 11:07:57 +0200

Hi Maxime,

here's a new patch as per your suggestion. I'm removing the code that
downloads from the internet, and the call to date for the NOW variable.

I also remove the SQLITE_STATIC and SQLITE_TRANSIENT sections in the
generated constants.c file, they cause a warning and would have been
remove by the original script.

I changed the #:tests? keyword to (%current-target-system), but I
noticed the tests of the package are now not run anymore when I build
the package. Is this expected?

I tried to specify a target when building the package, but this gives me
the following error:

./pre-inst-env guix build emacs-sqlite3-api --target=x86_64
guix build: error: /home/roman/workspace/guix/gnu/packages/emacs-xyz.scm:5738:4: [email-masked]: build system `emacs' does not support cross builds

Do you know how I can trigger the tests when building this package from
the command line, or even better from within Emacs?

Maxime Devos <[email-masked]> writes:

> [[PGP Signed Part:Undecided]]
> Roman Scherer schreef op zo 27-03-2022 om 19:55 [+0200]:
>> I think my preference would be to go without generating the consts.c
>> file, the patch works, it uses the same file the maintainer of the
>> packages is using, and I believe it is less brittle. :)
>
> I don't expect any practical problems but technically it isn't source
> code, and rather a binary (or, as GPL words it, ‘object code’), at
> least according to the GPL's definition:
>
>   The "source code" for a work means the preferred form of the work
>   for making modifications to it.  "Object code" means any non-source
>   form of a work.
>
> , and Guix builds things from source. I don't think constants.c is in
> preferred form, rather it seems to be sqlite.h
>
> Maybe it's not much of a problem here though, I donk't know.
>
> I don't see the relevancy of what files the maintainer is using.  What
> does maintainerhood have to do with anything?

Well, I was looking at the last time the consts.c has been modified by
the maintainer and it was 2 years ago.

I was thinking it would be more stable to use the code that ships with
the repository, rather than building something from the internet which
hasn't been updated for 2 years.

But if this file is considered object code, ok.

> Greetings,
> Maxime.
>
> [[End of PGP Signed Part]]

From 16a89de32c9ef7458e852169e62eb08f008a6a2b Mon Sep 17 00:00:00 2001
From: r0man <[email-masked]>
Date: Sat, 26 Mar 2022 14:59:01 +0100
Subject: [PATCH] Add emacs-sqlite3-api package

This patch adds the emacs-sqlite3-api package to Guix.

The package provides a dynamic module for Emacs that allows direct access to
the SQLite C interface.  It only exposes a subset of the full SQLite C
interface, but should satisfy most user's needs.

The original source code uses a file called constants.c, which is checked into
the repository, but can be generated by running make in the tools directory of
the source.

However, the procedure to generate this file downloads a list of constants
from the SQLite website. We are patching the scripts to generate those
constants, to not download anything from the internet to have a stable build
process.
---
 gnu/packages/emacs-xyz.scm | 61 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/gnu/packages/emacs-xyz.scm b/gnu/packages/emacs-xyz.scm
index 42fc13f4c2..b4eacce952 100644
--- a/gnu/packages/emacs-xyz.scm
+++ b/gnu/packages/emacs-xyz.scm
@@ -5731,6 +5731,67 @@ (define-public emacs-sqlite
 It is not intended as a user interface.")
       (license license:gpl3+))))
 
+(define-public emacs-sqlite3-api
+  (let ((version "0.15")
+        (revision "0")
+        (commit "7cb4b660fe30deb8a4229f3abb18bd99ca9c971c"))
+    (package
+      (name "emacs-sqlite3-api")
+      (version (git-version version revision commit))
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://github.com/pekingduck/emacs-sqlite3-api")
+                      (commit commit)))
+                (file-name (git-file-name name version))
+                (sha256
+                 (base32
+                  "1b7if1dp6i5kqwhq25gna89xbca66i4mmgx1a5yn12kncfdgs6d7"))))
+      (build-system emacs-build-system)
+      (arguments
+       `(#:modules ((guix build emacs-build-system)
+                    (guix build emacs-utils)
+                    (guix build utils))
+         #:phases
+         (modify-phases %standard-phases
+           (add-after 'unpack 'patch-module-load
+             (lambda* (#:key outputs #:allow-other-keys)
+               (chmod "sqlite3.el" #o644)
+               (emacs-substitute-sexps "sqlite3.el"
+                 ("(require 'sqlite3-api nil t)"
+                  `(module-load ,(string-append (assoc-ref outputs "out")
+                                                "/lib/sqlite3-api.so"))))))
+           (add-before 'check 'build-emacs-module
+             (lambda* (#:key outputs #:allow-other-keys)
+               ;; Remove code that fetches constants from the SQLite website
+               ;; and the call to generate a timestamp.
+               (invoke "sed" "--in-place" "3,4d;24,28d;31d" "tools/gen-consts.sh")
+               ;; Remove filter logic from the script that generates the constants.
+               (invoke "sed" "--in-place" "7,11d;18,22d" "tools/gen-consts.py")
+               ;; Generate the consts.c file.
+               (invoke "make" "--directory=tools")
+               ;; Remove the SQLITE_STATIC and SQLITE_TRANSIENT
+               ;; constants. They cause a compilation warning and would have
+               ;; been removed by the original script.
+               (invoke "sed" "--in-place" "/ifdef SQLITE_STATIC/,+2d" "consts.c")
+               (invoke "sed" "--in-place" "/ifdef SQLITE_TRANSIENT/,+2d" "consts.c")
+               ;; Compile the shared object file.
+               (invoke "make" (string-append "CC=" ,(cc-for-target)))
+               ;; Move the shared object file into /lib.
+               (install-file "sqlite3-api.so"
+                             (string-append (assoc-ref outputs "out")
+                                            "/lib")))))
+         #:tests? ,(%current-target-system)
+         #:test-command '("make" "test" "EMACS=emacs")))
+      (inputs (list sqlite))
+      (native-inputs (list python sed))
+      (home-page "https://github.com/pekingduck/emacs-sqlite3-api")
+      (synopsis "SQLite dynamic module for Emacs Lisp")
+      (description "This package provides a dynamic module for Emacs that allows
+direct access to the SQLite C interface.  It only exposes a subset of the full
+SQLite C interface, but should satisfy most user's needs.")
+      (license license:gpl3+))))
+
 (define-public emacs-sr-speedbar
   (let ((commit "77a83fb50f763a465c021eca7343243f465b4a47")
         (revision "0"))
-- 
2.34.0