Subject: [bug#49946] [PATCH 07/31] gnu: Add tree-sitter.

From: Pierre Langlois <[email-masked]>
Date: Fri, 13 Aug 2021 14:17:17 +0100

Pierre Langlois <[email-masked]> writes:

> * gnu/packages/tree-sitter.scm: New file.
> * gnu/local.mk (GNU_SYSTEM_MODULES): Register it.
> ---
>  gnu/local.mk                 |  1 +
>  gnu/packages/tree-sitter.scm | 98 ++++++++++++++++++++++++++++++++++++
>  2 files changed, 99 insertions(+)
>  create mode 100644 gnu/packages/tree-sitter.scm
>
> diff --git a/gnu/local.mk b/gnu/local.mk
> index 3f09b167b1..3763df0821 100644
> --- a/gnu/local.mk
> +++ b/gnu/local.mk
> @@ -559,6 +559,7 @@ GNU_SYSTEM_MODULES =				\
>    %D%/packages/tls.scm				\
>    %D%/packages/tmux.scm				\
>    %D%/packages/tor.scm				\
> +  %D%/packages/tree-sitter.scm			\
>    %D%/packages/tv.scm				\
>    %D%/packages/uglifyjs.scm			\
>    %D%/packages/uml.scm				\
> diff --git a/gnu/packages/tree-sitter.scm b/gnu/packages/tree-sitter.scm
> new file mode 100644
> index 0000000000..2c749dc0a8
> --- /dev/null
> +++ b/gnu/packages/tree-sitter.scm
> @@ -0,0 +1,98 @@
> +;;; GNU Guix --- Functional package management for GNU
> +;;; Copyright © 2021 Pierre Langlois <[email-masked]>
> +;;;
> +;;; 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 <http://www.gnu.org/licenses/>.
> +
> +(define-module (gnu packages tree-sitter)
> +  #:use-module ((guix licenses) #:prefix license:)
> +  #:use-module (guix build-system cargo)
> +  #:use-module (guix git-download)
> +  #:use-module (guix packages)
> +  #:use-module (gnu packages crates-io)
> +  #:use-module (gnu packages crates-graphics))
> +
> +(define-public tree-sitter
> +  (package
> +    (name "tree-sitter")
> +    (version "0.19.5")
> +    (source
> +      (origin
> +        (method git-fetch)
> +        (uri (git-reference
> +              (url "https://github.com/tree-sitter/tree-sitter")
> +              (commit (string-append "v" version))))
> +        (file-name (git-file-name name version))
> +        (sha256
> +         (base32
> +          "1qmb0sva28zv6r3c3j7xs9pc8bpwwhkb9vxxndw2zbdn9wkvmbmn"))))
> +    (build-system cargo-build-system)

The tree-sitter package here both ships the `tree-sitter' command-line
program, written in Rust, and the runtime library, written in C.  I
think it would be better to split this into two packages, `tree-sitter'
for the runtime and `tree-sitter-cli` for the Rust program.

That way, a potential future Emacs will be able to link against
libtree-sitter *without* bringing in Rust as a hard dependency. I saw
that native tree-sitter support was being worked on on emacs-devel
list. One would still need Rust to actually use it, but at least it
remains an optional dependency.

Thanks,
Pierre