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

@ -163,6 +163,14 @@ jobs:
env:
CFLAGS: -g -Werror -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types
- name: Build C library on Windows (make)
if: ${{ runner.os == 'Windows' }}
run: make.sh -j CC="$CC" CFLAGS="$CFLAGS" AR="$AR"
env:
CC: x86_64-w64-mingw32-gcc
AR: x86_64-w64-mingw32-ar
CFLAGS: -g -Werror -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types
- name: Build C library (CMake)
if: ${{ !matrix.use-cross }}
run: |