From dc404b71b006dcb7d8f53cba3a57a5d6264aa5de Mon Sep 17 00:00:00 2001 From: Martin Jambon Date: Tue, 11 Jun 2024 20:47:11 -0700 Subject: [PATCH 01/14] Upgrade tree-sitter to 0.22.6 --- scripts/download-tree-sitter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/download-tree-sitter b/scripts/download-tree-sitter index 5d8a673..48e13ef 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 From 55c5232b4a313e886cb7a74dc1427b366107ae25 Mon Sep 17 00:00:00 2001 From: Martin Jambon Date: Wed, 12 Jun 2024 15:06:28 -0700 Subject: [PATCH 02/14] Add protection against dummy grammar.js --- test/Makefile.common | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/Makefile.common b/test/Makefile.common index 5f8d23f..3337dc7 100644 --- a/test/Makefile.common +++ b/test/Makefile.common @@ -53,6 +53,14 @@ gen-c: else \ echo "src/parser.c for $(LANG) is up to date."; \ fi + # 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. + @echo "..... not the input grammar! Use 'tree-sitter generate src/grammar.json'" \ + > grammar.js .PHONY: gen-ocaml gen-ocaml: ocaml-src/tree-sitter-lang.opam From adf71fd88ad3551d3666f010cfbfdaf2e967de99 Mon Sep 17 00:00:00 2001 From: Martin Jambon Date: Wed, 12 Jun 2024 16:09:29 -0700 Subject: [PATCH 03/14] Add comment --- test/Makefile.common | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Makefile.common b/test/Makefile.common index 3337dc7..386ab81 100644 --- a/test/Makefile.common +++ b/test/Makefile.common @@ -59,6 +59,7 @@ gen-c: # '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 From 723cabf6cfd2924b55d2ef5bd096f1749a2fc53c Mon Sep 17 00:00:00 2001 From: Martin Jambon Date: Thu, 13 Jun 2024 17:30:22 -0700 Subject: [PATCH 04/14] Remove spurious tabs from tree-sitter's makefile (see https://github.com/tree-sitter/tree-sitter/pull/3417) --- patch/tree-sitter-0.22.6/Makefile | 112 ++++++++++++++++++++++++++++++ scripts/download-tree-sitter | 16 +++++ 2 files changed, 128 insertions(+) create mode 100644 patch/tree-sitter-0.22.6/Makefile diff --git a/patch/tree-sitter-0.22.6/Makefile b/patch/tree-sitter-0.22.6/Makefile new file mode 100644 index 0000000..3e9d30c --- /dev/null +++ b/patch/tree-sitter-0.22.6/Makefile @@ -0,0 +1,112 @@ +VERSION := 0.22.6 + +# install directory layout +PREFIX ?= /usr/local +INCLUDEDIR ?= $(PREFIX)/include +LIBDIR ?= $(PREFIX)/lib +PCLIBDIR ?= $(LIBDIR)/pkgconfig + +# collect sources +ifneq ($(AMALGAMATED),1) + 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 +endif +OBJ := $(SRC:.c=.o) + +# define default flags, and override to append mandatory flags +ARFLAGS := rcs +CFLAGS ?= -O3 -Wall -Wextra -Wshadow -pedantic +override CFLAGS += -std=c11 -fPIC -fvisibility=hidden +override CFLAGS += -Ilib/src -Ilib/src/wasm -Ilib/include + +# ABI versioning +SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION))) +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 +else + 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 +endif + +all: libtree-sitter.a libtree-sitter.$(SOEXT) tree-sitter.pc + +libtree-sitter.a: $(OBJ) + $(AR) $(ARFLAGS) $@ $^ + +libtree-sitter.$(SOEXT): $(OBJ) + $(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@ +ifneq ($(STRIP),) + $(STRIP) $@ +endif + +tree-sitter.pc: tree-sitter.pc.in + sed -e 's|@VERSION@|$(VERSION)|' \ + -e 's|@LIBDIR@|$(LIBDIR)|' \ + -e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \ + -e 's|=$(PREFIX)|=$${prefix}|' \ + -e 's|@PREFIX@|$(PREFIX)|' $< > $@ + +clean: + $(RM) $(OBJ) tree-sitter.pc libtree-sitter.a libtree-sitter.$(SOEXT) + +install: all + install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)' + install -m644 lib/include/tree_sitter/api.h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/api.h + install -m644 tree-sitter.pc '$(DESTDIR)$(PCLIBDIR)'/tree-sitter.pc + install -m644 libtree-sitter.a '$(DESTDIR)$(LIBDIR)'/libtree-sitter.a + install -m755 libtree-sitter.$(SOEXT) '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXTVER) + ln -sf libtree-sitter.$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXTVER_MAJOR) + ln -sf libtree-sitter.$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXT) + +uninstall: + $(RM) '$(DESTDIR)$(LIBDIR)'/libtree-sitter.a \ + '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXTVER) \ + '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXTVER_MAJOR) \ + '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXT) \ + '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/api.h \ + '$(DESTDIR)$(PCLIBDIR)'/tree-sitter.pc + +.PHONY: all install uninstall clean + + +##### Dev targets ##### + +test: + script/fetch-fixtures + script/generate-fixtures + script/test + +test_wasm: + script/generate-fixtures-wasm + script/test-wasm + +lint: + cargo update --workspace --locked --quiet + cargo check --workspace --all-targets + cargo +nightly fmt --all --check + cargo clippy --workspace --all-targets -- -D warnings + +format: + cargo +nightly fmt --all + +changelog: + @git-cliff --config script/cliff.toml --output CHANGELOG.md --latest --github-token $(shell gh auth token) + +.PHONY: test test_wasm lint format changelog diff --git a/scripts/download-tree-sitter b/scripts/download-tree-sitter index 48e13ef..e9fb470 100755 --- a/scripts/download-tree-sitter +++ b/scripts/download-tree-sitter @@ -89,3 +89,19 @@ EOF fi fi ) + +case "$version" in + 0.20.6) + ;; + 0.22.6) + # See https://github.com/tree-sitter/tree-sitter/pull/3417 + # regarding Windows support + mv downloads/tree-sitter-0.22.6/Makefile \ + downloads/tree-sitter-0.22.6/Makefile.orig + cp patch/tree-sitter-0.22.6/Makefile downloads/tree-sitter-0.22.6/ + ;; + *) + echo "*** tree-sitter version: $version" + echo "*** Warning: tree-sitter 0.22.6 required patching the Makefile!" + echo "*** Remove this code once we're fully migrated to a version > 0.22.6" +esac From a7495d50ad32fa4e31a36f4571a922fb2c4770bb Mon Sep 17 00:00:00 2001 From: Martin Jambon Date: Thu, 13 Jun 2024 17:40:22 -0700 Subject: [PATCH 05/14] Checking if Windows really isn't supported by tree-sitter 0.22.6's makefile --- patch/tree-sitter-0.22.6/Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/patch/tree-sitter-0.22.6/Makefile b/patch/tree-sitter-0.22.6/Makefile index 3e9d30c..40f42b4 100644 --- a/patch/tree-sitter-0.22.6/Makefile +++ b/patch/tree-sitter-0.22.6/Makefile @@ -28,9 +28,10 @@ SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION))) SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION))) # OS-specific bits -ifeq ($(OS),Windows_NT) - $(error "Windows is not supported") -else ifeq ($(shell uname),Darwin) +#ifeq ($(OS),Windows_NT) +# $(error "Windows is not supported") +#else ifeq ($(shell uname),Darwin) +ifeq ($(shell uname),Darwin) SOEXT = dylib SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib From 5b9688ef07a23271648dd79d687d9ea7ba4ff7fc Mon Sep 17 00:00:00 2001 From: Martin Jambon Date: Fri, 14 Jun 2024 18:33:58 -0700 Subject: [PATCH 06/14] Install parser.h to make it available as --- scripts/install-tree-sitter-lib | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/install-tree-sitter-lib b/scripts/install-tree-sitter-lib index d9649b0..557685b 100755 --- a/scripts/install-tree-sitter-lib +++ b/scripts/install-tree-sitter-lib @@ -55,6 +55,12 @@ dir_name=$(dirname "$BASH_SOURCE") cd downloads/tree-sitter make PREFIX="$prefix" make PREFIX="$prefix" install + + # This is probably the wrong way of making + # available but it works. We need this to compile tree-sitter + # parsers to JavaScript with Emscripten in semgrep. + mkdir -p "$prefix"/include/ + cp lib/src/parser.h "$prefix"/include/ ) cat < Date: Fri, 14 Jun 2024 18:40:19 -0700 Subject: [PATCH 07/14] Don't overwrite grammar.js with a dummy grammar.js --- scripts/ocaml-tree-sitter-gen-c | 10 ++++++++++ test/Makefile.common | 9 --------- 2 files changed, 10 insertions(+), 9 deletions(-) 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 < grammar.js .PHONY: gen-ocaml gen-ocaml: ocaml-src/tree-sitter-lang.opam From 4ce8cb3ed107e3ef6e290ae9462683b7995b9ce7 Mon Sep 17 00:00:00 2001 From: Martin Jambon Date: Fri, 14 Jun 2024 19:07:24 -0700 Subject: [PATCH 08/14] Undo code described as "this is probably wrong" because it turns out it is --- scripts/install-tree-sitter-lib | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scripts/install-tree-sitter-lib b/scripts/install-tree-sitter-lib index 557685b..d9649b0 100755 --- a/scripts/install-tree-sitter-lib +++ b/scripts/install-tree-sitter-lib @@ -55,12 +55,6 @@ dir_name=$(dirname "$BASH_SOURCE") cd downloads/tree-sitter make PREFIX="$prefix" make PREFIX="$prefix" install - - # This is probably the wrong way of making - # available but it works. We need this to compile tree-sitter - # parsers to JavaScript with Emscripten in semgrep. - mkdir -p "$prefix"/include/ - cp lib/src/parser.h "$prefix"/include/ ) cat < Date: Tue, 18 Jun 2024 15:05:58 -0700 Subject: [PATCH 09/14] Restore makefile test that excludes native Windows --- patch/tree-sitter-0.22.6/Makefile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/patch/tree-sitter-0.22.6/Makefile b/patch/tree-sitter-0.22.6/Makefile index 40f42b4..97e8df3 100644 --- a/patch/tree-sitter-0.22.6/Makefile +++ b/patch/tree-sitter-0.22.6/Makefile @@ -28,9 +28,15 @@ SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION))) SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION))) # OS-specific bits -#ifeq ($(OS),Windows_NT) -# $(error "Windows is not supported") -#else ifeq ($(shell uname),Darwin) + +# This makefile doesn't work in a native Windows environment +ifeq ($(OS),Windows_NT) + # but it works with Cygwin + ifneq ($(OSTYPE),cygwin) + $(error "Windows is not supported by this Makefile") + endif +endif + ifeq ($(shell uname),Darwin) SOEXT = dylib SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib From 7b217be8e8a1345ddd93122ab14f52ca6bda098c Mon Sep 17 00:00:00 2001 From: Martin Jambon Date: Tue, 18 Jun 2024 15:35:34 -0700 Subject: [PATCH 10/14] Use a patch instead of a full modified copy of the file to patch --- patch/tree-sitter-0.22.6/Makefile | 119 ------------------------ patch/tree-sitter-0.22.6/Makefile.patch | 60 ++++++++++++ scripts/download-tree-sitter | 34 +++---- 3 files changed, 78 insertions(+), 135 deletions(-) delete mode 100644 patch/tree-sitter-0.22.6/Makefile create mode 100644 patch/tree-sitter-0.22.6/Makefile.patch diff --git a/patch/tree-sitter-0.22.6/Makefile b/patch/tree-sitter-0.22.6/Makefile deleted file mode 100644 index 97e8df3..0000000 --- a/patch/tree-sitter-0.22.6/Makefile +++ /dev/null @@ -1,119 +0,0 @@ -VERSION := 0.22.6 - -# install directory layout -PREFIX ?= /usr/local -INCLUDEDIR ?= $(PREFIX)/include -LIBDIR ?= $(PREFIX)/lib -PCLIBDIR ?= $(LIBDIR)/pkgconfig - -# collect sources -ifneq ($(AMALGAMATED),1) - 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 -endif -OBJ := $(SRC:.c=.o) - -# define default flags, and override to append mandatory flags -ARFLAGS := rcs -CFLAGS ?= -O3 -Wall -Wextra -Wshadow -pedantic -override CFLAGS += -std=c11 -fPIC -fvisibility=hidden -override CFLAGS += -Ilib/src -Ilib/src/wasm -Ilib/include - -# ABI versioning -SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION))) -SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION))) - -# OS-specific bits - -# This makefile doesn't work in a native Windows environment -ifeq ($(OS),Windows_NT) - # but it works with Cygwin - ifneq ($(OSTYPE),cygwin) - $(error "Windows is not supported by this Makefile") - endif -endif - -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) -endif -ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),) - PCLIBDIR := $(PREFIX)/libdata/pkgconfig -endif - -all: libtree-sitter.a libtree-sitter.$(SOEXT) tree-sitter.pc - -libtree-sitter.a: $(OBJ) - $(AR) $(ARFLAGS) $@ $^ - -libtree-sitter.$(SOEXT): $(OBJ) - $(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@ -ifneq ($(STRIP),) - $(STRIP) $@ -endif - -tree-sitter.pc: tree-sitter.pc.in - sed -e 's|@VERSION@|$(VERSION)|' \ - -e 's|@LIBDIR@|$(LIBDIR)|' \ - -e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \ - -e 's|=$(PREFIX)|=$${prefix}|' \ - -e 's|@PREFIX@|$(PREFIX)|' $< > $@ - -clean: - $(RM) $(OBJ) tree-sitter.pc libtree-sitter.a libtree-sitter.$(SOEXT) - -install: all - install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)' - install -m644 lib/include/tree_sitter/api.h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/api.h - install -m644 tree-sitter.pc '$(DESTDIR)$(PCLIBDIR)'/tree-sitter.pc - install -m644 libtree-sitter.a '$(DESTDIR)$(LIBDIR)'/libtree-sitter.a - install -m755 libtree-sitter.$(SOEXT) '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXTVER) - ln -sf libtree-sitter.$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXTVER_MAJOR) - ln -sf libtree-sitter.$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXT) - -uninstall: - $(RM) '$(DESTDIR)$(LIBDIR)'/libtree-sitter.a \ - '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXTVER) \ - '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXTVER_MAJOR) \ - '$(DESTDIR)$(LIBDIR)'/libtree-sitter.$(SOEXT) \ - '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/api.h \ - '$(DESTDIR)$(PCLIBDIR)'/tree-sitter.pc - -.PHONY: all install uninstall clean - - -##### Dev targets ##### - -test: - script/fetch-fixtures - script/generate-fixtures - script/test - -test_wasm: - script/generate-fixtures-wasm - script/test-wasm - -lint: - cargo update --workspace --locked --quiet - cargo check --workspace --all-targets - cargo +nightly fmt --all --check - cargo clippy --workspace --all-targets -- -D warnings - -format: - cargo +nightly fmt --all - -changelog: - @git-cliff --config script/cliff.toml --output CHANGELOG.md --latest --github-token $(shell gh auth token) - -.PHONY: test test_wasm lint format changelog 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..9b51053 --- /dev/null +++ b/patch/tree-sitter-0.22.6/Makefile.patch @@ -0,0 +1,60 @@ +--- ../../downloads/tree-sitter-0.22.6/Makefile 2024-05-05 13:47:18.000000000 -0700 ++++ Makefile 2024-06-18 15:05:44.257992007 -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,28 @@ + SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION))) + + # OS-specific bits ++ ++# This makefile doesn't work in a native Windows environment + 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 ++ # but it works with Cygwin ++ ifneq ($(OSTYPE),cygwin) ++ $(error "Windows is not supported by this Makefile") ++ endif ++endif ++ ++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 e9fb470..6cbf816 100755 --- a/scripts/download-tree-sitter +++ b/scripts/download-tree-sitter @@ -87,21 +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 ) - -case "$version" in - 0.20.6) - ;; - 0.22.6) - # See https://github.com/tree-sitter/tree-sitter/pull/3417 - # regarding Windows support - mv downloads/tree-sitter-0.22.6/Makefile \ - downloads/tree-sitter-0.22.6/Makefile.orig - cp patch/tree-sitter-0.22.6/Makefile downloads/tree-sitter-0.22.6/ - ;; - *) - echo "*** tree-sitter version: $version" - echo "*** Warning: tree-sitter 0.22.6 required patching the Makefile!" - echo "*** Remove this code once we're fully migrated to a version > 0.22.6" -esac From d17b45fe90ed4586729baa9798d4b52897534e64 Mon Sep 17 00:00:00 2001 From: Martin Jambon Date: Tue, 18 Jun 2024 16:09:20 -0700 Subject: [PATCH 11/14] Fix the OSTYPE hack --- patch/tree-sitter-0.22.6/Makefile.patch | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/patch/tree-sitter-0.22.6/Makefile.patch b/patch/tree-sitter-0.22.6/Makefile.patch index 9b51053..b60a24a 100644 --- a/patch/tree-sitter-0.22.6/Makefile.patch +++ b/patch/tree-sitter-0.22.6/Makefile.patch @@ -1,5 +1,5 @@ ---- ../../downloads/tree-sitter-0.22.6/Makefile 2024-05-05 13:47:18.000000000 -0700 -+++ Makefile 2024-06-18 15:05:44.257992007 -0700 +--- ../../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 16:05:05.402925942 -0700 @@ -8,12 +8,12 @@ # collect sources @@ -18,11 +18,13 @@ endif OBJ := $(SRC:.c=.o) -@@ -28,21 +28,28 @@ +@@ -28,21 +28,30 @@ SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION))) # OS-specific bits + ++OSTYPE := $(shell echo "$$OSTYPE") ++ +# This makefile doesn't work in a native Windows environment ifeq ($(OS),Windows_NT) - $(error "Windows is not supported") From a8554ccd9b4e0ec2af17b607113467443c237b07 Mon Sep 17 00:00:00 2001 From: Martin Jambon Date: Tue, 18 Jun 2024 18:05:55 -0700 Subject: [PATCH 12/14] Try calling bash to determine OS type --- patch/tree-sitter-0.22.6/Makefile.patch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patch/tree-sitter-0.22.6/Makefile.patch b/patch/tree-sitter-0.22.6/Makefile.patch index b60a24a..69ff23c 100644 --- a/patch/tree-sitter-0.22.6/Makefile.patch +++ b/patch/tree-sitter-0.22.6/Makefile.patch @@ -1,5 +1,5 @@ --- ../../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 16:05:05.402925942 -0700 ++++ ../../downloads/tree-sitter-0.22.6/Makefile 2024-06-18 17:57:34.217371030 -0700 @@ -8,12 +8,12 @@ # collect sources @@ -23,7 +23,7 @@ # OS-specific bits + -+OSTYPE := $(shell echo "$$OSTYPE") ++OSTYPE := $(shell bash -c 'echo "$$OSTYPE"') + +# This makefile doesn't work in a native Windows environment ifeq ($(OS),Windows_NT) From a3383bf58bd6afd688b06f7f4ff0119532e145e5 Mon Sep 17 00:00:00 2001 From: Martin Jambon Date: Tue, 18 Jun 2024 19:30:54 -0700 Subject: [PATCH 13/14] Try another way to check if we're on Cygwin --- patch/tree-sitter-0.22.6/Makefile.patch | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/patch/tree-sitter-0.22.6/Makefile.patch b/patch/tree-sitter-0.22.6/Makefile.patch index 69ff23c..0ef101c 100644 --- a/patch/tree-sitter-0.22.6/Makefile.patch +++ b/patch/tree-sitter-0.22.6/Makefile.patch @@ -1,5 +1,5 @@ --- ../../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 17:57:34.217371030 -0700 ++++ ../../downloads/tree-sitter-0.22.6/Makefile 2024-06-18 19:27:48.892528589 -0700 @@ -8,12 +8,12 @@ # collect sources @@ -23,7 +23,7 @@ # OS-specific bits + -+OSTYPE := $(shell bash -c 'echo "$$OSTYPE"') ++UNAME_S := $(shell uname -s) + +# This makefile doesn't work in a native Windows environment ifeq ($(OS),Windows_NT) @@ -34,7 +34,7 @@ - SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib - LINKSHARED += -dynamiclib -Wl,-install_name,$(LIBDIR)/libtree-sitter.$(SONAME_MAJOR).dylib + # but it works with Cygwin -+ ifneq ($(OSTYPE),cygwin) ++ ifneq ($(findstring CYGWIN,$(UNAME_S)),CYGWIN) + $(error "Windows is not supported by this Makefile") + endif +endif From fe3f3856cd514d372819a95226676ae9b7423706 Mon Sep 17 00:00:00 2001 From: Martin Jambon Date: Tue, 18 Jun 2024 20:00:17 -0700 Subject: [PATCH 14/14] Giving up on trying to detect Cygwin. Without shell access, it's incredibly time-consuming. --- patch/tree-sitter-0.22.6/Makefile.patch | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/patch/tree-sitter-0.22.6/Makefile.patch b/patch/tree-sitter-0.22.6/Makefile.patch index 0ef101c..a8b5a66 100644 --- a/patch/tree-sitter-0.22.6/Makefile.patch +++ b/patch/tree-sitter-0.22.6/Makefile.patch @@ -1,5 +1,5 @@ --- ../../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:27:48.892528589 -0700 ++++ ../../downloads/tree-sitter-0.22.6/Makefile 2024-06-18 19:52:35.772310737 -0700 @@ -8,12 +8,12 @@ # collect sources @@ -18,26 +18,17 @@ endif OBJ := $(SRC:.c=.o) -@@ -28,21 +28,30 @@ +@@ -28,21 +28,20 @@ SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION))) # OS-specific bits -+ -+UNAME_S := $(shell uname -s) -+ -+# This makefile doesn't work in a native Windows environment - ifeq ($(OS),Windows_NT) +-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 -+ # but it works with Cygwin -+ ifneq ($(findstring CYGWIN,$(UNAME_S)),CYGWIN) -+ $(error "Windows is not supported by this Makefile") -+ endif -+endif + +ifeq ($(shell uname),Darwin) + SOEXT = dylib