From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id +E03I6qY6GNWhgEAbAwnHQ (envelope-from ) for ; Sun, 12 Feb 2023 08:43:38 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id YJgMI6qY6GOqbgAAauVa8A (envelope-from ) for ; Sun, 12 Feb 2023 08:43:38 +0100 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 2185427BE for ; Sun, 12 Feb 2023 08:43:38 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pR70q-0007Hs-A8; Sun, 12 Feb 2023 02:43:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pR70o-0007He-Ge for guix-patches@gnu.org; Sun, 12 Feb 2023 02:43:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pR70o-0002Lg-6v for guix-patches@gnu.org; Sun, 12 Feb 2023 02:43:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pR70n-0006OF-Vv for guix-patches@gnu.org; Sun, 12 Feb 2023 02:43:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#49946] [PATCH v7 06/32] build-system: Add tree-sitter-build-system. Resent-From: Andrew Tropin Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 12 Feb 2023 07:43: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: Pierre Langlois , 49946@debbugs.gnu.org Cc: Pierre Langlois Received: via spool by 49946-submit@debbugs.gnu.org id=B49946.167618776224535 (code B ref 49946); Sun, 12 Feb 2023 07:43:01 +0000 Received: (at 49946) by debbugs.gnu.org; 12 Feb 2023 07:42:42 +0000 Received: from localhost ([127.0.0.1]:43933 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pR70T-0006Ne-9H for submit@debbugs.gnu.org; Sun, 12 Feb 2023 02:42:42 -0500 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:47889) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pR70O-0006NQ-Rh for 49946@debbugs.gnu.org; Sun, 12 Feb 2023 02:42:39 -0500 Received: (Authenticated sender: andrew@trop.in) by mail.gandi.net (Postfix) with ESMTPSA id 6F54620003; Sun, 12 Feb 2023 07:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop.in; s=gm1; t=1676187750; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FY63GfRrlSNdqIg692f9ZoPcfoFSssfzyhdKn/Pgpmw=; b=BcoGPhqcbNX7YCppQ2u2JolhZ/rv6H19ScuTQSWF4/8zMmc2YObjCc4p5WmiWJPFCHmycZ c19XG+CxjpeP2zCUmeVj/myC263JziCSj0MTzQFe/0ea81IRpM+D/zOTQvjUmvWjiMxrkF kzfcaCAjt7wkKRGq9k1b116HqjHLRho9ZjiTPKyZBBVpujboZVsxYzvtL47LPkJSfJA+SC V36QYtVV7mA6oyYX9sACsCejTJMmpLUt/4GSbacyxZcIyB+BTHT7Cn9vlkwl8efQ24DIIp PIkbXIEo421ZGrOEvSySv46iHnqDr9xv1O15h/dmBGC+9JAS8pfUJT2KYkap0w== From: Andrew Tropin In-Reply-To: <87r0xrcpei.fsf@gmx.com> References: <87mtfi63ut.fsf@gmx.com> <20221125012142.22579-1-pierre.langlois@gmx.com> <20221125012142.22579-7-pierre.langlois@gmx.com> <87r0xrcpei.fsf@gmx.com> Date: Sun, 12 Feb 2023 11:42:24 +0400 Message-ID: <87edqvfhy7.fsf@trop.in> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1676187818; a=rsa-sha256; cv=none; b=MpISMnkZ/3IZau9sSnrIqbVePGDJFMVESFvG6fnbkk7QfuXXBVuKszuQ4ox8ZpfPDO5jQN +AjsvEg/fnN9vY9MfoNi93FfOvXBXGW8yDvpIFDaEeUSVr4oB09Mpaa7jOtAIcTzZ4z3ur Tb0zShZvA36g/2pphpNnSaUgh6rxIDlC3oyz+3oYpojeMzM9Ltwns+Hii8eAFwaqBACtuH j6AJEocLPHC9yOjlLnDX93S6gtwlBw/1GdS/bApjC0b+jQHEf86j90GU9sm892QFF2Mvdh AdGN2i2/xfNP8PM9Mwh3qhT//Cx2ylVV1Kgq18yhy7aKop/PL2/nFrpcCW0Bvw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=trop.in header.s=gm1 header.b=BcoGPhqc; dmarc=none; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1676187818; 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=FY63GfRrlSNdqIg692f9ZoPcfoFSssfzyhdKn/Pgpmw=; b=QSQY0t45SkUKegWYnbnWu1iCIvXLR2BNOjxWSqKzMF5RHcrCj6Dtwqf9xzqIWUgx8eqq9x B+6V562Um8B7iRRfLD1VxNsjZCH+hDB7eIghaT18PmSQImrEknIeV2r0DIBceOLqYZL+eH iIEqoqL87pbcQdV8zYc7cRDTLpv0sJpOvxF27lhIOSvXGczK9MWa8gzdWPyTRrbK9Hiq5M 2JCXvIoA7IqRD+vs8guCji2cN5/q/6aQO3Yt1FpkCOtu0hN9SL053epCV/1Pu7vPOhs0p4 zX8TPio0e5/LawtaZ1HdBsH5WW2MhunpCCWNmlgZ4oWeCKNrjB12XGmk4bjXgw== Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=trop.in header.s=gm1 header.b=BcoGPhqc; dmarc=none; 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-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -1.32 X-Spam-Score: -1.32 X-Migadu-Queue-Id: 2185427BE X-TUID: Pz/0Xo08InwK --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 2022-11-25 01:57, Pierre Langlois wrote: > It appears this email is making it through, so here it is as an > attachment: > > From 4a3c1fff8460a03bfb7c1aada9863205cd6f22fd Mon Sep 17 00:00:00 2001 > From: Pierre Langlois > Date: Tue, 29 Mar 2022 20:13:34 +0100 > Subject: [PATCH v7 06/32] build-system: Add tree-sitter-build-system. > > * guix/build-system/tree-sitter.scm: New module. > * guix/build/tree-sitter-build-system.scm: Likewise. > * Makefile.am (MODULES): Add them. > * doc/guix.texi: Document it. > --- > Makefile.am | 2 + > doc/guix.texi | 21 ++- > guix/build-system/tree-sitter.scm | 190 ++++++++++++++++++++++++ > guix/build/tree-sitter-build-system.scm | 153 +++++++++++++++++++ > 4 files changed, 365 insertions(+), 1 deletion(-) > create mode 100644 guix/build-system/tree-sitter.scm > create mode 100644 guix/build/tree-sitter-build-system.scm > > diff --git a/Makefile.am b/Makefile.am > index c3af23b68e..a16c4fcd7e 100644 > --- a/Makefile.am > +++ b/Makefile.am > @@ -178,6 +178,7 @@ MODULES =3D \ > guix/build-system/ruby.scm \ > guix/build-system/scons.scm \ > guix/build-system/texlive.scm \ > + guix/build-system/tree-sitter.scm \ > guix/build-system/trivial.scm \ > guix/ftp-client.scm \ > guix/http-client.scm \ > @@ -234,6 +235,7 @@ MODULES =3D \ > guix/build/ruby-build-system.scm \ > guix/build/scons-build-system.scm \ > guix/build/texlive-build-system.scm \ > + guix/build/tree-sitter-build-system.scm \ > guix/build/waf-build-system.scm \ > guix/build/haskell-build-system.scm \ > guix/build/julia-build-system.scm \ > diff --git a/doc/guix.texi b/doc/guix.texi > index e547d469f4..4e997f7176 100644 > --- a/doc/guix.texi > +++ b/doc/guix.texi > @@ -79,7 +79,7 @@ Copyright @copyright{} 2020 Jack Hill@* > Copyright @copyright{} 2020 Naga Malleswari@* > Copyright @copyright{} 2020, 2021 Brice Waegeneire@* > Copyright @copyright{} 2020 R Veera Kumar@* > -Copyright @copyright{} 2020, 2021 Pierre Langlois@* > +Copyright @copyright{} 2020, 2021, 2022 Pierre Langlois@* > Copyright @copyright{} 2020 pinoaffe@* > Copyright @copyright{} 2020 Andr=C3=A9 Batista@* > Copyright @copyright{} 2020, 2021 Alexandru-Sergiu Marton@* > @@ -9732,6 +9732,25 @@ be specified with the @code{#:node} parameter whic= h defaults to > @code{node}. > @end defvr >=20=20 > +@defvr {Scheme Variable} tree-sitter-build-system > + > +This variable is exported by @code{(guix build-system tree-sitter)}. It > +implements procedures to compile grammars for the > +@url{https://tree-sitter.github.io/tree-sitter/, Tree-sitter} parsing > +library. It essentially runs @code{tree-sitter generate} to translate > +@code{grammar.js} grammars to JSON and then to C. Which it then > +compiles to native code. > + > +Tree-sitter packages may support multiple grammars, so this build system > +supports a @code{#:grammar-directories} keyword to specify a list of > +locations where a @code{grammar.js} file may be found. > + > +Grammars sometimes depend on each other, such as C++ depending on C and > +TypeScript depending on JavaScript. You may use inputs to declare such > +dependencies. > + > +@end defvr > + > Lastly, for packages that do not need anything as sophisticated, a > ``trivial'' build system is provided. It is trivial in the sense that > it provides basically no support: it does not pull any implicit inputs, > diff --git a/guix/build-system/tree-sitter.scm b/guix/build-system/tree-s= itter.scm > new file mode 100644 > index 0000000000..aeb96e3ef5 > --- /dev/null > +++ b/guix/build-system/tree-sitter.scm > @@ -0,0 +1,190 @@ > +;;; GNU Guix --- Functional package management for GNU > +;;; Copyright =C2=A9 2022 Pierre Langlois > +;;; > +;;; This file is part of GNU Guix. > +;;; > +;;; GNU Guix is free software; you can redistribute it and/or modify it > +;;; under the terms of the GNU General Public License as published by > +;;; the Free Software Foundation; either version 3 of the License, or (at > +;;; your option) any later version. > +;;; > +;;; GNU Guix is distributed in the hope that it will be useful, but > +;;; WITHOUT ANY WARRANTY; without even the implied warranty of > +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +;;; GNU General Public License for more details. > +;;; > +;;; You should have received a copy of the GNU General Public License > +;;; along with GNU Guix. If not, see . > + > +(define-module (guix build-system tree-sitter) > + #:use-module (guix store) > + #:use-module (guix utils) > + #:use-module (guix packages) > + #:use-module (guix gexp) > + #:use-module (guix monads) > + #:use-module (guix search-paths) > + #:use-module (guix build-system) > + #:use-module (guix build-system gnu) > + #:use-module (guix build-system node) > + #:use-module (ice-9 match) > + #:export (%tree-sitter-build-system-modules > + tree-sitter-build > + tree-sitter-build-system)) > + > +(define %tree-sitter-build-system-modules > + ;; Build-side modules imported by default. > + `((guix build tree-sitter-build-system) > + ,@%node-build-system-modules)) > + > +(define* (lower name > + #:key source inputs native-inputs outputs system target > + #:allow-other-keys > + #:rest arguments) > + "Return a bag for NAME from the given arguments." > + (define private-keywords > + `(#:inputs #:native-inputs #:outputs ,@(if target > + '() > + '(#:target)))) > + (define node > + (module-ref (resolve-interface '(gnu packages node)) > + 'node-lts)) > + (define tree-sitter > + (module-ref (resolve-interface '(gnu packages tree-sitter)) > + 'tree-sitter)) > + (define tree-sitter-cli > + (module-ref (resolve-interface '(gnu packages tree-sitter)) > + 'tree-sitter-cli)) > + ;; Grammars depend on each other via JS modules, which we package into= a > + ;; dedicated js output. > + (define grammar-inputs > + (map (match-lambda > + ((name package) > + `(,name ,package "js"))) > + inputs)) > + (bag > + (name name) > + (system system) (target target) > + (build-inputs `(,@(if source > + `(("source" ,source)) > + '()) > + ("node" ,node) > + ("tree-sitter-cli" ,tree-sitter-cli) > + ,@native-inputs > + ,@(if target '() grammar-inputs) > + ;; Keep the standard inputs of 'gnu-build-system'. > + ,@(if target > + (standard-cross-packages target 'host) > + '()) > + ,@(standard-packages))) > + (host-inputs `(("tree-sitter" ,tree-sitter) > + ,@(if target grammar-inputs '()))) > + ;; Keep the standard inputs of 'gnu-buid-system'. > + (target-inputs (if target > + (standard-cross-packages target 'target) > + '())) > + ;; XXX: this is a hack to get around issue #41569. > + (outputs (match outputs > + (("out") (cons "js" outputs)) > + (_ outputs))) > + (build (if target tree-sitter-cross-build tree-sitter-build)) > + (arguments (strip-keyword-arguments private-keywords arguments)))) > + > +(define* (tree-sitter-build name inputs > + #:key > + source > + (phases '%standard-phases) > + (grammar-directories '(".")) > + (tests? #t) > + (outputs '("out" "js")) > + (search-paths '()) > + (system (%current-system)) > + (guile #f) > + (imported-modules %tree-sitter-build-system-= modules) > + (modules '((guix build utils) > + (guix build tree-sitter-build-sys= tem)))) > + (define builder > + (with-imported-modules imported-modules > + #~(begin > + (use-modules #$@(sexp->gexp modules)) > + (tree-sitter-build #:name #$name > + #:source #+source > + #:system #$system > + #:phases #$phases > + #:tests? #$tests? > + #:grammar-directories '#$grammar-directories > + #:outputs #$(outputs->gexp outputs) > + #:search-paths '#$(sexp->gexp > + (map search-path-specifi= cation->sexp > + search-paths)) > + #:inputs #$(input-tuples->gexp inputs))))) > + > + (mlet %store-monad ((guile (package->derivation (or guile (default-gui= le)) > + system #:graft? #f))) > + (gexp->derivation name builder > + #:system system > + #:guile-for-build guile))) > + > +(define* (tree-sitter-cross-build name > + #:key > + target > + build-inputs target-inputs host-inputs > + guile source > + (phases '%standard-phases) > + (grammar-directories '(".")) > + (tests? #t) > + (outputs '("out" "js")) > + (search-paths '()) > + (native-search-paths '()) > + (system (%current-system)) > + (build (nix-system->gnu-triplet system= )) > + (imported-modules %tree-sitter-build-s= ystem-modules) > + (modules '((guix build utils) > + (guix build tree-sitter-bui= ld-system)))) > + (define builder > + (with-imported-modules imported-modules > + #~(begin > + (use-modules #$@(sexp->gexp modules)) > + > + (define %build-host-inputs > + #+(input-tuples->gexp build-inputs)) > + > + (define %build-target-inputs > + (append #$(input-tuples->gexp host-inputs) > + #+(input-tuples->gexp target-inputs))) > + > + (define %build-inputs > + (append %build-host-inputs %build-target-inputs)) > + > + (tree-sitter-build #:name #$name > + #:source #+source > + #:system #$system > + #:build #$build > + #:target #$target > + #:phases #$phases > + #:tests? #$tests? > + #:grammar-directories '#$grammar-directories > + #:outputs #$(outputs->gexp outputs) > + #:inputs %build-target-inputs > + #:native-inputs %build-host-inputs > + #:search-paths '#$(sexp->gexp > + (map search-path-specifi= cation->sexp > + search-paths)) > + #:native-search-paths '#$(sexp->gexp > + (map > + search-path-spec= ification->sexp > + native-search-pa= ths)))))) > + > + (mlet %store-monad ((guile (package->derivation (or guile (default-gui= le)) > + system #:graft? #f))) > + (gexp->derivation name builder > + #:system system > + #:target target > + #:guile-for-build guile))) > + > +(define tree-sitter-build-system > + (build-system > + (name 'tree-sitter) > + (description "The Tree-sitter grammar build system") > + (lower lower))) > + > +;;; tree-sitter.scm ends here > diff --git a/guix/build/tree-sitter-build-system.scm b/guix/build/tree-si= tter-build-system.scm > new file mode 100644 > index 0000000000..574b0f2a1c > --- /dev/null > +++ b/guix/build/tree-sitter-build-system.scm > @@ -0,0 +1,153 @@ > +;;; GNU Guix --- Functional package management for GNU > +;;; Copyright =C2=A9 2022 Pierre Langlois > +;;; > +;;; This file is part of GNU Guix. > +;;; > +;;; GNU Guix is free software; you can redistribute it and/or modify it > +;;; under the terms of the GNU General Public License as published by > +;;; the Free Software Foundation; either version 3 of the License, or (at > +;;; your option) any later version. > +;;; > +;;; GNU Guix is distributed in the hope that it will be useful, but > +;;; WITHOUT ANY WARRANTY; without even the implied warranty of > +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +;;; GNU General Public License for more details. > +;;; > +;;; You should have received a copy of the GNU General Public License > +;;; along with GNU Guix. If not, see . > + > +(define-module (guix build tree-sitter-build-system) > + #:use-module ((guix build node-build-system) #:prefix node:) > + #:use-module (guix build json) > + #:use-module (guix build utils) > + #:use-module (ice-9 match) > + #:use-module (ice-9 regex) > + #:use-module (srfi srfi-1) > + #:export (%standard-phases > + tree-sitter-build)) > + > +;; Commentary: > +;; > +;; Build procedures for tree-sitter grammar packages. This is the > +;; builder-side code, which builds on top fo the node build-system. > +;; > +;; Tree-sitter grammars are written in JavaScript and compiled to a nati= ve > +;; shared object. The `tree-sitter generate' command invokes `node' in = order > +;; to evaluate the grammar.js into a grammar.json file, which is then > +;; translated into C code. We then compile the C code ourselves. Packa= ges > +;; also sometimes add extra manually written C/C++ code. > +;; > +;; In order to support grammars depending on each other, such as C and C= ++, > +;; JavaScript and TypeScript, this build-system installs the source of t= he > +;; node module in a dedicated "js" output. > +;; > +;; Code: > + > +(define* (patch-dependencies #:key inputs #:allow-other-keys) > + "Rewrite dependencies in 'package.json'. We remove all runtime depend= encies > +and replace development dependencies with tree-sitter grammar node modul= es." > + > + (define (rewrite package.json) > + (map (match-lambda > + (("dependencies" @ . _) > + '("dependencies" @)) > + (("devDependencies" @ . _) > + `("devDependencies" @ > + ,@(filter-map (match-lambda > + ((key . directory) > + (let ((node-module > + (string-append directory > + "/lib/node_modules/" > + key))) > + (and (directory-exists? node-module) > + `(,key . ,node-module))))) > + (alist-delete "node" inputs)))) > + (other other)) > + package.json)) > + > + (node:with-atomic-json-file-replacement "package.json" > + (match-lambda > + (('@ . package.json) > + (cons '@ (rewrite package.json)))))) > + > +;; FIXME: The node build-system's configure phase does not support > +;; cross-compiling so we re-define it. > +(define* (configure #:key native-inputs inputs #:allow-other-keys) > + (invoke (search-input-file (or native-inputs inputs) "/bin/npm") > + "--offline" "--ignore-scripts" "install")) > + > +(define* (build #:key grammar-directories #:allow-other-keys) > + (for-each (lambda (dir) > + (with-directory-excursion dir > + ;; Avoid generating binding code for other languages, we= do > + ;; not support this use-case yet and it relies on running > + ;; `node-gyp' to build native addons. > + (invoke "tree-sitter" "generate" "--no-bindings"))) > + grammar-directories)) > + > +(define* (check #:key grammar-directories tests? #:allow-other-keys) > + (when tests? > + (for-each (lambda (dir) > + (with-directory-excursion dir > + (invoke "tree-sitter" "test"))) > + grammar-directories))) > + > +(define* (install #:key target grammar-directories outputs #:allow-other= -keys) > + (let ((lib (string-append (assoc-ref outputs "out") > + "/lib/tree-sitter"))) > + (mkdir-p lib) > + (define (compile-language dir) > + (with-directory-excursion dir > + (let ((lang (assoc-ref (call-with-input-file "src/grammar.json" > + read-json) > + "name")) > + (source-file (lambda (path) > + (if (file-exists? path) > + path > + #f)))) > + (apply invoke > + `(,(if target > + (string-append target "-g++") > + "g++") > + "-shared" > + "-fPIC" > + "-fno-exceptions" > + "-O2" > + "-g" > + "-o" ,(string-append lib "/" lang ".so") > + ;; An additional `scanner.{c,cc}' file is sometimes > + ;; provided. > + ,@(cond > + ((source-file "src/scanner.c") > + =3D> (lambda (file) (list "-xc" "-std=3Dc99" file= ))) > + ((source-file "src/scanner.cc") > + =3D> (lambda (file) (list file))) > + (else '())) > + "-xc" "src/parser.c"))))) > + (for-each compile-language grammar-directories))) > + > +(define* (install-js #:key native-inputs inputs outputs #:allow-other-ke= ys) > + (invoke (search-input-file (or native-inputs inputs) "/bin/npm") > + "--prefix" (assoc-ref outputs "js") > + "--global" > + "--offline" > + "--loglevel" "info" > + "--production" > + ;; Skip scripts to prevent building bindings via GYP. > + "--ignore-scripts" > + "install" "../package.tgz")) > + > +(define %standard-phases > + (modify-phases node:%standard-phases > + (replace 'patch-dependencies patch-dependencies) > + (replace 'configure configure) > + (replace 'build build) > + (replace 'check check) > + (replace 'install install) > + (add-after 'install 'install-js install-js))) > + > +(define* (tree-sitter-build #:key inputs (phases %standard-phases) > + #:allow-other-keys #:rest args) > + (apply node:node-build #:inputs inputs #:phases phases args)) > + > +;;; tree-sitter-build-system.scm ends here Applied, slightly reformatted, pushed as dbd4d2d0707b486f1e2c8659e94e1d3b15e4351e Also, migrated tree-sitter-grammar fn to this build system. I still try to get the taste of packaging grammars with tree-sitter-grammar helper and just as plain packages and try to understand how good/bad template function idea is in this case and if we want to keep it or not. =2D-=20 Best regards, Andrew Tropin --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmPomGAACgkQIgjSCVjB 3rBNCg/+MLQ2JZC58PmhThF3IiJ8y2w/elM/me0Nlr1MT47sR7+y3lYAvSDSy8fN Sl0KEgobI3VhXieJysH0WQAlh7+f2JnVrr4kFOG6Gw2VSKIW2/EjaBdIKgYbf4Tc VkTd+vi6m1WuJj+rYG+CwdmnQpnXTMYa9tMhV2aNA7H+v/RyXuxbFWzz+6XUuIi0 BIXNt/3X+TqtdaH4c/WkZFOSFrWsJh2k9bj6w/rKDumKD7EdyVDlI6nR0COkD1Ua Datz/POOcruXrj/EYqBas4phSOHWmP9uxkIv6mA/6+7yxS6jKEagTBJyUtRSQXPJ NQombe3oEZQWBhxSyQTSjbUL0FmQYKBjF5SBCV6xWK9Hbis1HiaAhUNsQaauazzl n6GN4pH8kkAAAmdTn97Q0gJKZTr0dUCVkJfIxCJq2FLK9qqn1F7zAVDuNcA2Z3ga ylu38/ue92e5MlFO3rgUpP8TcwvXs2uahWdMkqjglCXPcXq3YytMb9KN/ihFN/VV OQW4ul4a/6P0sHGYfCUwipGEEr+OD9p20aK0eH/fRNy/YbZ9rms15FBgZ+fecknr qrmJnQgcA9jC2rA0ieNB6UcDDxdtDxU8ieeePZbnYWoK9TaMQtAm8+xwQjFVG4wl u56wQZN9vEphzPoqAPk5HsTL766UAGetQeQBy1x7sRmn3MAfjMo= =uq1j -----END PGP SIGNATURE----- --=-=-=--