feat(bindings): auto-detect scanners
This commit is contained in:
parent
60c5057617
commit
66dab20462
5 changed files with 38 additions and 26 deletions
|
|
@ -2,7 +2,9 @@ package tree_sitter_LOWER_PARSER_NAME
|
|||
|
||||
// #cgo CFLAGS: -std=c11 -fPIC
|
||||
// #include "../../src/parser.c"
|
||||
// // NOTE: if your language has an external scanner, add it here.
|
||||
// #if __has_include("../../src/scanner.c")
|
||||
// #include "../../src/scanner.c"
|
||||
// #endif
|
||||
import "C"
|
||||
|
||||
import "unsafe"
|
||||
|
|
|
|||
|
|
@ -11,9 +11,14 @@
|
|||
"sources": [
|
||||
"bindings/node/binding.cc",
|
||||
"src/parser.c",
|
||||
# NOTE: if your language has an external scanner, add it here.
|
||||
],
|
||||
"variables": {
|
||||
"has_scanner": "<!(node -p \"fs.exists('src/scanner.c')\")"
|
||||
},
|
||||
"conditions": [
|
||||
["has_scanner=='true'", {
|
||||
"sources+": ["src/scanner.c"],
|
||||
}],
|
||||
["OS!='win'", {
|
||||
"cflags_c": [
|
||||
"-std=c11",
|
||||
|
|
|
|||
|
|
@ -11,12 +11,11 @@ fn main() {
|
|||
c_config.file(&parser_path);
|
||||
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
|
||||
|
||||
// NOTE: if your language uses an external scanner, uncomment this block:
|
||||
/*
|
||||
let scanner_path = src_dir.join("scanner.c");
|
||||
c_config.file(&scanner_path);
|
||||
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
||||
*/
|
||||
if scanner_path.exists() {
|
||||
c_config.file(&scanner_path);
|
||||
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
||||
}
|
||||
|
||||
c_config.compile("tree-sitter-PARSER_NAME");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,13 @@
|
|||
// swift-tools-version:5.3
|
||||
|
||||
import Foundation
|
||||
import PackageDescription
|
||||
|
||||
var sources = ["src/parser.c"]
|
||||
if FileManager.default.fileExists(atPath: "src/scanner.c") {
|
||||
sources.append("src/scanner.c")
|
||||
}
|
||||
|
||||
let package = Package(
|
||||
name: "TreeSitterCAMEL_PARSER_NAME",
|
||||
products: [
|
||||
|
|
@ -14,10 +21,7 @@ let package = Package(
|
|||
name: "TreeSitterCAMEL_PARSER_NAME",
|
||||
dependencies: [],
|
||||
path: ".",
|
||||
sources: [
|
||||
"src/parser.c",
|
||||
// NOTE: if your language has an external scanner, add it here.
|
||||
],
|
||||
sources: sources,
|
||||
resources: [
|
||||
.copy("queries")
|
||||
],
|
||||
|
|
|
|||
|
|
@ -1,15 +1,27 @@
|
|||
from os.path import isdir, join
|
||||
from os import path
|
||||
from platform import system
|
||||
|
||||
from setuptools import Extension, find_packages, setup
|
||||
from setuptools.command.build import build
|
||||
from wheel.bdist_wheel import bdist_wheel
|
||||
|
||||
sources = [
|
||||
"bindings/python/tree_sitter_LOWER_PARSER_NAME/binding.c",
|
||||
"src/parser.c",
|
||||
]
|
||||
if path.exists("src/scanner.c"):
|
||||
sources.extend("src/scanner.c")
|
||||
|
||||
if system() != "Windows":
|
||||
cflags = ["-std=c11", "-fvisibility=hidden"]
|
||||
else:
|
||||
cflags = ["/std:c11", "/utf-8"]
|
||||
|
||||
|
||||
class Build(build):
|
||||
def run(self):
|
||||
if isdir("queries"):
|
||||
dest = join(self.build_lib, "tree_sitter_PARSER_NAME", "queries")
|
||||
if path.isdir("queries"):
|
||||
dest = path.join(self.build_lib, "tree_sitter_PARSER_NAME", "queries")
|
||||
self.copy_tree("queries", dest)
|
||||
super().run()
|
||||
|
||||
|
|
@ -33,18 +45,8 @@ setup(
|
|||
ext_modules=[
|
||||
Extension(
|
||||
name="_binding",
|
||||
sources=[
|
||||
"bindings/python/tree_sitter_LOWER_PARSER_NAME/binding.c",
|
||||
"src/parser.c",
|
||||
# NOTE: if your language uses an external scanner, add it here.
|
||||
],
|
||||
extra_compile_args=[
|
||||
"-std=c11",
|
||||
"-fvisibility=hidden",
|
||||
] if system() != "Windows" else [
|
||||
"/std:c11",
|
||||
"/utf-8",
|
||||
],
|
||||
sources=sources,
|
||||
extra_compile_args=cflags,
|
||||
define_macros=[
|
||||
("Py_LIMITED_API", "0x03090000"),
|
||||
("PY_SSIZE_T_CLEAN", None),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue