[tree-sitter-c,vcpkg-tool-tree-sitter] New ports (#44761)

This commit is contained in:
Kai Pastor 2025-04-04 20:09:17 +02:00 committed by GitHub
parent 566770a4b4
commit c026da0e82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 272 additions and 0 deletions

View File

@ -0,0 +1,23 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e6a23ee..f45024d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,15 +41,15 @@ set_target_properties(tree-sitter-c
SOVERSION "${TREE_SITTER_ABI_VERSION}.${PROJECT_VERSION_MAJOR}"
DEFINE_SYMBOL "")
+include(GNUInstallDirs)
+
configure_file(bindings/c/tree-sitter-c.pc.in
"${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-c.pc" @ONLY)
-include(GNUInstallDirs)
-
install(FILES bindings/c/tree-sitter-c.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tree_sitter")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-c.pc"
- DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig")
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
install(TARGETS tree-sitter-c
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")

View File

@ -0,0 +1,26 @@
if(VCPKG_TARGET_IS_WINDOWS)
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
endif()
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO tree-sitter/tree-sitter-c
REF "v${VERSION}"
SHA512 76022e55c613901e6c58d08e425aa0d527027d0130ce6bed2c5f83cd9056a8bdfef7af73ccd5df056b03515a9a733d64759b37766ccaa994f757c8e5c51b9a74
HEAD_REF master
PATCHES
pkgconfig.diff
)
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
"-DTREE_SITTER_CLI=${CURRENT_HOST_INSTALLED_DIR}/tools/tree-sitter-cli/tree-sitter${VCPKG_HOST_EXECUTABLE_SUFFIX}"
-DTREE_SITTER_REUSE_ALLOCATOR=ON
)
vcpkg_cmake_install()
vcpkg_fixup_pkgconfig()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")

View File

@ -0,0 +1,18 @@
{
"name": "tree-sitter-c",
"version": "0.23.5",
"description": "C grammar for tree-sitter",
"homepage": "https://github.com/tree-sitter/tree-sitter-c",
"license": "MIT",
"dependencies": [
"tree-sitter",
{
"name": "tree-sitter-cli",
"host": true
},
{
"name": "vcpkg-cmake",
"host": true
}
]
}

View File

@ -0,0 +1,104 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
set(key NOTFOUND)
if(VCPKG_CMAKE_SYSTEM_NAME)
set(key "${VCPKG_CMAKE_SYSTEM_NAME}-${VCPKG_TARGET_ARCHITECTURE}")
elseif(VCPKG_TARGET_IS_WINDOWS)
set(key "Windows-${VCPKG_TARGET_ARCHITECTURE}")
endif()
vcpkg_download_distfile(license
URLS "https://github.com/tree-sitter/tree-sitter/raw/refs/tags/v${VERSION}/LICENSE"
FILENAME "tree-sitter-v${VERSION}-LICENSE"
SHA512 50781942281117c409cd4fe79b18314bf26560107e13539bfd8f1e5ded538ab7e00b8e7e665dbc6acb69a6ca524d1a3a5ef2fb3d0156aa0984f68c178d6aeb6e
)
set(archive_path NOTFOUND)
# For convenient updates, use
# vcpkg install tree-sitter-cli --cmake-args=-DVCPKG_TREE_SITTER_UPDATE=1
if(key STREQUAL "Linux-arm64" OR VCPKG_TREE_SITTER_UPDATE)
set(filename "tree-sitter-${VERSION}-linux-arm64.gz")
vcpkg_download_distfile(archive_path
URLS "https://github.com/tree-sitter/tree-sitter/releases/download/v${VERSION}/tree-sitter-linux-arm64.gz"
FILENAME "${filename}"
SHA512 749578d0d9928ae0da5b030df67e76bd548623cda1317316ac6c2a9025ae1c0d5ca2843e88b10b9b900dc39419099a4234ad67fd93b422a4f9a280f80523a47e
)
endif()
if(key STREQUAL "Linux-x64" OR VCPKG_TREE_SITTER_UPDATE)
set(filename "tree-sitter-${VERSION}-linux-x64.gz")
vcpkg_download_distfile(archive_path
URLS "https://github.com/tree-sitter/tree-sitter/releases/download/v${VERSION}/tree-sitter-linux-x64.gz"
FILENAME "${filename}"
SHA512 29f9b5890338d9b37adaa2112daabe66dca999a5bbc1e47853481fcd388c0676b38d6134dab614e683c0b9c793f1b8036f09999abbc744a9ccecdbdf4943873b
)
endif()
if(key STREQUAL "Darwin-arm64" OR VCPKG_TREE_SITTER_UPDATE)
set(filename "tree-sitter-${VERSION}-macos-arm64.gz")
vcpkg_download_distfile(archive_path
URLS "https://github.com/tree-sitter/tree-sitter/releases/download/v${VERSION}/tree-sitter-macos-arm64.gz"
FILENAME "${filename}"
SHA512 393580273793c8d376aea46ea2f73f224e442729b89985541371986123f1dc396e70310ab3eb213ae8eb1432633c3605d228296aac2545bd269583ef103949f2
)
# Avoid breaking the code signature.
set(VCPKG_FIXUP_MACHO_RPATH OFF)
endif()
if(key STREQUAL "Darwin-x64" OR VCPKG_TREE_SITTER_UPDATE)
set(filename "tree-sitter-${VERSION}-macos-x64.gz")
vcpkg_download_distfile(archive_path
URLS "https://github.com/tree-sitter/tree-sitter/releases/download/v${VERSION}/tree-sitter-macos-x64.gz"
FILENAME "${filename}"
SHA512 5d9267b02b254377a508685ee3b522c5f186cc65aae4ae2d0099effeb3a8296a208e97fbf0fec77cd75b0c6427bc3d27beafd83bfe4776ec3345b87cd088c687
)
# Avoid breaking the code signature.
set(VCPKG_FIXUP_MACHO_RPATH OFF)
endif()
if(key STREQUAL "Windows-arm64" OR VCPKG_TREE_SITTER_UPDATE)
set(filename "tree-sitter-${VERSION}-windows-arm64.gz")
vcpkg_download_distfile(archive_path
URLS "https://github.com/tree-sitter/tree-sitter/releases/download/v${VERSION}/tree-sitter-windows-arm64.gz"
FILENAME "${filename}"
SHA512 07a2b8e0f2325b83e543e76a2ff4f248c230bad51486f870b1c0e856bca9aa4ac04d70b66535ef517bfa184b55081b3b5a78b07532a3ae750195579f45621d6d
)
endif()
if(key STREQUAL "Windows-x64" OR VCPKG_TREE_SITTER_UPDATE)
set(filename "tree-sitter-${VERSION}-windows-x64.gz")
vcpkg_download_distfile(archive_path
URLS "https://github.com/tree-sitter/tree-sitter/releases/download/v${VERSION}/tree-sitter-windows-x64.gz"
FILENAME "${filename}"
SHA512 dd51eef2b0ca9d372ed0b66acb9b079a46a623adccffd1af40bbad9330b8caac71716f6163a98f6972ca26be1254978dc22b843b9b827a7420e074b8789d7f7e
)
endif()
if(NOT archive_path)
message(FATAL_ERROR "Unsupported platform '${key}'. Please implement me!")
endif()
if(VCPKG_TREE_SITTER_UPDATE)
message(STATUS "All downloads are up-to-date.")
message(FATAL_ERROR "Stopping due to VCPKG_TREE_SITTER_UPDATE being enabled.")
endif()
file(COPY "${archive_path}" DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}")
cmake_path(GET archive_path FILENAME archive_name)
set(gunzip_command_line gunzip "${archive_name}")
if(CMAKE_HOST_WIN32)
vcpkg_acquire_msys(MSYS_ROOT)
vcpkg_host_path_list(APPEND ENV{PATH} "${MSYS_ROOT}/usr/bin")
set(gunzip_command_line sh -c "gunzip '${archive_name}'")
endif()
vcpkg_execute_required_process(
ALLOW_IN_DOWNLOAD_MODE
COMMAND ${gunzip_command_line}
WORKING_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/${PORT}"
LOGNAME "gunzip-${TARGET_TRIPLET}"
)
string(REGEX REPLACE "[.]gz\$" "" tool_name "${archive_name}")
file(RENAME "${CURRENT_PACKAGES_DIR}/tools/${PORT}/${tool_name}" "${CURRENT_PACKAGES_DIR}/tools/${PORT}/tree-sitter${VCPKG_HOST_EXECUTABLE_SUFFIX}")
file(CHMOD "${CURRENT_PACKAGES_DIR}/tools/${PORT}/tree-sitter${VCPKG_HOST_EXECUTABLE_SUFFIX}"
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
vcpkg_install_copyright(FILE_LIST "${license}"
COMMENT [[
Tree-sitter is licensed under the MIT license. The tree-sitter CLI uses
third-party components which are not listed individually here.
]])

View File

@ -0,0 +1,8 @@
{
"name": "tree-sitter-cli",
"version": "0.25.3",
"description": "Tree-sitter is a parser generator tool and an incremental parsing library. This port installs the CLI executable.",
"homepage": "https://github.com/tree-sitter/tree-sitter",
"license": null,
"supports": "native"
}

View File

@ -0,0 +1,10 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
vcpkg_find_acquire_program(PKGCONFIG)
vcpkg_cmake_configure(
SOURCE_PATH "${CURRENT_PORT_DIR}/project"
OPTIONS
"-DPKG_CONFIG_EXECUTABLE=${PKGCONFIG}"
)
vcpkg_cmake_build()

View File

@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.30)
project(tree-sitter-test C)
find_package(PkgConfig REQUIRED)
pkg_check_modules(tree-sitter_pc tree-sitter REQUIRED IMPORTED_TARGET)
pkg_check_modules(tree-sitter-c_pc tree-sitter-c REQUIRED IMPORTED_TARGET)
add_executable(main-pkconfig main.c)
target_link_libraries(main-pkconfig PRIVATE
PkgConfig::tree-sitter_pc
PkgConfig::tree-sitter-c_pc
)

View File

@ -0,0 +1,21 @@
#include <stdio.h>
#include <string.h>
#include <tree_sitter/api.h>
#include <tree_sitter/tree-sitter-c.h>
int main()
{
TSParser *parser = ts_parser_new();
ts_parser_set_language(parser, tree_sitter_c());
const char *source_code = "int main() { return -1; }\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;
}

View File

@ -0,0 +1,15 @@
{
"name": "vcpkg-ci-tree-sitter",
"version-string": "ci",
"description": "Port to test the tree-sitter group of port in CI",
"homepage": "https://github.com/microsoft/vcpkg",
"license": "MIT",
"dependencies": [
"tree-sitter",
"tree-sitter-c",
{
"name": "vcpkg-cmake",
"host": true
}
]
}

View File

@ -9392,6 +9392,14 @@
"baseline": "0.25.3",
"port-version": 0
},
"tree-sitter-c": {
"baseline": "0.23.5",
"port-version": 0
},
"tree-sitter-cli": {
"baseline": "0.25.3",
"port-version": 0
},
"treehh": {
"baseline": "3.18",
"port-version": 0

View File

@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "c328547f974b97d7181e603d82c66c8cf34a4e2d",
"version": "0.23.5",
"port-version": 0
}
]
}

View File

@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "73f51ab723ad9a1228e7c533eb824ddd2066d24a",
"version": "0.25.3",
"port-version": 0
}
]
}

View File

@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "d4a7088a9ec363083e503cb10bacdeb4ab8ab7a6",
"version": "0.25.3",
"port-version": 0
}
]
}