Skip to content

refactor: switch to official go tree-sitter implementation #2952

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 2 commits into
base: main
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
13 changes: 12 additions & 1 deletion gazelle/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,25 @@ local_path_override(

go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
go_deps.module_override(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is, sadly, a blocker because overrides cannot be used in non-root modules.

If this is included, then no one can add the dep via:

# MODULE.bazel
bazel_dep(name = "rules_python_gazelle_plugin")

As it will fail with:

Using the "go_deps.{tag_class}" tag in a non-root Bazel module is forbidden

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can fork that library as well if you want, or ask users to add these 3 lines themselves. I'm just opening this PR to suggest using the modern go-tree-sitter library...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm 100% for using the modern go-tree-sitter library. I just think we are blocked from doing so until bazel-contrib/rules_go#4298 is released and we update our rules_go version.

Otherwise we get stuck in the "users must apply a patch themselves" or "we have to maintain a fork" situation that we're already in.

I think the path forward is:

  1. Wait for rules_go to release the fix.
  2. Update rules_go
  3. Remove the dougthor42/go-tree-sitter hack and go back to smacker/go-tree-sitter
  4. Migrate to the official tree-sitter repos.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think bazel-contrib/rules_go#4298 fixes every scenario. After upgrading to rules_go@HEAD I was able to remove my patch to smacker/go-tree-sitter, but when switching to tree-sitter/go-tree-sitter I had to add almost the same patch again 😢

patches = ["//patches:go-tree-sitter-cc_library.patch"],
path = "github.com/tree-sitter/go-tree-sitter",
patch_strip = 1,
)
go_deps.module_override(
path = "github.com/tree-sitter/tree-sitter-python",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One alternative to patching the tree-sitter-* libraries (with the bindings/go/bindings.go file) is generating a single BUILD ourselves like what I've done in the aspect-cli, see the http fetch+BUILD and associated go.

That's probably nicer then a patch now that I look at it again...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using go modules works better when mixing go modules across multiple modules though, such as multiple gazelle languages from different modules. But that requires the patches :/

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making the BUILD file ourselves is basically what the dougthor42/go-tree-sitter does.

Does manually setting http_archive.build_file_content work with both WORKSPACE and bzlmod? If so that might be a way forward. I agree it's cleaner than the patches.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only for the tree-sitter-{lang}/bindings/go/bindings.go files, not the main go-tree-sitter go module that has the bigger problem.

patches = ["//patches:tree-sitter-python-cc_library.patch"],
patch_strip = 1,
)
use_repo(
go_deps,
"com_github_bazelbuild_buildtools",
"com_github_bmatcuk_doublestar_v4",
"com_github_dougthor42_go_tree_sitter",
"com_github_emirpasic_gods",
"com_github_ghodss_yaml",
"com_github_stretchr_testify",
"com_github_tree_sitter_go_tree_sitter",
"com_github_tree_sitter_tree_sitter_python",
"in_gopkg_yaml_v2",
"org_golang_x_sync",
)
Expand Down
104 changes: 96 additions & 8 deletions gazelle/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ def go_deps():
sum = "h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=",
version = "v0.5.9",
)
go_repository(
name = "com_github_mattn_go_pointer",
importpath = "github.com/mattn/go-pointer",
sum = "h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o0=",
version = "v0.0.1",
)

go_repository(
name = "com_github_pmezard_go_difflib",
importpath = "github.com/pmezard/go-difflib",
Expand All @@ -182,12 +189,7 @@ def go_deps():
sum = "h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM=",
version = "v0.0.0-20190812154241-14fe0d1b01d4",
)
go_repository(
name = "com_github_dougthor42_go_tree_sitter",
importpath = "github.com/dougthor42/go-tree-sitter",
sum = "h1:b9s96BulIARx0konX36sJ5oZhWvAvjQBBntxp1eUukQ=",
version = "v0.0.0-20241210060307-2737e1d0de6b",
)

