From 83fc3cf53a4b54a4ec3bf464cfea97f74522cd8d Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 21 Nov 2024 14:55:38 +0200 Subject: [PATCH] Future-proof loading tree-sitter library on MS-Windows * src/treesit.c (syms_of_treesit) : New internal variable. * lisp/term/w32-win.el (dynamic-library-alist): Use 'tree-sitter--library-abi' to select a proper libtree-sitter DLL version. --- lisp/term/w32-win.el | 14 ++++++++++++-- src/treesit.c | 11 +++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lisp/term/w32-win.el b/lisp/term/w32-win.el index 3c0acf368f4..2a59ec2460d 100644 --- a/lisp/term/w32-win.el +++ b/lisp/term/w32-win.el @@ -290,8 +290,18 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.") '(lcms2 "liblcms2-2.dll") '(gccjit "libgccjit-0.dll") ;; MSYS2 distributes libtree-sitter.dll, without API version - ;; number... - '(tree-sitter "libtree-sitter.dll" "libtree-sitter-0.dll"))) + ;; number, upto and including version 0.24.3-2; later versions + ;; come with libtree-sitter-major.minor.dll (as in + ;; libtree-sitter-0.24.dll). Sadly, the header files don't have + ;; any symbols for library version, so we can only use the + ;; library-language ABI version; according to + ;; https://github.com/tree-sitter/tree-sitter/issues/3925, the + ;; language ABI must change when the library's ABI is modified. + (if (<= tree-sitter--library-abi 14) + '(tree-sitter "libtree-sitter-0.24.dll" + "libtree-sitter.dll" + "libtree-sitter-0.dll") + '(tree-sitter "libtree-sitter-0.25.dll")))) ;;; multi-tty support (defvar w32-initialized nil diff --git a/src/treesit.c b/src/treesit.c index 679b8fc7ddd..4031d80f7c9 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -4371,4 +4371,15 @@ the symbol of that THING. For example, (or sexp sentence). */); defsubr (&Streesit_subtree_stat); #endif /* HAVE_TREE_SITTER */ defsubr (&Streesit_available_p); +#ifdef WINDOWSNT + DEFSYM (Qtree_sitter__library_abi, "tree-sitter--library-abi"); + Fset (Qtree_sitter__library_abi, +#if HAVE_TREE_SITTER + make_fixnum (TREE_SITTER_LANGUAGE_VERSION) +#else + make_fixnum (-1) +#endif + ); +#endif + } -- 2.30.2