feat: Windows support using MinGW-w64#4201
Conversation
|
But it does not produce a .dll |
It does, but just with the $ make
cc -O3 -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types -std=c11 -fPIC -fvisibility=hidden -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -Ilib/src -Ilib/src/wasm -Ilib/include -c -o lib/src/alloc.o lib/src/alloc.c
cc -O3 -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types -std=c11 -fPIC -fvisibility=hidden -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -Ilib/src -Ilib/src/wasm -Ilib/include -c -o lib/src/get_changed_ranges.o lib/src/get_changed_ranges.c
cc -O3 -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types -std=c11 -fPIC -fvisibility=hidden -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -Ilib/src -Ilib/src/wasm -Ilib/include -c -o lib/src/language.o lib/src/language.c
cc -O3 -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types -std=c11 -fPIC -fvisibility=hidden -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -Ilib/src -Ilib/src/wasm -Ilib/include -c -o lib/src/lexer.o lib/src/lexer.c
cc -O3 -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types -std=c11 -fPIC -fvisibility=hidden -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -Ilib/src -Ilib/src/wasm -Ilib/include -c -o lib/src/node.o lib/src/node.c
cc -O3 -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types -std=c11 -fPIC -fvisibility=hidden -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -Ilib/src -Ilib/src/wasm -Ilib/include -c -o lib/src/parser.o lib/src/parser.c
cc -O3 -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types -std=c11 -fPIC -fvisibility=hidden -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -Ilib/src -Ilib/src/wasm -Ilib/include -c -o lib/src/query.o lib/src/query.c
cc -O3 -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types -std=c11 -fPIC -fvisibility=hidden -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -Ilib/src -Ilib/src/wasm -Ilib/include -c -o lib/src/stack.o lib/src/stack.c
cc -O3 -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types -std=c11 -fPIC -fvisibility=hidden -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -Ilib/src -Ilib/src/wasm -Ilib/include -c -o lib/src/subtree.o lib/src/subtree.c
cc -O3 -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types -std=c11 -fPIC -fvisibility=hidden -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -Ilib/src -Ilib/src/wasm -Ilib/include -c -o lib/src/tree.o lib/src/tree.c
cc -O3 -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types -std=c11 -fPIC -fvisibility=hidden -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -Ilib/src -Ilib/src/wasm -Ilib/include -c -o lib/src/tree_cursor.o lib/src/tree_cursor.c
cc -O3 -Wall -Wextra -Wshadow -Wpedantic -Werror=incompatible-pointer-types -std=c11 -fPIC -fvisibility=hidden -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -Ilib/src -Ilib/src/wasm -Ilib/include -c -o lib/src/wasm_store.o lib/src/wasm_store.c
sed -e 's|@PROJECT_VERSION@|0.25.1|' \
-e 's|@CMAKE_INSTALL_LIBDIR@|lib|' \
-e 's|@CMAKE_INSTALL_INCLUDEDIR@|include|' \
-e 's|@PROJECT_DESCRIPTION@|An incremental parsing system for programming tools|' \
-e 's|@PROJECT_HOMEPAGE_URL@|https://tree-sitter.github.io/tree-sitter/|' \
-e 's|@CMAKE_INSTALL_PREFIX@|/usr/local|' lib/tree-sitter.pc.in > tree-sitter.pc
ar rcs libtree-sitter.a lib/src/alloc.o lib/src/get_changed_ranges.o lib/src/language.o lib/src/lexer.o lib/src/node.o lib/src/parser.o lib/src/query.o lib/src/stack.o lib/src/subtree.o lib/src/tree.o lib/src/tree_cursor.o lib/src/wasm_store.o
cc -shared -Wl,-soname,libtree-sitter.so.0.25 lib/src/alloc.o lib/src/get_changed_ranges.o lib/src/language.o lib/src/lexer.o lib/src/node.o lib/src/parser.o lib/src/query.o lib/src/stack.o lib/src/subtree.o lib/src/tree.o lib/src/tree_cursor.o lib/src/wasm_store.o
-o libtree-sitter.so
$ file libtree-sitter.so
libtree-sitter.so: PE32+ executable (DLL) (console) x86-64, for MS Windows, 18 sections |
f664d14 to
2448435
Compare
2448435 to
7e26e56
Compare
|
I think the build using MinGW-w64 succeeds. I'm not interested in supporting MSVC/clang-cl or Cygwin+ |
7b10bf9 to
d6a3153
Compare
|
This is a bit too much. |
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.
d6a3153 to
87a376a
Compare
Ok, I've removed the |
|
The CI timed out but should succeed. Is the PR more acceptable now? |
|
Thanks @MisterDA, looks good. And thanks for the reviews @ObserverOfTime. |
This is best-effort and should help picking the right cc, ar, and strip utilities, whether they are prefixed (as when using the MinGW-w64 cross-compiler) or not. For a refresh of the shell features used, see: POSIX 2018 2.6.2 Parameter Expansion. https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_06_02 This includes an update the Makefile patch to build with MinGW-w64. GNU Make 4.4.1 build for x86_64-pc-cygwin is perfectly capable of reading the Makefile. It needs to be taught how to use MinGW-w64 to build a DLL. This is a backport of patches accepted upstream. See tree-sitter/tree-sitter#4201 for the corresponding upstream fix. Co-authored-by: Antonin Décimo <antonin@tarides.com>
* Detect CC, AR, and STRIP to build tree-sitter on MinGW-w64 This is best-effort and should help picking the right cc, ar, and strip utilities, whether they are prefixed (as when using the MinGW-w64 cross-compiler) or not. For a refresh of the shell features used, see: POSIX 2018 2.6.2 Parameter Expansion. https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_06_02 This includes an update the Makefile patch to build with MinGW-w64. GNU Make 4.4.1 build for x86_64-pc-cygwin is perfectly capable of reading the Makefile. It needs to be taught how to use MinGW-w64 to build a DLL. This is a backport of patches accepted upstream. See tree-sitter/tree-sitter#4201 for the corresponding upstream fix. Co-authored-by: Antonin Décimo <antonin@tarides.com> * Don't pass `-rpath` on Windows --------- Co-authored-by: Antonin Décimo <antonin@tarides.com>
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-stripExported symbols should be tagged.
Useful reference: How to build and use DLLs on Windows.
This PR doesn't include support to build libtree-sitter with MSVC or clang-cl, but generates a
libtree-sitter.libfile for MSVC/clang-cl consumers.Cf #3418 #3417
cc @ObserverOfTime