diff --git a/recipes/tree-sitter/all/conandata.yml b/recipes/tree-sitter/all/conandata.yml new file mode 100644 index 0000000000000..a6260e4dd3f92 --- /dev/null +++ b/recipes/tree-sitter/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "0.17.3": + url: https://github.com/tree-sitter/tree-sitter/archive/0.17.3.tar.gz + sha256: a897e5c9a7ccb74271d9b20d59121d2d2e9de8b896c4d1cfaac0f8104c1ef9f8 diff --git a/recipes/tree-sitter/all/conanfile.py b/recipes/tree-sitter/all/conanfile.py new file mode 100644 index 0000000000000..b74120affdfa0 --- /dev/null +++ b/recipes/tree-sitter/all/conanfile.py @@ -0,0 +1,65 @@ +import os +from conans import ConanFile, AutoToolsBuildEnvironment, tools +from conans.errors import ConanInvalidConfiguration +import shutil + +required_conan_version = ">=1.29.1" + +class TreeSitterConan(ConanFile): + name = "tree-sitter" + description = "Tree-sitter is a parser generator tool and an incremental parsing library. It can build a concrete syntax tree for a source file and efficiently update the syntax tree as the source file is edited." + topics = ("parser", "incremental", "rust") + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://tree-sitter.github.io/tree-sitter" + license = "MIT" + settings = "os", "compiler", "build_type", "arch" + options = {"fPIC": [True, False], + "shared": [True, False]} + default_options = {"fPIC": True, + "shared": False} + _autotools = None + + + @property + def _source_subfolder(self): + return "source_subfolder" + + def configure(self): + if self.settings.os == "Windows": + raise ConanInvalidConfiguration("tree-sitter is not support on {}.".format(self.settings.os)) + + def source(self): + tools.get(**self.conan_data["sources"][self.version]) + os.rename("{}-{}".format(self.name, self.version), self._source_subfolder) + + def _configure_autotools(self): + if not self._autotools: + self._autotools = AutoToolsBuildEnvironment(self) + + return self._autotools + + def build(self): + autotools = self._configure_autotools() + + with tools.chdir(self._source_subfolder): + autotools.make() + + def package(self): + self.copy("LICENSE", src=self._source_subfolder, dst="licenses") + + autotools = self._configure_autotools() + with tools.chdir(self._source_subfolder): + autotools.install(args=["PREFIX={}".format(self.package_folder)]) + + if self.options.shared: + tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.a") + else: + tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.so*") + tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.dylib*") + + tools.rmdir(os.path.join(self.package_folder, os.path.join("lib", "pkgconfig"))) + + + def package_info(self): + self.cpp_info.names["pkg_config"] = "tree-sitter" + self.cpp_info.libs = ["tree-sitter"] diff --git a/recipes/tree-sitter/all/test_package/CMakeLists.txt b/recipes/tree-sitter/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..34af13462f44f --- /dev/null +++ b/recipes/tree-sitter/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +add_executable(${PROJECT_NAME} test_package.c) +target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) diff --git a/recipes/tree-sitter/all/test_package/conanfile.py b/recipes/tree-sitter/all/test_package/conanfile.py new file mode 100644 index 0000000000000..a59ab6adf99d9 --- /dev/null +++ b/recipes/tree-sitter/all/test_package/conanfile.py @@ -0,0 +1,17 @@ +import os + +from conans import ConanFile, CMake, tools + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self.settings): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/tree-sitter/all/test_package/test_package.c b/recipes/tree-sitter/all/test_package/test_package.c new file mode 100644 index 0000000000000..0d59221b13437 --- /dev/null +++ b/recipes/tree-sitter/all/test_package/test_package.c @@ -0,0 +1,11 @@ +#include +#include + +//More datailed example search at https://tree-sitter.github.io/tree-sitter/using-parsers#getting-started +int main() { + TSParser *parser = ts_parser_new(); + ts_parser_delete(parser); + printf( "Test package\n" ); + return 0; +} + diff --git a/recipes/tree-sitter/config.yml b/recipes/tree-sitter/config.yml new file mode 100644 index 0000000000000..e150b71c816ff --- /dev/null +++ b/recipes/tree-sitter/config.yml @@ -0,0 +1,3 @@ +versions: + "0.17.3": + folder: all