{"id":32789055,"url":"https://github.com/zaccari/go-tree-sitter-bazel","last_synced_at":"2026-05-04T08:31:47.161Z","repository":{"id":322296699,"uuid":"1087397995","full_name":"zaccari/go-tree-sitter-bazel","owner":"zaccari","description":"Bazel bindings for go-tree-sitter","archived":false,"fork":false,"pushed_at":"2025-11-03T18:27:04.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-03T19:08:46.361Z","etag":null,"topics":["bazel","bazel-module","go","tree-sitter"],"latest_commit_sha":null,"homepage":"","language":"Starlark","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zaccari.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-31T20:58:13.000Z","updated_at":"2025-11-03T18:24:09.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/zaccari/go-tree-sitter-bazel","commit_stats":null,"previous_names":["zaccari/go-tree-sitter-bazel"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/zaccari/go-tree-sitter-bazel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaccari%2Fgo-tree-sitter-bazel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaccari%2Fgo-tree-sitter-bazel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaccari%2Fgo-tree-sitter-bazel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaccari%2Fgo-tree-sitter-bazel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zaccari","download_url":"https://codeload.github.com/zaccari/go-tree-sitter-bazel/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaccari%2Fgo-tree-sitter-bazel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":282799912,"owners_count":26729199,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-05T02:00:05.946Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bazel","bazel-module","go","tree-sitter"],"created_at":"2025-11-05T10:00:16.086Z","updated_at":"2025-11-05T10:00:19.043Z","avatar_url":"https://github.com/zaccari.png","language":"Starlark","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go_tree_sitter Bazel Module\n\nA Bazel module providing [go_tree_sitter][1] bindings for use in Bazel\nprojects. This module handles the complexities of building the tree-sitter C\nlibrary and Go bindings together using Bazel's modern module system (bzlmod).\n\n## Features\n\n- 🚀 Easy integration with Bazel projects using `bazel_dep`\n- 🔧 Automatic management of tree-sitter C library compilation\n- 📦 Includes all upstream go_tree_sitter dependencies\n- 🎯 Support for all tree-sitter language parsers (C, C++, Go, Java,\n     JavaScript, JSON, PHP, Python, Ruby, Rust, HTML, and more)\n- ⚡  Uses Bazel's modern module system (bzlmod)\n\n## Requirements\n\n- Bazel 8.4.2 or higher\n- A C11-compatible compiler\n- Go 1.25.3 or higher (automatically managed by rules_go)\n\n## Installation\n\nAdd this module to your `MODULE.bazel` file:\n\n```starlark\nbazel_dep(name = \"go_tree_sitter\", version = \"0.25.0\")\ngit_override(\n    module_name = \"go_tree_sitter\",\n    remote = \"https://github.com/zaccari/go-tree-sitter-bazel.git\",\n    commit = \"\u003ccommit-sha\u003e\",\n)\n```\n\nNote: BCR does not currently recommend hosting go modules.\n\n## Usage\n\nOnce added to your `MODULE.bazel`, you can use go_tree_sitter in your Go code:\n\n### In your BUILD.bazel file\n\n```starlark\nload(\"@rules_go//go:def.bzl\", \"go_binary\", \"go_library\")\n\ngo_library(\n    name = \"mylib\",\n    srcs = [\"mycode.go\"],\n    importpath = \"github.com/yourorg/yourproject/mylib\",\n    deps = [\n        \"@go_tree_sitter//:go_tree_sitter\",\n        # Add language-specific parsers as needed\n        \"@com_github_tree_sitter_tree_sitter_go//:go\",\n        \"@com_github_tree_sitter_tree_sitter_python//:python\",\n    ],\n)\n```\n\n### In your Go code\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    tree_sitter \"github.com/tree-sitter/go-tree-sitter\"\n    tree_sitter_go \"github.com/tree-sitter/tree-sitter-go/bindings/go\"\n)\n\nfunc main() {\n    // Create a parser\n    parser := tree_sitter.NewParser()\n    defer parser.Close()\n\n    // Set the language\n    parser.SetLanguage(tree_sitter.NewLanguage(tree_sitter_go.Language()))\n\n    // Parse some code\n    sourceCode := []byte(\"package main\\n\\nfunc main() {}\")\n    tree := parser.Parse(sourceCode, nil)\n    defer tree.Close()\n\n    // Work with the syntax tree\n    root := tree.RootNode()\n    fmt.Printf(\"Syntax tree: %s\\n\", root.String())\n}\n```\n\n## Available Language Parsers\n\nThis module includes dependencies for the following tree-sitter language parsers:\n\n- C\n- C++\n- Go\n- Java\n- JavaScript\n- JSON\n- PHP\n- Python\n- Ruby\n- Rust\n- HTML\n- Embedded Template\n\nAll parsers are available as dependencies through the module's go_deps extension.\n\n## Building from Source\n\n```bash\n# Build the module\nbazelisk build //:go_tree_sitter\n\n# Query all targets\nbazelisk query //...\n```\n\nOr use the Makefile:\n\n```bash\nmake build  # Build the library\nmake query  # Query all targets\nmake help   # Show all available targets\n```\n\n## How It Works\n\nThis module uses a Bazel module extension to:\n\n1. Fetch the upstream go_tree_sitter source code from GitHub\n2. Apply a small patch to make the code Bazel-compatible (removes the `lib.c`\n   inclusion from CGo directives)\n3. Build the tree-sitter C library separately\n4. Link the Go bindings against the C library using CGo\n\nThe separation of the C library build from the Go build is necessary because\nthe upstream code includes `lib.c` in the CGo directives, which conflicts with\nBazel's compilation model.\n\n## Version Mapping\n\nThis module's version tracks the upstream go_tree_sitter version:\n\n| Module Version | go_tree_sitter Version | Notes |\n|----------------|------------------------|-------|\n| 0.25.0         | 0.25 (branch)          | Tracking branch until v0.25.0 tag is released |\n\n## Technical Details\n\n### Patch File\n\nThe module applies a minimal patch (`tree_sitter.go.patch`) to the upstream\nsource to remove the `#include \"lib.c\"` directive, which would cause build\nconflicts in Bazel. Instead, the C library is built separately as a\n`cc_library` target and linked via the `cdeps` attribute.\n\n### Module Structure\n\n- `MODULE.bazel` - Module definition and dependencies\n- `extensions.bzl` - Module extension for fetching upstream source\n- `version.bzl` - Version constants and integrity hashes\n- `BUILD.bazel` - Main build file with public alias\n- `BUILD.upstream` - Build rules for upstream go_tree_sitter source\n- `tree_sitter.go.patch` - Compatibility patch for Bazel builds\n\n## Contributing\n\nContributions are welcome! Please feel free to submit issues or pull requests.\n\n### Updating to a New Upstream Version\n\n1. Update `GO_TREE_SITTER_VERSION` in `version.bzl`\n2. Run `./print_sha.bash` to compute the new integrity hash\n3. Update `GO_TREE_SITTER_INTEGRITY` in `version.bzl`\n4. Test the build: `bazelisk build //:go_tree_sitter`\n5. Update `CHANGELOG.md` with the new version\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE)\nfile for details.\n\nThe upstream [go_tree_sitter](https://github.com/tree-sitter/go-tree-sitter)\nproject is also licensed under the MIT License.\n\n## Acknowledgments\n\n- [tree-sitter][2] - The underlying parsing library\n- [go_tree_sitter][1] - Go bindings for tree-sitter\n- [rules_go][3] - Bazel rules for Go\n\n## Resources\n\n- [go_tree_sitter Documentation](https://github.com/tree-sitter/go-tree-sitter)\n- [tree-sitter Documentation](https://tree-sitter.github.io/tree-sitter/)\n- [Bazel Documentation](https://bazel.build/)\n- [rules_go Documentation](https://github.com/bazelbuild/rules_go/blob/master/docs/go/core/bzlmod.md)\n\n[1]: https://github.com/tree-sitter/go-tree-sitter\n[2]: https://tree-sitter.github.io/tree-sitter/\n[3]: https://github.com/bazelbuild/rules_go\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaccari%2Fgo-tree-sitter-bazel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzaccari%2Fgo-tree-sitter-bazel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaccari%2Fgo-tree-sitter-bazel/lists"}