在Bazel中使用cmake
时,如果无法自动下载repo,可以尝试手动下载并配置repo。
以下是解决方法的示例代码:
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
BUILD
文件或WORKSPACE
文件)中,添加以下内容来配置repo的路径:# WORKSPACE文件示例
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
name = "com_github_git_repo",
remote = "https://github.com/git/git",
commit = "",
shallow_since = "",
)
cmake
时指定repo的路径。例如:# BUILD文件示例
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
rules_cc_git_repository(
name = "git",
remote = "https://github.com/git/git",
commit = "",
shallow_since = "",
)
cc_binary(
name = "my_binary",
srcs = ["main.cc"],
deps = ["@git//:git"],
)
cc_library(
name = "my_library",
srcs = ["my_lib.cc"],
deps = ["@git//:git"],
)
cc_test(
name = "my_test",
srcs = ["test.cc"],
deps = [
"@git//:git",
"//path/to:my_library",
],
)
请根据实际情况修改上述代码示例中的路径和参数。这样,当Bazel使用cmake
时,它将使用手动下载的repo,并且不再需要自动下载。