【发布时间】:2019-01-15 09:20:47
【问题描述】:
我的工作区
cat WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")
http_archive(
name = "io_bazel_rules_go",
urls = ["https://github.com/bazelbuild/rules_go/releases/download/0.16.5/rules_go-0.16.5.tar.gz"],
sha256 = "7be7dc01f1e0afdba6c8eb2b43d2fa01c743be1b9273ab1eaf6c233df078d705",
)
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
go_rules_dependencies()
go_register_toolchains()
# ... rocksdb and etc
new_git_repository(
name = "com_github_tecbot_gorocksdb",
remote = "https://github.com/tecbot/gorocksdb.git",
commit = "3e476152774442234f9a9f747386a48a1d82a515",
build_file = "third-party/gorocksdb.BUILD",
)
还有我的 gorocksdb.BUILD
cat third-party/gorocksdb.BUILD
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"backup.go",
"cache.go",
"cf_handle.go",
# ...
"write_batch.go",
"gorocksdb.c",
"gorocksdb.h",
],
importpath = "github.com/tecbot/gorocksdb",
cgo = True,
visibility = ["//visibility:public"],
cdeps = [
"@com_github_facebook_rocksdb//:rocksdb",
],
)
我使用 Bazel containers 运行 bazel。
docker run -e USER=(id -u) -u=(id -u) -v $PWD:/src/workspace -v /tmp/build_output:/tmp/build_output -w /src/workspace l.gcr.io/google/bazel:0.17.1 --output_user_root=/tmp/build_output run --verbose_failures //:helloworld
我遇到了类似的错误
ERROR: /src/workspace/BUILD.bazel:3:1: no such package '@com_github_tecbot_gorocksdb//': Traceback (most recent call last):
File "/tmp/build_output/a08c2e4811c846650b733c6fc815a920/external/bazel_tools/tools/build_defs/repo/git.bzl", line 160
workspace_and_buildfile(ctx)
File "/tmp/build_output/a08c2e4811c846650b733c6fc815a920/external/bazel_tools/tools/build_defs/repo/utils.bzl", line 60, in workspace_and_buildfile
ctx.symlink(ctx.attr.build_file, "BUILD.bazel")
Not a regular file: /src/workspace/external/third-party/gorocksdb.BUILD and referenced by '//:helloworld'
看到bazel的docs,找到了build_file attr的描述。
字符串;可选
用作此目录的 BUILD 文件的文件。 必须指定 build_file 或 build_file_content。
此属性是相对于主工作区的标签。该文件不需要命名为 BUILD,但可以。 (像 BUILD.new-repo-name 这样的东西可以很好地将其与存储库的实际 BUILD 文件区分开来。)
似乎third-party/gorocksdb.BUILD 是来自 WORKSPACE 的正确相对路径,它适用于某些较低版本的 bazel。不知道为什么bazel会在__workspace_dir__/external/下找这个文件,我真的没有声明任何名为external的东西,是bazel的新特性而且没有文档记录吗?
我确信我的项目中的所有其他部分都是正确的,因为当我复制 gorocksdb.BUILD 的全部内容并将其粘贴到 build_file_content attr 时,效果非常好。
【问题讨论】:
标签: bazel