feat: Windows support using MinGW-w64 (#4201)

Building tree-sitter on Windows within a Cygwin or MSYS2 environment
for MinGW-w64 targets should work. As there's no configure-like step,
the tools have to be specified with:

    make CC=x86_64-w64-mingw32-gcc \
         AR=x86_64-w64-mingw32-ar \
         STRIP=x86_64-w64-mingw32-strip

Useful reference:
[How to build and use DLLs on Windows](https://nullprogram.com/blog/2021/05/31/)

This commit doesn't tag public functions with dllexport or
dllimport. This results in exporting non-static functions visible
between translation units, and generating slightly less efficient code
for calling exported functions from the DLL.

This commit doesn't include support to build libtree-sitter with MSVC or
clang-cl, but generates a libtree-sitter.lib file for MSVC/clang-cl
consumers.
This commit is contained in:
Antonin Décimo 2025-02-13 01:31:06 +01:00 committed by GitHub
parent 8e79929cb8
commit f0571b1e33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 10 deletions

View file

@ -1,7 +1,3 @@
ifeq ($(OS),Windows_NT)
$(error Windows is not supported)
endif
LANGUAGE_NAME := tree-sitter-KEBAB_PARSER_NAME
HOMEPAGE_URL := PARSER_URL
VERSION := PARSER_VERSION
@ -37,6 +33,10 @@ ifeq ($(shell uname),Darwin)
SOEXTVER_MAJOR = $(SONAME_MAJOR).$(SOEXT)
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).$(SOEXT)
LINKSHARED = -dynamiclib -Wl,-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SOEXTVER),-rpath,@executable_path/../Frameworks
else ifneq ($(findstring mingw32,$(shell $(CC) -dumpmachine)),)
SOEXT = dll
LINKSHARED += -s -shared -Wl,--out-implib,$(@:dll=lib)
lib$(LANGUAGE_NAME).lib: lib$(LANGUAGE_NAME).$(SOEXT)
else
SOEXT = so
SOEXTVER_MAJOR = $(SOEXT).$(SONAME_MAJOR)
@ -89,7 +89,7 @@ uninstall:
$(RM) -r '$(DESTDIR)$(DATADIR)'/tree-sitter/queries/KEBAB_PARSER_NAME
clean:
$(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT)
$(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) lib$(LANGUAGE_NAME).lib
test:
$(TS) test