From patchwork Mon Dec 13 06:00:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip McGrath X-Patchwork-Id: 35179 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 3DA6A27BBE9; Mon, 13 Dec 2021 06:06:10 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 9BFF127BBEA for ; Mon, 13 Dec 2021 06:06:08 +0000 (GMT) Received: from localhost ([::1]:45130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mweTP-0004yX-NQ for patchwork@mira.cbaines.net; Mon, 13 Dec 2021 01:06:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mweSR-0003el-DA for guix-patches@gnu.org; Mon, 13 Dec 2021 01:05:08 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:42273) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mweSP-0007ZB-I5 for guix-patches@gnu.org; Mon, 13 Dec 2021 01:05:07 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mweSP-0002dc-BZ for guix-patches@gnu.org; Mon, 13 Dec 2021 01:05:05 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51838] [PATCH v4 29/45] gnu: Add node-sqlite3. Resent-From: Philip McGrath Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 13 Dec 2021 06:05:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51838 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51838@debbugs.gnu.org Cc: Timothy Sample , Pierre Langlois , Jelle Licht , Philip McGrath , Liliana Marie Prikler Received: via spool by 51838-submit@debbugs.gnu.org id=B51838.16393754959996 (code B ref 51838); Mon, 13 Dec 2021 06:05:05 +0000 Received: (at 51838) by debbugs.gnu.org; 13 Dec 2021 06:04:55 +0000 Received: from localhost ([127.0.0.1]:53788 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mweRz-0002a3-VY for submit@debbugs.gnu.org; Mon, 13 Dec 2021 01:04:55 -0500 Received: from mail-ua1-f54.google.com ([209.85.222.54]:45627) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mweRj-0002Z7-QN for 51838@debbugs.gnu.org; Mon, 13 Dec 2021 01:04:24 -0500 Received: by mail-ua1-f54.google.com with SMTP id ay21so27252382uab.12 for <51838@debbugs.gnu.org>; Sun, 12 Dec 2021 22:04:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philipmcgrath.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4QlSe+2vPMDGTufcnOYGxZK20Lpc6crlgOBa5eFV5z4=; b=ELcx9hEyutAB1wHbWzyzTxR9N1oBQIqzkyBt5/jIT9odoG9hzK2RnJl9QH9FmWw8hL xZ1EwtxUJKvKBRxG0nP5Hw4nuNRjduZKZHJBOoRn4DWoiymjErn488n919k05Z3xWLTu XKPgA0wWPNfOty4PbA07+N8m1WNgE93x+QbT5ePYBEN/LMiEwOlD9/5P3eALX4d6xhvd +9ZLeV1Q9U1zJXOuiHr3AevpuDc0FcvMGxL5MpoKKAh7i47pgo4kMwwGClEwxj9f7NlV kVu71OUsaPhpa/PkcvNpSwdNkJik8mwhlRkne0PNu7SQ3FA/SfnpWi3j6c5jSzHb4mN/ dQ2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4QlSe+2vPMDGTufcnOYGxZK20Lpc6crlgOBa5eFV5z4=; b=IuIMc1W9HtCaaoCAzV3B65wApxXwaQXDV3iuh4IyoBOZ21fjUFF9jJV+CbLQnfvs6P AR41au3BIVDIkMiab+t4DQC0NgwyiIxyeW2vE8ncUrcCxKB2pfYpCaEe5xctTb+gkPV3 dLLcUEfYCd5wrlnv87xVVUeTBiwt+rg8xq0NEvj/m6MU8mLcokEAKIOHvJq0qvwA4Fab VL+sFSMN6yaui3+K+uusUl7xnDlRmh7e7D9YV1FuD78OrQ4qgiYecFRf3KgOODIuWzBj 4QowHkKg8HMvoEr73OuT3+EWFm7y+tGD4nAyrNmItKuuMWtZ0tpdTamtRvG64sgWOAXu gYyA== X-Gm-Message-State: AOAM532ejvnG8Z2wGj6Ga9N1PDXpYPcTh6g4xzSp2uAEdq4KU3wPKixo Kx8/D79P9xFK8Deb2Bg8LLoHQhUiMiBGzz+7buQ= X-Google-Smtp-Source: ABdhPJy+Ts/lrPhHTOiu0Q1WSKYXB0wXlHQ7GCSIBoDsg/e1EEXiu/jza/gNYXJXkpN+8M4+CYssYw== X-Received: by 2002:a67:e44e:: with SMTP id n14mr25859999vsm.55.1639375458411; Sun, 12 Dec 2021 22:04:18 -0800 (PST) Received: from localhost (c-73-125-89-242.hsd1.fl.comcast.net. [73.125.89.242]) by smtp.gmail.com with ESMTPSA id e13sm3694595vkd.21.2021.12.12.22.04.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Dec 2021 22:04:18 -0800 (PST) From: Philip McGrath Date: Mon, 13 Dec 2021 01:00:51 -0500 Message-Id: <20211213060107.129223-30-philip@philipmcgrath.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211213060107.129223-1-philip@philipmcgrath.com> References: <46a042bc08eb72a068b1e8c69bfe28cf2d4b2e53.camel@gmail.com> <20211208202838.752542-1-philip@philipmcgrath.com> <20211208202838.752542-5-philip@philipmcgrath.com> <877dc924h7.fsf@gmx.com> <5c62c3ce-dd50-5dcd-00ed-ff1524be4e0b@philipmcgrath.com> <20211213060107.129223-1-philip@philipmcgrath.com> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/packages/node-xyz.scm (node-sqlite3): New variable. --- gnu/packages/node-xyz.scm | 132 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/gnu/packages/node-xyz.scm b/gnu/packages/node-xyz.scm index c7bc660134..d1bb236186 100644 --- a/gnu/packages/node-xyz.scm +++ b/gnu/packages/node-xyz.scm @@ -655,3 +655,135 @@ (define-public node-addon-api @code{libuv} (included in a project via @code{#include }) are not ABI-stable across Node.js major versions.") (license license:expat))) + +(define-public node-sqlite3 + (package + (name "node-sqlite3") + (version "5.0.2") + (source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/mapbox/node-sqlite3") + (commit (string-append "v" version)))) + (file-name (git-file-name name version)) + (sha256 + (base32 "0sbbzzli282nxyfha10zx0k5m8hdp0sf3ipl59khjb7wm449j86h")) + (snippet + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils)) + ;; unbundle sqlite + (for-each delete-file-recursively + (find-files "deps" + (lambda (pth stat) + (gzip-file? pth))))))))) + (inputs + `(("node-addon-api" ,node-addon-api) + ("python" ,python) + ("sqlite" ,sqlite))) + (build-system node-build-system) + (arguments + `(#:tests? + #f ; FIXME: tests depend on node-mocha + #:modules + ((guix build node-build-system) + (guix build json) + (srfi srfi-1) + (ice-9 match) + (guix build utils)) + #:absent-dependencies + `(;; Normally, this is "built" using @mapbox/node-pre-gyp, + ;; which publishes or downloads pre-built binaries + ;; or falls back to building from source. + ;; Here, we patch out all of that and just build directly. + ;; It would be better to patch a version of @mapbox/node-pre-gyp + ;; that always builds from source, as Debian does, + ;; but there are a number of dependencies that need + ;; to be packaged or removed. + "@mapbox/node-pre-gyp" + "node-pre-gyp" ;; deprecated name still used in some places + "aws-sdk" + "@mapbox/cloudfriend" + ;; Confusingly, this is only a dependency because of + ;; @mapbox/node-pre-gyp: with that removed, + ;; npm will use its own copy: + "node-gyp" + ;; These we'd like, we just don't have them yet: + "eslint" + "mocha") + #:phases + (modify-phases %standard-phases + (add-before 'configure 'npm-config-sqlite + ;; We need this step even if we do replace @mapbox/node-pre-gyp + ;; because the package expects to build its bundled sqlite + (lambda* (#:key inputs #:allow-other-keys) + (setenv "npm_config_sqlite" (assoc-ref inputs "sqlite")))) + (add-after 'install 'patch-binding-path + ;; We replace a file that dynamic searches for the addon using + ;; node-pre-gyp (which we don't have) with a version that + ;; simply uses the path to the addon we built directly. + ;; The exact path is supposed to depend on things like the + ;; architecture and napi_build_version, so, to avoid having + ;; hard-code the details accurately, we do this after the addon + ;; has been built so we can just find where it ended up. + (lambda* (#:key outputs #:allow-other-keys) + (with-directory-excursion + (string-append (assoc-ref outputs "out") + "/lib/node_modules/sqlite3/lib") + (match (find-files "binding" "\\.node$") + ((rel-path) + (with-atomic-file-replacement "sqlite3-binding.js" + (lambda (in out) + (format out "var binding = require('./~a');\n" rel-path) + (display "module.exports = exports = binding;\n" out)))))))) + (add-after 'patch-dependencies 'avoid-node-pre-gyp + (lambda args + ;; We need to patch .npmignore before the 'repack phase + ;; so that the built addon is installed with in the package. + ;; (Upstream assumes node-pre-gyp will download a pre-built + ;; version when this package is installed.) + (substitute* ".npmignore" + (("lib/binding") + "#lib/binding # <- patched for Guix")) + ;; We need to remove the install script from "package.json", + ;; as it would try to use node-pre-gyp and would block the + ;; automatic building performed by `npm install`. + (with-atomic-file-replacement "package.json" + (lambda (in out) + (let* ((js (read-json in)) + (alist (match js + (('@ . alist) alist))) + (scripts-alist (match (assoc-ref alist "scripts") + (('@ . alist) alist))) + (scripts-alist + ;; install script would use node-pre-gyp + (assoc-remove! scripts-alist "install")) + (alist + (assoc-set! alist "scripts" (cons '@ scripts-alist))) + (binary-alist (match (assoc-ref alist "binary") + (('@ . alist) alist))) + (js (cons '@ alist))) + ;; When it builds from source, node-pre-gyp supplies + ;; module_name and module_path based on the entries under + ;; "binary" from "package.json", so this package's + ;; "binding.gyp" doesn't define them. Thus, we also need + ;; to supply them. The GYP_DEFINES environment variable + ;; turns out to be the easiest way to make sure they are + ;; propagated from npm to node-gyp to gyp. + (setenv "GYP_DEFINES" + (string-append + "module_name=" + (assoc-ref binary-alist "module_name") + " " + "module_path=" + (assoc-ref binary-alist "module_path"))) + (write-json js + out))))))))) + (home-page "https://github.com/mapbox/node-sqlite3") + (synopsis "Asynchronous, non-blocking SQLite3 bindings for Node.js") + (description + "The Node.js add-on @code{node-sqlite3} provides a set of a asynchronous, +non-blocking bindings for SQLite3, written in modern C++ and tested for memory +leaks.") + (license license:bsd-3)))