1

我正在尝试为我的项目创建一个仅嵌入文件集合的 Bazel 规则。嵌入规则如下:

go_embed_data(
    name = "my_files_go",
    src = [
        "embedded/src1", "embedded/src2"
    ],
    package = "my_lib",
    var = "myFiles",
)

然后我将其添加到我的 go_library 规则中:

go_library(
    name = "library",
    srcs = [
        "library.go",
    ],
    importpath = "github.com/nickfelker/golang-app",
    deps = [
        ":my_files_go"
        "//otherLib",
    ],
)

但是,当我尝试构建它时,我最终得到了一个在其他地方找不到的模糊错误。

Error: <target //library:my_files_go> (rule 'go_embed_data') doesn't contain declared provider 'GoArchive'
ERROR: Analysis of target '//:binary' failed; build aborted: Analysis of target '//library:library' failed

我应该如何解决这个错误?

4

1 回答 1

1

为其创建的规则go_embed_data不作为该go_library规则的依赖项。相反,它应该被视为其中之一srcs,如下所示:

go_embed_data(
    name = "my_files_go",
    src = [
        "embedded/src1", "embedded/src2"
    ],
    package = "my_lib",
    var = "myFiles",
)

go_library(
    name = "library",
    srcs = [
        ":my_files_go",
        "library.go",
    ],
    importpath = "github.com/nickfelker/golang-app",
    deps = [
        "//otherLib",
    ],
)
于 2020-09-03T21:40:48.600 回答