Skip to content

Incorrect BUILD file for go_library that requires a C file that has #include "../array.h" #2059

@dougthor42

Description

@dougthor42

Originally reported in smacker/go-tree-sitter#175

Steps to Reproduce

  1. Download or clone https://github.com/smacker/go-tree-sitter @ dd81d9e
  2. Run gazelle on the repo
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy