Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to tree-sitter 0.22.6 #77

Merged
merged 14 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions patch/tree-sitter-0.22.6/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
VERSION := 0.22.6
mjambon marked this conversation as resolved.
Show resolved Hide resolved

# 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)
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
18 changes: 17 additions & 1 deletion scripts/download-tree-sitter
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/
mjambon marked this conversation as resolved.
Show resolved Hide resolved
;;
*)
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
9 changes: 9 additions & 0 deletions test/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ 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.
# 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

.PHONY: gen-ocaml
gen-ocaml: ocaml-src/tree-sitter-lang.opam
Expand Down
Loading