-
Notifications
You must be signed in to change notification settings - Fork 406
Description
Originally reported in smacker/go-tree-sitter#175
Steps to Reproduce
- Download or clone https://github.com/smacker/go-tree-sitter @ dd81d9e
- Run
gazelle
on the repo - View the generated
python/BUILD.bazel
file
Expected Result
Gazelle correctly identifies that the python/scanner.c
file depends on the root array.h
header file and that file and its dependencies are added to the resulting go_library
target (as srcs
?).
Actual Result
Gazelle generates
go_library(
name = "python",
srcs = [
"binding.go",
"parser.c",
"parser.h",
"scanner.c",
],
cgo = True,
importpath = "github.com/smacker/go-tree-sitter/python",
visibility = ["//visibility:public"],
deps = ["//:go-tree-sitter"],
)
The build then fails for python/scanner.c:1:10: fatal error: '../array.h' file not found
A manual fix
I know very little about C and Go, so my manual workaround is to make a filegroup
target in the root BUILD.bazel
file:
filegroup(
name = "common_libs",
srcs = [
"alloc.h",
"api.h",
"array.h",
],
visibility = [":__subpackages__"],
)
and then add that as srcs
to the go_library targets:
go_library(
name = "python",
srcs = [
"binding.go",
"parser.c",
"parser.h",
"scanner.c",
"//:common_libs", # manually added
],
cgo = True,
importpath = "github.com/smacker/go-tree-sitter/python",
visibility = ["//visibility:public"],
deps = ["//:go-tree-sitter"],
)
Background and Other Links
I do not know why smacker/go-tree-sitter
changed things to use #include ../array.h
, but we found this out when trying to add python 3.12 syntax support to rules_python
. However, the original implementation was not sustainable for a small number of users so I tried an alternative approach (which also didn't work).
The TL;DR is that we think that the best way forward for rules_python
is to get the upstream Gazelle to make the correct targets.