diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 91f0b38..e1b1ab1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,27 +2,8 @@ name: CI on: push: branches: [main] - paths: - - grammar.js - - src/** - - test/** - - bindings/** - - binding.gyp - - package.json - - package-lock.json - - .nvmrc - - .github/workflows/** pull_request: - paths: - - grammar.js - - src/** - - test/** - - bindings/** - - binding.gyp - - package.json - - package-lock.json - - .nvmrc - - .github/workflows/** + branches: [main] concurrency: group: ${{github.workflow}}-${{github.ref}} @@ -30,15 +11,14 @@ concurrency: jobs: test: - runs-on: ubuntu-latest + runs-on: ${{matrix.os}} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] steps: - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' + uses: actions/checkout@v6 - name: Set up tree-sitter uses: tree-sitter/setup-action/cli@v2 @@ -46,10 +26,9 @@ jobs: tree-sitter-ref: v0.26.8 - name: Run tests - uses: tree-sitter/parser-test-action@v2 + uses: tree-sitter/parser-test-action@v3 with: test-rust: true - test-node: false + test-node: false # https://github.com/tree-sitter/node-tree-sitter/issues/268 test-python: true test-go: true - test-swift: false diff --git a/bindings/c/tree_sitter/tree-sitter-rescript.h b/bindings/c/tree_sitter/tree-sitter-rescript.h new file mode 100644 index 0000000..3d40a36 --- /dev/null +++ b/bindings/c/tree_sitter/tree-sitter-rescript.h @@ -0,0 +1,16 @@ +#ifndef TREE_SITTER_RESCRIPT_H_ +#define TREE_SITTER_RESCRIPT_H_ + +typedef struct TSLanguage TSLanguage; + +#ifdef __cplusplus +extern "C" { +#endif + +const TSLanguage *tree_sitter_rescript(void); + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_RESCRIPT_H_ diff --git a/package-lock.json b/package-lock.json index 8f6dc5d..64cd0f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ }, "devDependencies": { "rescript": "^12.1.0", + "tree-sitter": "^0.25.0", "tree-sitter-cli": "^0.26.3" }, "peerDependencies": { @@ -176,6 +177,18 @@ "@rescript/win32-x64": "12.1.0" } }, + "node_modules/tree-sitter": { + "version": "0.25.0", + "resolved": "https://registry.npmjs.org/tree-sitter/-/tree-sitter-0.25.0.tgz", + "integrity": "sha512-PGZZzFW63eElZJDe/b/R/LbsjDDYJa5UEjLZJB59RQsMX+fo0j54fqBPn1MGKav/QNa0JR0zBiVaikYDWCj5KQ==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "dependencies": { + "node-addon-api": "^8.3.0", + "node-gyp-build": "^4.8.4" + } + }, "node_modules/tree-sitter-cli": { "version": "0.26.8", "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.26.8.tgz", diff --git a/package.json b/package.json index 53e6110..62f7c1f 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.2.0", "main": "bindings/node", "author": "Victor Nakoryakov", + "type": "module", "license": "MIT", "dependencies": { "nan": "^2.15.0", @@ -11,6 +12,7 @@ }, "devDependencies": { "rescript": "^12.1.0", + "tree-sitter": "^0.25.0", "tree-sitter-cli": "^0.26.3" }, "peerDependencies": { diff --git a/setup.py b/setup.py index 3fe0fb8..94ed666 100644 --- a/setup.py +++ b/setup.py @@ -1,31 +1,12 @@ from os import path -from platform import system 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_rescript/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 system() != "Windows": - cflags = ["-std=c11", "-fvisibility=hidden"] -else: - cflags = ["/std:c11", "/utf-8"] - class Build(build): def run(self): @@ -35,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() @@ -61,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_rescript/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, },