From e31cdb90ee12a5ad2d67feacd20f093f82bab940 Mon Sep 17 00:00:00 2001 From: ObserverOfTime Date: Tue, 7 Oct 2025 17:33:08 +0300 Subject: [PATCH] chore: update bindings --- CMakeLists.txt | 11 ++++-- Cargo.toml | 2 +- Makefile | 2 +- bindings/node/index.js | 13 +++---- bindings/python/tests/test_binding.py | 4 +-- package.json | 2 +- setup.py | 49 ++++++++++++++------------- src/parser.c | 2 +- 8 files changed, 46 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cf338b..c178137 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,11 @@ add_library(tree-sitter-yaml src/parser.c) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scanner.c) target_sources(tree-sitter-yaml PRIVATE src/scanner.c) endif() -target_include_directories(tree-sitter-yaml PRIVATE src) +target_include_directories(tree-sitter-yaml + PRIVATE src + INTERFACE $ + $) + set(YAML_SCHEMA core CACHE STRING "YAML schema") set(YAML_SCHEMA_VALUES core json legacy CACHE INTERNAL "Allowed schemas") @@ -54,8 +58,9 @@ configure_file(bindings/c/tree-sitter-yaml.pc.in include(GNUInstallDirs) -install(FILES bindings/c/tree-sitter-yaml.h - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tree_sitter") +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bindings/c/tree_sitter" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + FILES_MATCHING PATTERN "*.h") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-yaml.pc" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig") install(TARGETS tree-sitter-yaml diff --git a/Cargo.toml b/Cargo.toml index 38c2eb0..cdd7968 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ include = [ "queries/*", "src/*", "tree-sitter.json", - "LICENSE", + "/LICENSE", ] [lib] diff --git a/Makefile b/Makefile index cb36a27..e053b15 100644 --- a/Makefile +++ b/Makefile @@ -77,7 +77,7 @@ $(PARSER): $(SRC_DIR)/grammar.json install: all install -d '$(DESTDIR)$(DATADIR)'/tree-sitter/queries/yaml '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)' - install -m644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h + install -m644 bindings/c/tree_sitter/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h install -m644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc install -m644 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) diff --git a/bindings/node/index.js b/bindings/node/index.js index 22ec946..f455206 100644 --- a/bindings/node/index.js +++ b/bindings/node/index.js @@ -1,11 +1,12 @@ -const root = require("path").join(__dirname, "..", ".."); +const root = require('path').join(__dirname, '..', '..'); module.exports = - typeof process.versions.bun === "string" + typeof process.versions.bun === 'string' ? // Support `bun build --compile` by being statically analyzable enough to find the .node file at build-time - ? require(`../../prebuilds/${process.platform}-${process.arch}/tree-sitter-yaml.node`) - : require("node-gyp-build")(root); + require(`../../prebuilds/${process.platform}-${process.arch}/@tree-sitter-grammars+tree-sitter-yaml.node`) : + require('node-gyp-build')(root); try { - module.exports.nodeTypeInfo = require("../../src/node-types.json"); -} catch (_) {} + module.exports.nodeTypeInfo = require('../../src/node-types.json'); + // eslint-disable-next-line no-unused-vars +} catch (_) { } diff --git a/bindings/python/tests/test_binding.py b/bindings/python/tests/test_binding.py index b0ac01e..31fc675 100644 --- a/bindings/python/tests/test_binding.py +++ b/bindings/python/tests/test_binding.py @@ -1,12 +1,12 @@ from unittest import TestCase -import tree_sitter +from tree_sitter import Language, Parser import tree_sitter_yaml class TestLanguage(TestCase): def test_can_load_grammar(self): try: - tree_sitter.Language(tree_sitter_yaml.language()) + Parser(Language(tree_sitter_yaml.language())) except Exception: self.fail("Error loading YAML grammar") diff --git a/package.json b/package.json index a5754ed..bed5661 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "*.wasm" ], "dependencies": { - "node-addon-api": "^8.3.1", + "node-addon-api": "^8.5.0", "node-gyp-build": "^4.8.4" }, "devDependencies": { diff --git a/setup.py b/setup.py index 016c81a..900806e 100644 --- a/setup.py +++ b/setup.py @@ -1,30 +1,12 @@ -from os import name, path +from os import path from sysconfig import get_config_var from setuptools import Extension, find_packages, setup from setuptools.command.build import build +from setuptools.command.build_ext import build_ext from setuptools.command.egg_info import egg_info from wheel.bdist_wheel import bdist_wheel -sources = [ - "bindings/python/tree_sitter_yaml/binding.c", - "src/parser.c", -] -if path.exists("src/scanner.c"): - sources.append("src/scanner.c") - -macros: list[tuple[str, str | None]] = [ - ("PY_SSIZE_T_CLEAN", None), - ("TREE_SITTER_HIDE_SYMBOLS", None), -] -if limited_api := not get_config_var("Py_GIL_DISABLED"): - macros.append(("Py_LIMITED_API", "0x030A0000")) - -if name != "nt": - cflags = ["-std=c11", "-fvisibility=hidden"] -else: - cflags = ["/std:c11", "/utf-8"] - class Build(build): def run(self): @@ -34,6 +16,19 @@ def run(self): super().run() +class BuildExt(build_ext): + def build_extension(self, ext: Extension): + if self.compiler.compiler_type != "msvc": + ext.extra_compile_args = ["-std=c11", "-fvisibility=hidden"] + else: + ext.extra_compile_args = ["/std:c11", "/utf-8"] + if path.exists("src/scanner.c"): + ext.sources.append("src/scanner.c") + if ext.py_limited_api: + ext.define_macros.append(("Py_LIMITED_API", "0x030A0000")) + super().build_extension(ext) + + class BdistWheel(bdist_wheel): def get_tag(self): python, abi, platform = super().get_tag() @@ -60,15 +55,21 @@ def find_sources(self): ext_modules=[ Extension( name="_binding", - sources=sources, - extra_compile_args=cflags, - define_macros=macros, + sources=[ + "bindings/python/tree_sitter_yaml/binding.c", + "src/parser.c", + ], + define_macros=[ + ("PY_SSIZE_T_CLEAN", None), + ("TREE_SITTER_HIDE_SYMBOLS", None), + ], include_dirs=["src"], - py_limited_api=limited_api, + py_limited_api=not get_config_var("Py_GIL_DISABLED"), ) ], cmdclass={ "build": Build, + "build_ext": BuildExt, "bdist_wheel": BdistWheel, "egg_info": EggInfo, }, diff --git a/src/parser.c b/src/parser.c index c7831e5..34fe31b 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,4 +1,4 @@ -/* Automatically @generated by tree-sitter v0.25.4 (683a5044a8f496d8e8b57c06ac4f1a722c62205f) */ +/* Automatically @generated by tree-sitter v0.25.10 */ #include "tree_sitter/parser.h"