From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id GGEtDpIJkWGqYAAAgWs5BA (envelope-from ) for ; Sun, 14 Nov 2021 14:05:22 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id GB7oCZIJkWGjFAAA1q6Kng (envelope-from ) for ; Sun, 14 Nov 2021 13:05:22 +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 C1F4114145 for ; Sun, 14 Nov 2021 14:05:21 +0100 (CET) Received: from localhost ([::1]:51236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmFCC-000273-WF for larch@yhetil.org; Sun, 14 Nov 2021 08:05:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37826) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmFBu-00026A-Sf for guix-patches@gnu.org; Sun, 14 Nov 2021 08:05:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:37859) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mmFBu-000253-Jy for guix-patches@gnu.org; Sun, 14 Nov 2021 08:05:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mmFBu-0004zB-Fv for guix-patches@gnu.org; Sun, 14 Nov 2021 08:05:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51838] [PATCH 03/11] guix: node-build-system: Support compiling add-ons with node-gyp. Resent-From: Philip McGrath Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 14 Nov 2021 13:05:02 +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: Pierre Langlois , Philip McGrath Received: via spool by 51838-submit@debbugs.gnu.org id=B51838.163689509319132 (code B ref 51838); Sun, 14 Nov 2021 13:05:02 +0000 Received: (at 51838) by debbugs.gnu.org; 14 Nov 2021 13:04:53 +0000 Received: from localhost ([127.0.0.1]:49403 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmFBh-0004yT-TQ for submit@debbugs.gnu.org; Sun, 14 Nov 2021 08:04:53 -0500 Received: from mail-qt1-f179.google.com ([209.85.160.179]:42601) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmFBf-0004yB-HW for 51838@debbugs.gnu.org; Sun, 14 Nov 2021 08:04:48 -0500 Received: by mail-qt1-f179.google.com with SMTP id z9so12985814qtj.9 for <51838@debbugs.gnu.org>; Sun, 14 Nov 2021 05:04:47 -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=caZtV6CtWt9On14XOLrO/yexC0cfBS35X0odEutD4b4=; b=PXyrGqKLU4kjSbHixDkyVchzDrhSSKOWt+KWtETMcuY78Tvb83xaCbb0910BxbiUJK 17j+mN2u+Z/dLZAOG7icaqMFpYdb9ssbO/ThfEPmqbaMN0MWxNpOU+mttfYLjgTrhyF6 acGpQKz4zwn1ycqggi3kl5sd1HJmYLFTtpBRfTdd4WYMBIw5BYDTegDU8YxXXRWzItPJ 24MfnvAw76g8d0ecxPOBJJAbj/mhkQjwe7FChBZos5SXQwCk17czcN0WHS3MCGZTQ4rL ls2MpdKV/tjvDU4fKJpRk0Nbzm8Ewuy5Sbs+BJ0V0Y0L+W+ZLNl0/LSALogPIMMtHvpv ZzkQ== 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=caZtV6CtWt9On14XOLrO/yexC0cfBS35X0odEutD4b4=; b=kAw1JR6XS0+vuP0c274tWft/zrzBA0c+RWFgaQDQ229tZDb7jBFGgwbQlbLiQ5byPX +9d7bxiUf6iiU+qTCC+PosGLmLpStFP9RM4kfvPHElhRUN9ePrd2tvndDeMUcc6PTot1 ntXeiIKB5wut0ZFYanlXXNvzJ/J1CztswYsB/ETvZpGrjx8/QgCc4wds5U1X4iFlww68 dy/wNA36N6dcMsqu5eTETobbd4RpAh2dg2tHONhKFH6F5KOxMvJFxoIEhdeqRo7kcUf1 tvD/+SHwbko6wk8xyERP/q74oKyPKbQ7yLsAYbTFjfLwObG4JKv4k3qp0S9MQwWu9zyD Lfjg== X-Gm-Message-State: AOAM5330SvcERw2yFwPPNBKwMYW/VP9xgnkWfBowZvd/9OifZLtbDxna nakB+Imn51u67xesrUBKOpO2+mTieHnsmDAh X-Google-Smtp-Source: ABdhPJyIlnvXDJko1gERl+A2VYSbRGBNaAXRQZSpJEWEWBxBfGZJ/YQsmwCVdTEEV4XWSOGImyg+rA== X-Received: by 2002:a05:622a:391:: with SMTP id j17mr32919655qtx.228.1636895082018; Sun, 14 Nov 2021 05:04:42 -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 u10sm6275419qtx.3.2021.11.14.05.04.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 14 Nov 2021 05:04:41 -0800 (PST) From: Philip McGrath Date: Sun, 14 Nov 2021 08:04:01 -0500 Message-Id: <20211114130409.49241-2-philip@philipmcgrath.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211114130409.49241-1-philip@philipmcgrath.com> References: <20211114125830.45427-1-philip@philipmcgrath.com> <20211114130409.49241-1-philip@philipmcgrath.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1636895121; 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: content-transfer-encoding:content-transfer-encoding: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=caZtV6CtWt9On14XOLrO/yexC0cfBS35X0odEutD4b4=; b=FsQW/B4Za/AntoeWuInDKaPA/xPtAwCyY7COSJYK1GrNMwe66oblHaJ6Ly+FAnc+sxjC+w E1wEIoAzDxwColWBKO9gF4U4rhVzh2P0JOPn3lV/dshB7LR1J8am9SGM6Uz+6nGJhnnHBU 6Qsm+0WEo3HzR/iShSIOn3TYcLmKYl6lJV66TTFl7QuGPX2AKLCgV8zHeUMxJCGSRagx61 k9Ifs+WDA+dKpkN/oaOKuRRMijuHF95BLKkoIw4gDtgKFleM5e4Wy7Xl6XisMKcE2m4DRf LQUGikpZGG80p+jHe0X4uSEmv7iHeTYnHfXVV3lUbp4dOyiSwaI4wkK0YLD2mA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1636895121; a=rsa-sha256; cv=none; b=UMw6v7gibVLCZ8YaF7Z5FYKgxBrpFYj0VAEDIhVr0wsh1gBGHL9jGKHD/LZRLbjcIDwdQO L26SnyvJ+T2BpxK5wPdGs7C9omAFQT1WVJPxWmO7b2bnydPTKa5u05Jdqmb4jVlfCUvXH6 iqMBfTVjPFRBDLIklsPZS5wuFNNRFCIOVMRNdvf9F0JbIe4xneb3HMz6yHfuLkTPDfJEpQ 7LojQerSqvFDtvDgUcHuNCNdPBox2EsM9+kWcRDPa6WZIpjCjLOk+qyftypQqBvtWTnV9D ALpZUbBHvPOL+Rq825fKtgtUMiZ9Pu+eDsZe04q1I0BqKvar7iTHgRLHVOsR5A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b=PXyrGqKL; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -0.84 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b=PXyrGqKL; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: C1F4114145 X-Spam-Score: -0.84 X-Migadu-Scanner: scn0.migadu.com X-TUID: 2YNYyNohCz1H * 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. (libnode)[arguments]: Adjust to delete 'patch-nested-shebangs rather than 'patch-npm-shebang and 'patch-node-shebang. * guix/build-system/node.scm (lower): Add optional #:python argument and corresponding implicit input. Add the version of libuv used as an input to the #:node package as a new implicit input. * guix/build/node-build-system.scm (set-node-gyp-paths): New function. Sets the "npm_config_nodedir" and "npm_config_python" environment variables. Adds the "node-gyp-bin" directory to "PATH". (configure-gyp): New function. Run `node-gyp configure` if we see a `binding.gyp` file. (%standard-phases): Add 'set-node-gyp-paths after 'set-paths. Add 'configure-gyp after 'configure. Co-authored-by: Pierre Langlois --- gnu/packages/node.scm | 34 ++++++++++++++++---------------- guix/build-system/node.scm | 11 +++++++++-- guix/build/node-build-system.scm | 23 +++++++++++++++++++++ 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/gnu/packages/node.scm b/gnu/packages/node.scm index 89a9bc7533..ad5179426a 100644 --- a/gnu/packages/node.scm +++ b/gnu/packages/node.scm @@ -237,21 +237,20 @@ (define-public node 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-target"))))) + (for-each + (lambda (file) + (patch-shebang file path)) + (find-files (string-append prefix "/lib/node_modules") + (lambda (file stat) + (executable-file? file)) + #:stat lstat)))))))) (native-inputs `(;; Runtime dependencies for binaries used as a bootstrap. ("c-ares" ,c-ares) @@ -274,6 +273,7 @@ (define-public node (inputs `(("bash" ,bash-minimal) ("coreutils" ,coreutils) + ("python-for-target" ,python-wrapper) ;; for node-gyp (supports python3) ("c-ares" ,c-ares) ("http-parser" ,http-parser) ("icu4c" ,icu4c) @@ -795,6 +795,7 @@ (define-public node-lts (inputs `(("bash" ,bash-minimal) ("coreutils" ,coreutils) + ("python-for-target" ,python-wrapper) ;; for node-gyp (supports python3) ("c-ares" ,c-ares) ("icu4c" ,icu4c-67) ("libuv" ,libuv-for-node) @@ -813,5 +814,4 @@ (define-public libnode `(cons* "--shared" "--without-npm" ,flags)) ((#:phases phases '%standard-phases) `(modify-phases ,phases - (delete 'patch-npm-shebang) - (delete 'patch-node-shebang))))))) + (delete 'patch-nested-shebangs))))))) diff --git a/guix/build-system/node.scm b/guix/build-system/node.scm index 98f63f87ef..fee4142a99 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 © 2016 Jelle Licht ;;; Copyright © 2019 Timothy Sample +;;; Copyright © 2021 Pierre Langlois +;;; Copyright © 2021 Philip McGrath ;;; ;;; This file is part of GNU Guix. ;;; @@ -24,6 +26,7 @@ (define-module (guix build-system node) #: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 (default-node) (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)) (and (not target) ;XXX: no cross-compilation (bag @@ -58,10 +62,13 @@ (define private-keywords `(("source" ,source)) '()) ,@inputs - ;; Keep the standard inputs of 'gnu-build-system'. ,@(standard-packages))) (build-inputs `(("node" ,node) + ("python" ,python) + ;; We don't always need libuv, but the libuv and + ;; node versions need to match: + ("libuv" ,@(assoc-ref (package-inputs node) "libuv")) ,@native-inputs)) (outputs outputs) (build node-build) diff --git a/guix/build/node-build-system.scm b/guix/build/node-build-system.scm index 70a367618e..6aeb0149dd 100644 --- a/guix/build/node-build-system.scm +++ b/guix/build/node-build-system.scm @@ -2,6 +2,8 @@ ;;; Copyright © 2015 David Thompson ;;; Copyright © 2016, 2020 Jelle Licht ;;; Copyright © 2019, 2021 Timothy Sample +;;; Copyright © 2021 Pierre Langlois +;;; Copyright © 2021 Philip McGrath ;;; ;;; This file is part of GNU Guix. ;;; @@ -46,6 +48,19 @@ (define (set-home . _) (format #t "set HOME to ~s~%" (getenv "HOME"))))))) #t) +(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")) + (setenv "PATH" + (string-append (getenv "PATH") + ":" + ;; Put this at the end to make it easier to override, + ;; just in case that should ever be necessary: + (assoc-ref inputs "node") + "/lib/node_modules/npm/bin/node-gyp-bin")) + #t) + (define (module-name module) (let* ((package.json (string-append module "/package.json")) (package-meta (call-with-input-file package.json read-json))) @@ -101,6 +116,12 @@ (define* (configure #:key outputs inputs #:allow-other-keys) (invoke npm "--offline" "--ignore-scripts" "install") #t)) +(define* (configure-gyp #:key inputs #:allow-other-keys) + "Run 'node-gyp configure' if we see a 'binding.gyp' file." + (if (file-exists? "binding.gyp") + (invoke (which "node-gyp") "configure") + #t)) + (define* (build #:key inputs #:allow-other-keys) (let ((package-meta (call-with-input-file "package.json" read-json))) (if (and=> (assoc-ref package-meta "scripts") @@ -144,9 +165,11 @@ (define* (install #:key outputs inputs #:allow-other-keys) (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) + (add-after 'configure 'configure-gyp configure-gyp) (replace 'build build) (replace 'check check) (add-before 'install 'repack repack) -- 2.32.0