From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id WA+JKP5KWGFF1wAAgWs5BA (envelope-from ) for ; Sat, 02 Oct 2021 14:05:18 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id oJIhJP5KWGHBTQAAbx9fmQ (envelope-from ) for ; Sat, 02 Oct 2021 12:05:18 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 35AFC2ED6C for ; Sat, 2 Oct 2021 14:05:18 +0200 (CEST) Received: from localhost ([::1]:52890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWdlU-0000hK-Q5 for larch@yhetil.org; Sat, 02 Oct 2021 08:05:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55158) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWdlG-0000gw-9P for guix-patches@gnu.org; Sat, 02 Oct 2021 08:05:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:46592) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mWdlG-0004d6-0i for guix-patches@gnu.org; Sat, 02 Oct 2021 08:05:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mWdlF-00009d-S1 for guix-patches@gnu.org; Sat, 02 Oct 2021 08:05:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49946] [PATCH 3/3] guix: node-build-system: Support compiling addons with node-gyp. Resent-From: Pierre Langlois Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 02 Oct 2021 12:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49946 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Philip McGrath Cc: Pierre Langlois , 49946@debbugs.gnu.org, Maxime Devos Received: via spool by 49946-submit@debbugs.gnu.org id=B49946.1633176277559 (code B ref 49946); Sat, 02 Oct 2021 12:05:01 +0000 Received: (at 49946) by debbugs.gnu.org; 2 Oct 2021 12:04:37 +0000 Received: from localhost ([127.0.0.1]:58138 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mWdko-00008t-2o for submit@debbugs.gnu.org; Sat, 02 Oct 2021 08:04:37 -0400 Received: from mout.gmx.net ([212.227.17.21]:54101) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mWdkk-00008X-Fu for 49946@debbugs.gnu.org; Sat, 02 Oct 2021 08:04:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1633176260; bh=OcSuNLVM72fX25kvZ1+7oeoalAWe5WjD7StfiN7HVvs=; h=X-UI-Sender-Class:References:From:To:Cc:Subject:Date:In-reply-to; b=PGZSofT2kjgn1ffCgYuLCRe+Rn7Gu/+/YbcoU6RffRKJicJ8iphFmti5koXsBX7fu 5QilC7o2jQ2wjRsTEvYz889b765FNf2cMSN5yGiWwzKc8DriBf+7f+ceWA0q5yq9ek A5NL4Y0ODoPc9m1ZGBiF9oQsmloeyLhZuhEGFTv8= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from labiere ([82.69.64.142]) by mail.gmx.net (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1M8ykg-1mTuSo2Vdu-0069wM; Sat, 02 Oct 2021 14:04:20 +0200 References: <682f2ed3-90bd-a9f8-1193-34bef399ca62@philipmcgrath.com> <87h7fztt60.fsf@gmx.com> <20210808233354.6745-1-pierre.langlois@gmx.com> <20210808233354.6745-8-pierre.langlois@gmx.com> <42e10baddb6afe308f67c3240bf5da8159e6f118.camel@telenet.be> <87o88gq5p5.fsf@gmx.com> <20210930225611.2143194-1-philip@philipmcgrath.com> <20210930225611.2143194-4-philip@philipmcgrath.com> User-agent: mu4e 1.6.6; emacs 27.2 From: Pierre Langlois Date: Sat, 02 Oct 2021 12:49:48 +0100 In-reply-to: <20210930225611.2143194-4-philip@philipmcgrath.com> Message-ID: <878rzbtyyn.fsf@gmx.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-Provags-ID: V03:K1:v3jtw7jU3Iwa0+4ogZ5xTC13Qlh/+2DI1Qxd29bFNTPDav6XLmp XBTbkUPdV/twqiFzDdPIvcvIUhwwIUR3ipn8dp0tX2TJD9jZ9yXjhJeaVDhSMjg2D3DQBtq EeKJWez3x0w9vI7YBIvbc+S6gqYOu1QV6RjU/8OF81oD+HMQaVYSJl1kWXcAN6mbrlrJIYo tr4Mt7PPOTlWtSqVi20fg== X-UI-Out-Filterresults: notjunk:1;V03:K0:NMvJHMQYJ/c=:6jvWTScM5NR+RVkulNq8mS EhhXTVwc5/+IP0f3CRQvWfk+gReFPIJo3c41swRWpA7stOGrge/dIsumPAspc6GRrA6OlmVP2 ff4mGniJkieGHTmFxwG7Q2tK1rnWV2XtvH54t7z9eBRqNBU87Mvc0UcEjamYVnTiNu5SwoDXg C8WsQNEK7mquhB+HZmupI6+zKQp//2F3ICEydt0Y0FGa7HRrcq7xJzJ09xhklsj1wjbEp7dan aX1dl3hP9+IGyy2cESXxXOepzIn4l7xD6FurAHQBiHMLymfeBGdkyLM1hA6IyP/1C7HJx52s/ Cd3mCUuiWRIXN5sdM3dZasdiLFraJo/Qsy+I49eeLqPDpR/kfDgmRbKJJSEkLpglhvqnBFXUW zYSKOAJmezXJrg0n5A9iZpppeq9uWf+Wc7wViEMG0C3jFrBLLOrIzNKnBjn+Y82tRAo/HemhO CjFJMU8GgzWKQ1oJsi2L5klRUSwairYmwxHq99/mZ6yq793PVohpDZrpkdCtiJB8uxs69Akwi JdxqiykRKazdzlJB4fqkKcrYAcoZe3H+eaDz8QmQpzuhl3pLFXhHzL48X6YSH7oyzrfTl7g+M wNTJwVeMkwOpCM1RcT/YCOLFRlM1G/jlaYYpKwaR6CC37DJ5MQm9XUelT3Hf/7gUtXAMlDAWl ft94bHsFCIaFS221VEHEG/DSLOcJmwnY1Oo4i6hGOQLQ5XoLfOeOhpJ0pV3nvdkDMeLwrYd6L +vYIG9jKm7AwhT+pK6vYMDngY+1tCOIMZlh0U/HMmzPvp7lvUsXzccJHeyuSvusJdjIEYitz1 0d4OZnlDrv/1KGtOKp4GsvxBZbT+CzE38sqMjtup/xDS3rM5GnS4p9Kf3MRJuqzanOnX3Whh3 00tu6XbaqvFnRI+nCH3cyKYl7rGSq0wsJlwnhOnIOqeEsgn6DWonmbPWku9IaZb5zh9r3V/k2 +vG3kqc/xZLQCGKD6SnqRGWVmtbXdGHuzmTMEW35Kc9+aioqVn4VZpzZRgrP3lOWyVMltBrXL t+/59BsC0d9296dn7udWP56bTvw9+L3UKThoRt0jyebhQOpHPbiKB6t0Bwe2mjOncVFv22qUX XmVoVk+LWnEKjY= 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1633176318; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=MHUOkcVCpiPrQvNNyAFSkisfHdFP8Ixg9gze7qqK+cw=; b=Qvb3UCaCisVhlhhCm/IV2qPCZDu/68wT1/Ls53i90HWBvNHSOP7AmQqBpeDlAILjfYzSkT v4gfuBfq+BWGjj8RKMe8MVftTy4OBoXxn7TFIpUeJoWvjaAwatifcF6bglW0NpeJMKK7yE W1KR1TCUPZntORmpVK3WZ+58zMih3LoBN3Hnw1jQPegbcCKB7UjsL4mIZZWq28S/qGWYrt znKYicKwdGOP3/zgqd7vvGAAyCYL2km0quXhXWEGk3suu3u79YrjE/IDmGxBtG3vrzKJXC XqAxWdgsFiuTx3z/KAxXxWu9BwNI/+q++meq3M6aPJQbKnpVIEtbxbHP1Pl8bw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1633176318; a=rsa-sha256; cv=none; b=KD6E2kL4B+jHmuQlbBngcsXQNNcs2wn/5ifkxuGKaBqUmUXLEqkQ7NEkLD78XH0JR21+fE ChfSNzI9zSS5BTyGzjqWmDXqcWrzuunjuq9fOeLFh61kBGyTnoeRkT962g09R8Vg3ZaKfW nrdU0FWjo7OiXnnBQWIL0yrXnT/lgoCIEFto6lHO1qh/foo/sfkdIiVFO8DfDA5nchlL1S DzKHwok0FCPuhK59gvzFNrTYtb/Y+lX1U0NqshS7c2JXyFU/yh79hzze9KqJsTmKcGuw3Z vv8v+ty2l+l3x5Rwc578T3kO/U5rWBzJqPyenpwAF252Hgap3e7KWOkq5uG1IA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmx.net header.s=badeba3b8450 header.b=PGZSofT2; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmx.com (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -3.81 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmx.net header.s=badeba3b8450 header.b=PGZSofT2; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmx.com (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 35AFC2ED6C X-Spam-Score: -3.81 X-Migadu-Scanner: scn1.migadu.com X-TUID: rUXAJD5fxrX3 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Philip McGrath writes: > * gnu/packages/node.scm (node)[arguments]: Replace 'patch-npm-shebang > and 'patch-node-shebang with a new 'patch-nested-shebangs that also > handles node-gyp and other shebangs under "/lib/node_modules". > [inputs]: Add Python for node-gyp as "python-for-target". > (node-lts)[inputs]: Likewise. > * guix/build-system/node.scm (lower): Add optional #:python argument. > * guix/build/node-build-system.scm (set-node-gyp-paths): New > function. Sets the "npm_config_nodedir" and "npm_config_python" > environment variables. > (%standard-phases): Add 'set-node-gyp-paths after 'set-paths. Nice! I'll test this with the tree-sitter series. I just had one comment inline, otherwise it looks good to me. Do you want me to integrate it into the tree-sitter series or submit it separately? It might make its way upstream quicker separately, in which case I'd suggest to send it again in a new bug for more visibility. > > Co-authored-by: Pierre Langlois > --- > gnu/packages/node.scm | 33 +++++++++++++++++--------------- > guix/build-system/node.scm | 7 ++++++- > guix/build/node-build-system.scm | 9 +++++++++ > 3 files changed, 33 insertions(+), 16 deletions(-) > > diff --git a/gnu/packages/node.scm b/gnu/packages/node.scm > index 6d9c3ccc71..805a4f18fc 100644 > --- a/gnu/packages/node.scm > +++ b/gnu/packages/node.scm > @@ -244,21 +244,22 @@ > python > (string-append python "3"))) > "configure" flags)))) > - (add-after 'patch-shebangs 'patch-npm-shebang > - (lambda* (#:key outputs #:allow-other-keys) > - (let* ((bindir (string-append (assoc-ref outputs "out") > - "/bin")) > - (npm (string-append bindir "/npm")) > - (target (readlink npm))) > - (with-directory-excursion bindir > - (patch-shebang target (list bindir)))))) > - (add-after 'install 'patch-node-shebang > - (lambda* (#:key outputs #:allow-other-keys) > - (let* ((bindir (string-append (assoc-ref outputs "out") > - "/bin")) > - (npx (readlink (string-append bindir "/npx")))) > - (with-directory-excursion bindir > - (patch-shebang npx (list bindir))))))))) > + (add-after 'patch-shebangs 'patch-nested-shebangs > + (lambda* (#:key inputs outputs #:allow-other-keys) > + (let* ((prefix (assoc-ref outputs "out")) > + (path (map (lambda (dir) > + (string-append dir "/bin")) > + (list prefix > + (assoc-ref inputs "python-for-targe= t"))))) > + (with-directory-excursion (string-append prefix "/lib/nod= e_modules") > + (for-each > + (lambda (file) > + (patch-shebang file path)) > + (find-files "." > + (lambda (file stat) > + (and (eq? 'regular (stat:type stat)) > + (not (zero? (logand (stat:mode stat= ) #o100))))) > + #:stat lstat))))))))) Here you don't necessarily need with-directory-excursion. I see we also have a executable-file? predicate function in (guix build utils), could we use that? i.e: (for-each (lambda (file) (patch-shebang file path)) (find-files (string-append prefix "/lib/node_modules") executable-file?= )) > (native-inputs > `(;; Runtime dependencies for binaries used as a bootstrap. > ("c-ares" ,c-ares) > @@ -281,6 +282,7 @@ > (inputs > `(("bash" ,bash-minimal) > ("coreutils" ,coreutils) > + ("python-for-target" ,python-wrapper) ;; for node-gyp (supports p= ython3) > ("c-ares" ,c-ares) > ("http-parser" ,http-parser) > ("icu4c" ,icu4c) > @@ -764,6 +766,7 @@ source files.") > (inputs > `(("bash" ,bash-minimal) > ("coreutils" ,coreutils) > + ("python-for-target" ,python-wrapper) ;; for node-gyp (supports p= ython3) > ("c-ares" ,c-ares) > ("icu4c" ,icu4c-67) > ("libuv" ,libuv-for-node) > diff --git a/guix/build-system/node.scm b/guix/build-system/node.scm > index 98f63f87ef..3e49e67ff6 100644 > --- a/guix/build-system/node.scm > +++ b/guix/build-system/node.scm > @@ -1,6 +1,8 @@ > ;;; GNU Guix --- Functional package management for GNU > ;;; Copyright =C2=A9 2016 Jelle Licht > ;;; Copyright =C2=A9 2019 Timothy Sample > +;;; Copyright =C2=A9 2021 Pierre Langlois > +;;; Copyright =C2=A9 2021 Philip McGrath > ;;; > ;;; This file is part of GNU Guix. > ;;; > @@ -24,6 +26,7 @@ > #:use-module (guix search-paths) > #:use-module (guix build-system) > #:use-module (guix build-system gnu) > + #:use-module (guix build-system python) > #:use-module (ice-9 match) > #:export (%node-build-system-modules > node-build > @@ -44,11 +47,12 @@ > (define* (lower name > #:key source inputs native-inputs outputs system target > (node (default-node)) > + (python (default-python)) ;; for node-gyp > #:allow-other-keys > #:rest arguments) > "Return a bag for NAME." > (define private-keywords > - '(#:source #:target #:node #:inputs #:native-inputs)) > + '(#:source #:target #:node #:python #:inputs #:native-inputs)) >=20=20 > (and (not target) ;XXX: no cross-compilation > (bag > @@ -62,6 +66,7 @@ > ;; Keep the standard inputs of 'gnu-build-system= '. > ,@(standard-packages))) > (build-inputs `(("node" ,node) > + ("python" ,python) > ,@native-inputs)) > (outputs outputs) > (build node-build) > diff --git a/guix/build/node-build-system.scm b/guix/build/node-build-sys= tem.scm > index 70a367618e..5e62eb4784 100644 > --- a/guix/build/node-build-system.scm > +++ b/guix/build/node-build-system.scm > @@ -2,6 +2,8 @@ > ;;; Copyright =C2=A9 2015 David Thompson > ;;; Copyright =C2=A9 2016, 2020 Jelle Licht > ;;; Copyright =C2=A9 2019, 2021 Timothy Sample > +;;; Copyright =C2=A9 2021 Pierre Langlois > +;;; Copyright =C2=A9 2021 Philip McGrath > ;;; > ;;; This file is part of GNU Guix. > ;;; > @@ -46,6 +48,12 @@ > (format #t "set HOME to ~s~%" (getenv "HOME"))))))) > #t) >=20=20 > +(define* (set-node-gyp-paths #:key inputs #:allow-other-keys) > + "Initialize environment variables needed for building native addons." > + (setenv "npm_config_nodedir" (assoc-ref inputs "node")) > + (setenv "npm_config_python" (assoc-ref inputs "python")) > + #t) > + > (define (module-name module) > (let* ((package.json (string-append module "/package.json")) > (package-meta (call-with-input-file package.json read-json))) > @@ -144,6 +152,7 @@ >=20=20 > (define %standard-phases > (modify-phases gnu:%standard-phases > + (add-after 'set-paths 'set-node-gyp-paths set-node-gyp-paths) > (add-after 'unpack 'set-home set-home) > (add-before 'configure 'patch-dependencies patch-dependencies) > (replace 'configure configure) The build system changes are now so nice and simple :-). I guess we don't really need to set npm_config_python, it should be able to find python in the PATH, but it doesn't hurt. Thanks, Pierre --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQFMBAEBCgA2FiEEctU9gYy29KFyWDdMqPyeRH9PfVQFAmFYSsAYHHBpZXJyZS5s YW5nbG9pc0BnbXguY29tAAoJEKj8nkR/T31UbGwIAIkzKPG7t2Zzpwiq6OpznueP jnWlHc9SSX470xck1bwv7Gf06J84rIh523jkmiMGCiPN0vz2/KXj1FZIB6ykcJfr lXUfBu7gEWclAa8ilV2CwJHv1Xrn5oDXUPFdLxnmnUQtPaGKC7rwqWeNeHA6/oX3 rGLCN/5PiL3sM86Fym6sealM8t8wAIRU1SwyBr2JFthoAH5O5Dvol2Mtsv1Tckzh LvQWIg0KR+l0/sogj2YHSnhqvXemnK1icBR4hxD/5quBqpiCvH1j5Qh+1ogcKq4A WVvabJYzc3GQoLLuJTWtNEvIRDZMite9Og75DWaopRbWQBR0Pual/aY1x5YIdRk= =R3ZV -----END PGP SIGNATURE----- --=-=-=--