Skip to content

tree-sitter-glsl: Add new package #27350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions recipes/tree-sitter-glsl/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
cmake_minimum_required(VERSION 3.13)

project(tree-sitter-glsl
DESCRIPTION "GLSL grammar for tree-sitter"
HOMEPAGE_URL "https://github.com/tree-sitter-grammars/tree-sitter-glsl"
LANGUAGES C)

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
option(TREE_SITTER_REUSE_ALLOCATOR "Reuse the library allocator" OFF)

add_library(tree-sitter-glsl src/parser.c)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scanner.c)
target_sources(tree-sitter-glsl PRIVATE src/scanner.c)
endif()
target_include_directories(tree-sitter-glsl PRIVATE src)

target_compile_definitions(tree-sitter-glsl PRIVATE
$<$<BOOL:${TREE_SITTER_REUSE_ALLOCATOR}>:TREE_SITTER_REUSE_ALLOCATOR>
$<$<CONFIG:Debug>:TREE_SITTER_DEBUG>)

configure_file(bindings/c/tree-sitter-glsl.pc.in
"${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-glsl.pc" @ONLY)

include(GNUInstallDirs)

install(FILES bindings/c/tree-sitter-glsl.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tree_sitter")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-glsl.pc"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig")
install(TARGETS tree-sitter-glsl
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")

4 changes: 4 additions & 0 deletions recipes/tree-sitter-glsl/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"0.2.0":
url: "https://github.com/tree-sitter-grammars/tree-sitter-glsl/archive/refs/tags/v0.2.0.tar.gz"
sha256: "65d098362f9ffd47e9bf5916133ed24ccf934b01027debdaeeb46ff3ec41caf0"
73 changes: 73 additions & 0 deletions recipes/tree-sitter-glsl/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import get, copy

import os

required_conan_version = ">2.0"


class TreeSitterCConan(ConanFile):
name = "tree-sitter-glsl"
description = "GLSL grammar for tree-sitter."
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/tree-sitter-grammars/tree-sitter-glsl"
topics = ("parser", "grammar", "tree", "glsl", "ide")
settings = "os", "arch", "compiler", "build_type"
package_type = "library"

options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

def layout(self):
cmake_layout(self, src_folder="src")

def export_sources(self):
copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=os.path.join(self.export_sources_folder, "src"))

def generate(self):
tc = CMakeToolchain(self)
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def requirements(self):
self.requires("tree-sitter/0.25.1", transitive_headers=True, transitive_libs=True)

def build(self):
cmake = CMake(self)
cmake.configure()
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-glsl"]
7 changes: 7 additions & 0 deletions recipes/tree-sitter-glsl/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES C)

find_package(tree-sitter-glsl REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE tree-sitter-glsl::tree-sitter-glsl)
27 changes: 27 additions & 0 deletions recipes/tree-sitter-glsl/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout

import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
cmd = os.path.join(self.cpp.build.bindir, "test_package")
self.run(cmd, env="conanrun")
29 changes: 29 additions & 0 deletions recipes/tree-sitter-glsl/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <tree_sitter/api.h>

#include <tree_sitter/tree-sitter-glsl.h>

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

int main() {
TSParser *parser = ts_parser_new();
ts_parser_set_language(parser, tree_sitter_glsl());
const char *source_code = "vec2 Hammersley(uint i, uint N);";
TSTree *tree = ts_parser_parse_string(
parser,
NULL,
source_code,
strlen(source_code)
);
TSNode root_node = ts_tree_root_node(tree);

char *string = ts_node_string(root_node);
printf("Syntax tree: %s\n", string);
free(string);

ts_tree_delete(tree);
ts_parser_delete(parser);
return 0;
}

3 changes: 3 additions & 0 deletions recipes/tree-sitter-glsl/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.2.0":
folder: all