From 0deec6a60acd735a6ba07cc0b1be41809e00a9e5 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. (cherry picked from commit 83fc3cf53a4b54a4ec3bf464cfea97f74522cd8d) --- 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 911bd72184d..7d46c4d4d96 100644 --- a/lisp/term/w32-win.el +++ b/lisp/term/w32-win.el @@ -313,8 +313,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 6677158b9de..5e1e9b01059 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -4516,4 +4516,15 @@ applies to LANGUAGE-A will be redirected to LANGUAGE-B instead. */); 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.39.5