diff --git a/patch/tree-sitter-0.22.6/Makefile.patch b/patch/tree-sitter-0.22.6/Makefile.patch new file mode 100644 index 0000000..a8b5a66 --- /dev/null +++ b/patch/tree-sitter-0.22.6/Makefile.patch @@ -0,0 +1,53 @@ +--- ../../downloads/tree-sitter-0.22.6/Makefile.orig 2024-05-05 13:47:18.000000000 -0700 ++++ ../../downloads/tree-sitter-0.22.6/Makefile 2024-06-18 19:52:35.772310737 -0700 +@@ -8,12 +8,12 @@ + + # collect sources + ifneq ($(AMALGAMATED),1) +- SRC := $(wildcard lib/src/*.c) +- # do not double-include amalgamation +- SRC := $(filter-out lib/src/lib.c,$(SRC)) ++ SRC := $(wildcard lib/src/*.c) ++ # do not double-include amalgamation ++ SRC := $(filter-out lib/src/lib.c,$(SRC)) + else +- # use amalgamated build +- SRC := lib/src/lib.c ++ # use amalgamated build ++ SRC := lib/src/lib.c + endif + OBJ := $(SRC:.c=.o) + +@@ -28,21 +28,20 @@ + SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION))) + + # OS-specific bits +-ifeq ($(OS),Windows_NT) +- $(error "Windows is not supported") +-else ifeq ($(shell uname),Darwin) +- SOEXT = dylib +- SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib +- SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib +- LINKSHARED += -dynamiclib -Wl,-install_name,$(LIBDIR)/libtree-sitter.$(SONAME_MAJOR).dylib ++ ++ifeq ($(shell uname),Darwin) ++ SOEXT = dylib ++ SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib ++ SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib ++ LINKSHARED += -dynamiclib -Wl,-install_name,$(LIBDIR)/libtree-sitter.$(SONAME_MAJOR).dylib + else +- SOEXT = so +- SOEXTVER_MAJOR = so.$(SONAME_MAJOR) +- SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR) +- LINKSHARED += -shared -Wl,-soname,libtree-sitter.so.$(SONAME_MAJOR) ++ SOEXT = so ++ SOEXTVER_MAJOR = so.$(SONAME_MAJOR) ++ SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR) ++ LINKSHARED += -shared -Wl,-soname,libtree-sitter.so.$(SONAME_MAJOR) + endif + ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),) +- PCLIBDIR := $(PREFIX)/libdata/pkgconfig ++ PCLIBDIR := $(PREFIX)/libdata/pkgconfig + endif + + all: libtree-sitter.a libtree-sitter.$(SOEXT) tree-sitter.pc diff --git a/scripts/download-tree-sitter b/scripts/download-tree-sitter index 5d8a673..6cbf816 100755 --- a/scripts/download-tree-sitter +++ b/scripts/download-tree-sitter @@ -9,7 +9,7 @@ prog_name=$(basename "$0") # The official version of tree-sitter we use for the code generator and # for the runtime library. Please try to keep this as the single source # of truth. -default_version="0.20.6" +default_version="0.22.6" error() { echo "Current directory: $(pwd)" >&2 @@ -87,5 +87,23 @@ EOF if [[ ! -d "$src_dir" ]]; then error "Archive didn't unpack into the expected folder '$src_dir'." fi + + case "$version" in + 0.20.6) + ;; + 0.22.6) + # See https://github.com/tree-sitter/tree-sitter/pull/3417 + # regarding Windows/Cygwin support + patch --backup \ + tree-sitter-0.22.6/Makefile \ + ../patch/tree-sitter-0.22.6/Makefile.patch + ;; + *) + cat >&2 < 0.22.6 +EOF + esac fi ) diff --git a/scripts/ocaml-tree-sitter-gen-c b/scripts/ocaml-tree-sitter-gen-c index 1280b8f..ecbc8ce 100755 --- a/scripts/ocaml-tree-sitter-gen-c +++ b/scripts/ocaml-tree-sitter-gen-c @@ -42,6 +42,16 @@ else # This mechanism is used with languages whose base grammar is defined # in a tree-sitter-* submodule. + # tree-sitter 0.22.6 creates a dummy 'grammar.js' file if + # there isn't one already. This creates confusing situations + # because our input grammar as created by ocaml-tree-sitter is + # 'src/grammar.json', not the usual 'grammar.js'. Creating our + # own unparseable 'grammar.js' is a protection against using + # the wrong grammar. + # Tracked at https://github.com/tree-sitter/tree-sitter/issues/3415 + echo "..... not the input grammar! Use 'tree-sitter generate src/grammar.json'" \ + > grammar.js + orig_grammar_json="$import_from"/src/grammar.json if [[ ! -e "$orig_grammar_json" ]]; then cat >&2 <