go_repository(
name = "com_github_stretchr_objx",
importpath = "github.com/stretchr/objx",
Expand All @@ -197,8 +199,94 @@ def go_deps():
go_repository(
name = "com_github_stretchr_testify",
importpath = "github.com/stretchr/testify",
sum = "h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=",
version = "v1.9.0",
sum = "h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=",
version = "v1.10.0",
)
go_repository(
name = "com_github_tree_sitter_go_tree_sitter",
importpath = "github.com/tree-sitter/go-tree-sitter",
sum = "h1:sx6kcg8raRFCvc9BnXglke6axya12krCJF5xJ2sftRU=",
version = "v0.25.0",
patches = [
"//patches:go-tree-sitter-cc_library.patch", # keep
],
patch_strip = 1, # keep
)
go_repository(
name = "com_github_tree_sitter_tree_sitter_c",
importpath = "github.com/tree-sitter/tree-sitter-c",
sum = "h1:nBPH3FV07DzAD7p0GfNvXM+Y7pNIoPenQWBpvM++t4c=",
version = "v0.23.4",
)
go_repository(
name = "com_github_tree_sitter_tree_sitter_cpp",
importpath = "github.com/tree-sitter/tree-sitter-cpp",
sum = "h1:LaWZsiqQKvR65yHgKmnaqA+uz6tlDJTJFCyFIeZU/8w=",
version = "v0.23.4",
)
go_repository(
name = "com_github_tree_sitter_tree_sitter_embedded_template",
importpath = "github.com/tree-sitter/tree-sitter-embedded-template",
sum = "h1:nFkkH6Sbe56EXLmZBqHHcamTpmz3TId97I16EnGy4rg=",
version = "v0.23.2",
)
go_repository(
name = "com_github_tree_sitter_tree_sitter_go",
importpath = "github.com/tree-sitter/tree-sitter-go",
sum = "h1:yt5KMGnTHS+86pJmLIAZMWxukr8W7Ae1STPvQUuNROA=",
version = "v0.23.4",
)
go_repository(
name = "com_github_tree_sitter_tree_sitter_html",
importpath = "github.com/tree-sitter/tree-sitter-html",
sum = "h1:1UYDV+Yd05GGRhVnTcbP58GkKLSHHZwVaN+lBZV11Lc=",
version = "v0.23.2",
)
go_repository(
name = "com_github_tree_sitter_tree_sitter_java",
importpath = "github.com/tree-sitter/tree-sitter-java",
sum = "h1:J9YeMGMwXYlKSP3K4Us8CitC6hjtMjqpeOf2GGo6tig=",
version = "v0.23.5",
)
go_repository(
name = "com_github_tree_sitter_tree_sitter_javascript",
importpath = "github.com/tree-sitter/tree-sitter-javascript",
sum = "h1:1fWupaRC0ArlHJ/QJzsfQ3Ibyopw7ZfQK4xXc40Zveo=",
version = "v0.23.1",
)
go_repository(
name = "com_github_tree_sitter_tree_sitter_json",
importpath = "github.com/tree-sitter/tree-sitter-json",
sum = "h1:tV5rMkihgtiOe14a9LHfDY5kzTl5GNUYe6carZBn0fQ=",
version = "v0.24.8",
)
go_repository(
name = "com_github_tree_sitter_tree_sitter_php",
importpath = "github.com/tree-sitter/tree-sitter-php",
sum = "h1:iHewsLNDmznh8kgGyfWfujsZxIz1YGbSd2ZTEM0ZiP8=",
version = "v0.23.11",
)
go_repository(
name = "com_github_tree_sitter_tree_sitter_python",
importpath = "github.com/tree-sitter/tree-sitter-python",
sum = "h1:qHnWFR5WhtMQpxBZRwiaU5Hk/29vGju6CVtmvu5Haas=",
version = "v0.23.6",
patches = [
"//patches:tree-sitter-python-cc_library.patch", # keep
],
patch_strip = 1, # keep
)
go_repository(
name = "com_github_tree_sitter_tree_sitter_ruby",
importpath = "github.com/tree-sitter/tree-sitter-ruby",
sum = "h1:T/NKHUA+iVbHM440hFx+lzVOzS4dV6z8Qw8ai+72bYo=",
version = "v0.23.1",
)
go_repository(
name = "com_github_tree_sitter_tree_sitter_rust",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need all of the non-python languages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it needs any of them, but they are there, I think just for tests AFAICT.

I don't think we should care. That's how go.mod works, and deps.bzl is how (legacy) rules_go works.

importpath = "github.com/tree-sitter/tree-sitter-rust",
sum = "h1:6AtoooCW5GqNrRpfnvl0iUhxTAZEovEmLKDbyHlfw90=",
version = "v0.23.2",
)

go_repository(
Expand Down
6 changes: 4 additions & 2 deletions gazelle/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ require (
github.com/bazelbuild/buildtools v0.0.0-20231103205921-433ea8554e82
github.com/bazelbuild/rules_go v0.41.0
github.com/bmatcuk/doublestar/v4 v4.7.1
github.com/dougthor42/go-tree-sitter v0.0.0-20241210060307-2737e1d0de6b
github.com/emirpasic/gods v1.18.1
github.com/ghodss/yaml v1.0.0
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
github.com/tree-sitter/go-tree-sitter v0.25.0
github.com/tree-sitter/tree-sitter-python v0.23.6
golang.org/x/sync v0.2.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/mattn/go-pointer v0.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
Expand Down
36 changes: 30 additions & 6 deletions gazelle/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ github.com/bazelbuild/buildtools v0.0.0-20231103205921-433ea8554e82 h1:HTepWP/jh
github.com/bazelbuild/buildtools v0.0.0-20231103205921-433ea8554e82/go.mod h1:689QdV3hBP7Vo9dJMmzhoYIyo/9iMhEmHkJcnaPRCbo=
github.com/bazelbuild/rules_go v0.41.0 h1:JzlRxsFNhlX+g4drDRPhIaU5H5LnI978wdMJ0vK4I+k=
github.com/bazelbuild/rules_go v0.41.0/go.mod h1:TMHmtfpvyfsxaqfL9WnahCsXMWDMICTw7XeK9yVb+YU=
github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I=
github.com/bmatcuk/doublestar/v4 v4.6.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/bmatcuk/doublestar/v4 v4.7.1 h1:fdDeAqgT47acgwd9bd9HxJRDmc9UAmPpc+2m0CXv75Q=
github.com/bmatcuk/doublestar/v4 v4.7.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand All @@ -17,8 +15,6 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dougthor42/go-tree-sitter v0.0.0-20241210060307-2737e1d0de6b h1:b9s96BulIARx0konX36sJ5oZhWvAvjQBBntxp1eUukQ=
github.com/dougthor42/go-tree-sitter v0.0.0-20241210060307-2737e1d0de6b/go.mod h1:87UkDyPt18bTH/FvinLc/kj587VNYOdRKZT1la4T8Hg=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand All @@ -44,11 +40,39 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/mattn/go-pointer v0.0.1 h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o0=
github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tree-sitter/go-tree-sitter v0.25.0 h1:sx6kcg8raRFCvc9BnXglke6axya12krCJF5xJ2sftRU=
github.com/tree-sitter/go-tree-sitter v0.25.0/go.mod h1:r77ig7BikoZhHrrsjAnv8RqGti5rtSyvDHPzgTPsUuU=
github.com/tree-sitter/tree-sitter-c v0.23.4 h1:nBPH3FV07DzAD7p0GfNvXM+Y7pNIoPenQWBpvM++t4c=
github.com/tree-sitter/tree-sitter-c v0.23.4/go.mod h1:MkI5dOiIpeN94LNjeCp8ljXN/953JCwAby4bClMr6bw=
github.com/tree-sitter/tree-sitter-cpp v0.23.4 h1:LaWZsiqQKvR65yHgKmnaqA+uz6tlDJTJFCyFIeZU/8w=
github.com/tree-sitter/tree-sitter-cpp v0.23.4/go.mod h1:doqNW64BriC7WBCQ1klf0KmJpdEvfxyXtoEybnBo6v8=
github.com/tree-sitter/tree-sitter-embedded-template v0.23.2 h1:nFkkH6Sbe56EXLmZBqHHcamTpmz3TId97I16EnGy4rg=
github.com/tree-sitter/tree-sitter-embedded-template v0.23.2/go.mod h1:HNPOhN0qF3hWluYLdxWs5WbzP/iE4aaRVPMsdxuzIaQ=
github.com/tree-sitter/tree-sitter-go v0.23.4 h1:yt5KMGnTHS+86pJmLIAZMWxukr8W7Ae1STPvQUuNROA=
github.com/tree-sitter/tree-sitter-go v0.23.4/go.mod h1:Jrx8QqYN0v7npv1fJRH1AznddllYiCMUChtVjxPK040=
github.com/tree-sitter/tree-sitter-html v0.23.2 h1:1UYDV+Yd05GGRhVnTcbP58GkKLSHHZwVaN+lBZV11Lc=
github.com/tree-sitter/tree-sitter-html v0.23.2/go.mod h1:gpUv/dG3Xl/eebqgeYeFMt+JLOY9cgFinb/Nw08a9og=
github.com/tree-sitter/tree-sitter-java v0.23.5 h1:J9YeMGMwXYlKSP3K4Us8CitC6hjtMjqpeOf2GGo6tig=
github.com/tree-sitter/tree-sitter-java v0.23.5/go.mod h1:NRKlI8+EznxA7t1Yt3xtraPk1Wzqh3GAIC46wxvc320=
github.com/tree-sitter/tree-sitter-javascript v0.23.1 h1:1fWupaRC0ArlHJ/QJzsfQ3Ibyopw7ZfQK4xXc40Zveo=
github.com/tree-sitter/tree-sitter-javascript v0.23.1/go.mod h1:lmGD1EJdCA+v0S1u2fFgepMg/opzSg/4pgFym2FPGAs=
github.com/tree-sitter/tree-sitter-json v0.24.8 h1:tV5rMkihgtiOe14a9LHfDY5kzTl5GNUYe6carZBn0fQ=
github.com/tree-sitter/tree-sitter-json v0.24.8/go.mod h1:F351KK0KGvCaYbZ5zxwx/gWWvZhIDl0eMtn+1r+gQbo=
github.com/tree-sitter/tree-sitter-php v0.23.11 h1:iHewsLNDmznh8kgGyfWfujsZxIz1YGbSd2ZTEM0ZiP8=
github.com/tree-sitter/tree-sitter-php v0.23.11/go.mod h1:T/kbfi+UcCywQfUNAJnGTN/fMSUjnwPXA8k4yoIks74=
github.com/tree-sitter/tree-sitter-python v0.23.6 h1:qHnWFR5WhtMQpxBZRwiaU5Hk/29vGju6CVtmvu5Haas=
github.com/tree-sitter/tree-sitter-python v0.23.6/go.mod h1:cpdthSy/Yoa28aJFBscFHlGiU+cnSiSh1kuDVtI8YeM=
github.com/tree-sitter/tree-sitter-ruby v0.23.1 h1:T/NKHUA+iVbHM440hFx+lzVOzS4dV6z8Qw8ai+72bYo=
github.com/tree-sitter/tree-sitter-ruby v0.23.1/go.mod h1:kUS4kCCQloFcdX6sdpr8p6r2rogbM6ZjTox5ZOQy8cA=
github.com/tree-sitter/tree-sitter-rust v0.23.2 h1:6AtoooCW5GqNrRpfnvl0iUhxTAZEovEmLKDbyHlfw90=
github.com/tree-sitter/tree-sitter-rust v0.23.2/go.mod h1:hfeGWic9BAfgTrc7Xf6FaOAguCFJRo3RBbs7QJ6D7MI=
go.starlark.net v0.0.0-20210223155950-e043a3d3c984/go.mod h1:t3mmBBPzAVvK0L0n1drDmrQsJ8FoIx4INCqVMTr/Zo0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down
1 change: 1 addition & 0 deletions gazelle/patches/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports_files(glob(["*.patch"]))
25 changes: 25 additions & 0 deletions gazelle/patches/go-tree-sitter-cc_library.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff --git a/BUILD.bazel b/BUILD.bazel
index 37704d1..b6d17a8 100755
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -1,5 +1,12 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

+cc_library(
+ name = "clib",
+ hdrs = glob(["src/**/*.h", "src/**/*.c", "include/**/*.h"]),
+ includes = ["include", "src"],
+ visibility = ["//:__subpackages__"],
+)
+
go_library(
name = "go-tree-sitter",
srcs = [
@@ -22,6 +30,7 @@ go_library(
"tree_sitter.go",
],
cgo = True,
+ cdeps = ["//:clib"],
copts = ["-Iinclude -Isrc -std=c11 -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE"],
importpath = "github.com/tree-sitter/go-tree-sitter",
visibility = ["//visibility:public"],
32 changes: 32 additions & 0 deletions gazelle/patches/tree-sitter-python-cc_library.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git a/BUILD.bazel b/BUILD.bazel
index e69de29..1f5d973 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -0,0 +1,11 @@
+filegroup(
+ name = "csrcs",
+ srcs = glob(["src/**/*.h"]),
+ visibility = ["//visibility:public"],
+)
+
+cc_library(
+ name = "clib",
+ hdrs = ["src/parser.c", "src/scanner.c"] + glob(["src/tree_sitter/*.h"]),
+ visibility = ["//bindings/go:__subpackages__"],
+)
diff --git a/bindings/go/BUILD.bazel b/bindings/go/BUILD.bazel
index f3e5232..cec7083 100644
--- a/bindings/go/BUILD.bazel
+++ b/bindings/go/BUILD.bazel
@@ -2,9 +2,10 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go",
- srcs = ["binding.go"],
+ srcs = ["binding.go", "//:csrcs"],
cgo = True,
copts = ["-std=c11 -fPIC"],
+ cdeps = ["//:clib"],
importpath = "github.com/tree-sitter/tree-sitter-python/bindings/go",
visibility = ["//visibility:public"],
)
7 changes: 3 additions & 4 deletions gazelle/python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,20 @@ go_library(
importpath = "github.com/bazel-contrib/rules_python/gazelle/python",
visibility = ["//visibility:public"],
deps = [
"//manifest",
"//pythonconfig",
"@bazel_gazelle//config:go_default_library",
"@bazel_gazelle//label:go_default_library",
"@bazel_gazelle//language:go_default_library",
"@bazel_gazelle//repo:go_default_library",
"@bazel_gazelle//resolve:go_default_library",
"@bazel_gazelle//rule:go_default_library",
"@com_github_bazelbuild_buildtools//build:go_default_library",
"@com_github_bazelbuild_buildtools//build",
"@com_github_bmatcuk_doublestar_v4//:doublestar",
"@com_github_dougthor42_go_tree_sitter//:go-tree-sitter",
"@com_github_dougthor42_go_tree_sitter//python",
"@com_github_emirpasic_gods//lists/singlylinkedlist",
"@com_github_emirpasic_gods//sets/treeset",
"@com_github_emirpasic_gods//utils",
"@com_github_tree_sitter_go_tree_sitter//:go-tree-sitter",
"@com_github_tree_sitter_tree_sitter_python//bindings/go",
"@org_golang_x_sync//errgroup",
],
)
Expand Down
Loading