Skip to content

Commit

Permalink
(#22869) tree-sitter: add version 0.21.0
Browse files Browse the repository at this point in the history
* tree-sitter: add version 0.21.0

* use C11 on 0.21.0
  • Loading branch information
toge authored Feb 24, 2024
1 parent cea2b0c commit 9fce4eb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
19 changes: 12 additions & 7 deletions recipes/tree-sitter/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
cmake_minimum_required(VERSION 3.4)
project(tree-sitter C)
project(tree-sitter LANGUAGES C)

# Use cmake script instead of Makefile to support MSVC + follow fPIC option

file(GLOB SOURCES RELATIVE "${PROJECT_SOURCE_DIR}" src/lib/src/*.c)
list(REMOVE_ITEM SOURCES src/lib/src/lib.c)
file(GLOB SOURCES ${TREE_SITTER_SRC_DIR}/lib/src/*.c)
list(REMOVE_ITEM SOURCES ${TREE_SITTER_SRC_DIR}/lib/src/lib.c)

file(GLOB HEADERS src/lib/include/tree_sitter/*.h)
file(GLOB HEADERS ${TREE_SITTER_SRC_DIR}/lib/include/tree_sitter/*.h)

add_library(${PROJECT_NAME} ${SOURCES})
target_include_directories(${PROJECT_NAME}
PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/lib/include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/lib/src>
$<BUILD_INTERFACE:${TREE_SITTER_SRC_DIR}/lib/include>
$<BUILD_INTERFACE:${TREE_SITTER_SRC_DIR}/lib/src>
)
set_target_properties(${PROJECT_NAME}
PROPERTIES
C_STANDARD 99
PUBLIC_HEADER "${HEADERS}"
WINDOWS_EXPORT_ALL_SYMBOLS ON
)

if(TREE_SITTER_VERSION VERSION_LESS "0.21.0")
target_compile_features(${PROJECT_NAME} PRIVATE c_std_99)
else()
target_compile_features(${PROJECT_NAME} PRIVATE c_std_11)
endif()

include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
Expand Down
3 changes: 3 additions & 0 deletions recipes/tree-sitter/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"0.21.0":
url: "https://github.com/tree-sitter/tree-sitter/archive/refs/tags/v0.21.0.tar.gz"
sha256: "6bb60e5b63c1dc18aba57a9e7b3ea775b4f9ceec44cc35dac4634d26db4eb69c"
"0.20.8":
url: "https://github.com/tree-sitter/tree-sitter/archive/refs/tags/v0.20.8.tar.gz"
sha256: "6181ede0b7470bfca37e293e7d5dc1d16469b9485d13f13a605baec4a8b1f791"
Expand Down
10 changes: 7 additions & 3 deletions recipes/tree-sitter/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
from conan.tools.files import get, copy

required_conan_version = ">=1.53.0"
Expand All @@ -24,8 +24,6 @@ class TreeSitterConan(ConanFile):
"fPIC": True,
"shared": False,
}

generators = "CMakeToolchain"
exports_sources = "CMakeLists.txt"

def config_options(self):
Expand All @@ -44,6 +42,12 @@ def layout(self):
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["TREE_SITTER_SRC_DIR"] = self.source_folder.replace("\\", "/")
tc.variables["TREE_SITTER_VERSION"] = str(self.version)
tc.generate()

def build(self):
cmake = CMake(self)
cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir))
Expand Down
7 changes: 6 additions & 1 deletion recipes/tree-sitter/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)
project(test_package LANGUAGES C)

find_package(tree-sitter REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} tree-sitter::tree-sitter)
if(tree-sitter_VERSION VERSION_LESS "0.21.0")
target_compile_features(${PROJECT_NAME} PRIVATE c_std_99)
else()
target_compile_features(${PROJECT_NAME} PRIVATE c_std_11)
endif()
2 changes: 2 additions & 0 deletions recipes/tree-sitter/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"0.21.0":
folder: all
"0.20.8":
folder: all
"0.20.6":
Expand Down

0 comments on commit 9fce4eb

Please sign in to comment.