From c38ee2a2ab53e82f40c53d3346b29e9588eca5cd Mon Sep 17 00:00:00 2001 From: toge Date: Wed, 13 Nov 2024 23:06:57 +0900 Subject: [PATCH] tree-sitter-cql: add recipe (#25867) Co-authored-by: PerseoGI Co-authored-by: Uilian Ries --- recipes/tree-sitter-cql/all/CMakeLists.txt | 29 ++++++++ recipes/tree-sitter-cql/all/conandata.yml | 4 ++ recipes/tree-sitter-cql/all/conanfile.py | 70 +++++++++++++++++++ .../all/test_package/CMakeLists.txt | 7 ++ .../all/test_package/conanfile.py | 26 +++++++ .../all/test_package/test_package.c | 10 +++ recipes/tree-sitter-cql/config.yml | 3 + 7 files changed, 149 insertions(+) create mode 100644 recipes/tree-sitter-cql/all/CMakeLists.txt create mode 100644 recipes/tree-sitter-cql/all/conandata.yml create mode 100644 recipes/tree-sitter-cql/all/conanfile.py create mode 100644 recipes/tree-sitter-cql/all/test_package/CMakeLists.txt create mode 100644 recipes/tree-sitter-cql/all/test_package/conanfile.py create mode 100644 recipes/tree-sitter-cql/all/test_package/test_package.c create mode 100644 recipes/tree-sitter-cql/config.yml diff --git a/recipes/tree-sitter-cql/all/CMakeLists.txt b/recipes/tree-sitter-cql/all/CMakeLists.txt new file mode 100644 index 0000000000000..c382967b7491f --- /dev/null +++ b/recipes/tree-sitter-cql/all/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.15) +project(tree-sitter-cql LANGUAGES C) + +find_package(tree-sitter REQUIRED CONFIG) + +add_library(${PROJECT_NAME} + "${CMAKE_CURRENT_SOURCE_DIR}/src/src/parser.c" +) +target_link_libraries(${PROJECT_NAME} + PUBLIC + tree-sitter::tree-sitter +) +target_include_directories(${PROJECT_NAME} + PRIVATE + $ +) +set_target_properties(${PROJECT_NAME} + PROPERTIES + C_STANDARD 99 + PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/src/bindings/c/tree-sitter-cql.h" +) + +include(GNUInstallDirs) +install(TARGETS ${PROJECT_NAME} + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) diff --git a/recipes/tree-sitter-cql/all/conandata.yml b/recipes/tree-sitter-cql/all/conandata.yml new file mode 100644 index 0000000000000..ceb9f8a016e2a --- /dev/null +++ b/recipes/tree-sitter-cql/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "0.2.0": + url: "https://github.com/shotover/tree-sitter-cql/archive/refs/tags/v0.2.0.tar.gz" + sha256: "fc5aa2c660b6e6daa48e14b4bb7aca0a5a69294229bfae4fdcd9761d288edf07" diff --git a/recipes/tree-sitter-cql/all/conanfile.py b/recipes/tree-sitter-cql/all/conanfile.py new file mode 100644 index 0000000000000..0a3e600138c67 --- /dev/null +++ b/recipes/tree-sitter-cql/all/conanfile.py @@ -0,0 +1,70 @@ +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.files import get, copy +from conan.tools.microsoft import is_msvc +import os + +required_conan_version = ">=2.0.9" + + +class TreeSitterCQLConan(ConanFile): + name = "tree-sitter-cql" + description = "Tree-sitter parser for Cassandra CQL language" + license = "MIT" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/shotover/tree-sitter-cql" + topics = ("parser", "grammar", "tree", "CQL", "cassandra") + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } + implements = ["auto_shared_fpic"] + + def export_sources(self): + copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder) + + def configure(self): + self.settings.rm_safe("compiler.cppstd") + self.settings.rm_safe("compiler.libcxx") + + def layout(self): + cmake_layout(self, src_folder="src") + + def requirements(self): + self.requires("tree-sitter/0.24.3", transitive_headers=True, transitive_libs=True) + + def generate(self): + tc = CMakeToolchain(self) + if is_msvc(self): + tc.variables.preprocessor_definitions["TREE_SITTER_HIDE_SYMBOLS"] = not self.options.shared + tc.generate() + deps = CMakeDeps(self) + deps.generate() + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def build(self): + cmake = CMake(self) + cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir)) + cmake.build() + + def package(self): + copy( + self, + "LICENSE", + src=self.source_folder, + dst=os.path.join(self.package_folder, "licenses"), + ) + cmake = CMake(self) + cmake.install() + + def package_info(self): + self.cpp_info.libs = ["tree-sitter-cql"] + self.cpp_info.set_property("pkg_config_name", "tree-sitter-cql") diff --git a/recipes/tree-sitter-cql/all/test_package/CMakeLists.txt b/recipes/tree-sitter-cql/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..802cad95e018c --- /dev/null +++ b/recipes/tree-sitter-cql/all/test_package/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES C) + +find_package(tree-sitter-cql REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE tree-sitter-cql::tree-sitter-cql) diff --git a/recipes/tree-sitter-cql/all/test_package/conanfile.py b/recipes/tree-sitter-cql/all/test_package/conanfile.py new file mode 100644 index 0000000000000..cb81bc4873df8 --- /dev/null +++ b/recipes/tree-sitter-cql/all/test_package/conanfile.py @@ -0,0 +1,26 @@ + +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeToolchain", "CMakeDeps" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/tree-sitter-cql/all/test_package/test_package.c b/recipes/tree-sitter-cql/all/test_package/test_package.c new file mode 100644 index 0000000000000..5972b3828b0bb --- /dev/null +++ b/recipes/tree-sitter-cql/all/test_package/test_package.c @@ -0,0 +1,10 @@ +#include +#include + +int main() { + TSParser *parser = ts_parser_new(); + ts_parser_set_language(parser, tree_sitter_cql()); + ts_parser_delete(parser); + return 0; +} + diff --git a/recipes/tree-sitter-cql/config.yml b/recipes/tree-sitter-cql/config.yml new file mode 100644 index 0000000000000..b370fcee5fe7c --- /dev/null +++ b/recipes/tree-sitter-cql/config.yml @@ -0,0 +1,3 @@ +versions: + "0.2.0": + folder: all