googletest
googletest copied to clipboard
Using gtest with bazel broken: bazel dependency now requires `com_googlesource_code_re2`
When using the latest commit hash as described in the Bazel quickstart, the compile fails as gtest itself requires more dependencies than before:
fe4b433d531868b7dc4da32f407b7be0/external/com_google_googletest/BUILD.bazel:80:11: no such package '@com_googlesource_code_re2//': The repository '@com_googlesource_code_re2' could not be resolved: Repository '@com_googlesource_code_re2' is not defined and referenced by '@com_google_googletest//:gtest'
If I have to put these in my WORKSPACE
, then this should be documented somewhere,
In an ideal world however, the bazel configuration could pick this up recursively ? Not sure how to configure that though.
Would you mind sharing the problematic commit hash?
Using this WORKSPACE file in the quickstart worked for me:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "com_google_googletest",
urls = ["https://github.com/google/googletest/archive/2a02723b76eae879bafbcee5143d5104a13c3626/.zip"],
strip_prefix = "googletest-2a02723b76eae879bafbcee5143d5104a13c3626/",
)
I had used the latest commit at the time, but even with current head, I get the same issue.
Change of WORKSPACE file: https://github.com/chipsalliance/verible/pull/1337
How the failure manifests: https://github.com/chipsalliance/verible/runs/6459541782?check_suite_focus=true#step:7:44
I can indeed reproduce this by cloning Verible, but not by building the quickstart with --bazelrc=/dev/null
and WORKSPACE with the latest commit. I'd like to understand why in order to document it properly. I wonder what triggers Bazel to resolve dependencies (which it possibly doesn't even do in the quickstart).
I don't really know, maybe we need to find someone with insights into the bazel workings.
Did you find out something ?
@hzeller I was able to use
http_archive(
name = "com_google_googletest",
sha256 = "199e68f9dff997b30d420bf23cd9a0d3f66bfee4460e2cd95084a2c45ee00f1a",
strip_prefix = "googletest-5376968f6948923e2411081fd9372e71a59d8e77",
urls = ["https://github.com/google/googletest/archive/5376968f6948923e2411081fd9372e71a59d8e77.zip"],
)
in my WORKSPACE
file.
If you're using Abseil, the latest release notes say:
- Bazel users that build GoogleTest using the Abseil library as a dependency now also require a dependency on RE2 (https://github.com/google/googletest/commit/e33c2b24ca3e13df961ed369f7ed21e4cfcf9eec)
- Bazel users that build GoogleTest using the Abseil library now use the Abseil library to parse all command-line flags (https://github.com/google/googletest/commit/25dcdc7e8bfac8967f20fb2c0a628f5cf442188d)
The additional RE2 requirement looks like your issue above.
I am using 5.4.0
version of Bazel
and 1.13.0
version of googletest
. I am getting the following error.
/tmp/bazel-build/external/com_google_googletest/BUILD.bazel:80:11: no such package '@com_googlesource_code_re2//': The repository '@com_googlesource_code_re2' could not be resolved: Repository '@com_googlesource_code_re2' is not defined and referenced by '@com_google_googletest//:gtest'
.
Did anyone solve this issue?
@Chellapandi I'm not using this anymore, so I have no idea if this advice will make any difference, but you could try adding a dependency on this branch: https://github.com/google/re2/tree/abseil (based on this commit comment)
Thanks for the reply. But issue is not resolved even after adding the following snippet.
http_archive(
name = "com_google_absl",
strip_prefix = "abseil-cpp-master",
urls = ["https://github.com/abseil/abseil-cpp/archive/master.zip"],
)
That adds abseil
(Google's general-purpose library); the error message says to add re2
(its library for regular expressions). I suspect you need to add the branch I linked, which is a version of re2
compatible with abseil
.
You mean this snippet right?
@com_google_absl//absl/log is missing :(
com_google_protobuf/src/google/protobuf/compiler/BUILD.bazel:101:11: no such package '@com_google_absl//absl/log': BUILD file not found in directory 'absl/log' of external repository @com_google_absl. Add a BUILD file to a directory to mark it as a package. and referenced by '@com_google_protobuf//src/google/protobuf/compiler:protoc_lib_nowkt'
any updates? When I query some test based on gtest, bazel just failed for com_googlesource_code_re2 undefined.
Got it to working by examining tensorflow's repo: Add following snippet to WORKSPACE:
# Absl
http_archive(
name = "com_google_absl",
strip_prefix = "abseil-cpp-20230125.3",
urls = ["https://github.com/abseil/abseil-cpp/archive/refs/tags/20230125.3.tar.gz"],
)
# Tests
# re2 required for google tests
http_archive(
name = "com_googlesource_code_re2",
# build_file = "//third_party:re2.BUILD",
sha256 = "b90430b2a9240df4459108b3e291be80ae92c68a47bc06ef2dc419c5724de061",
strip_prefix = "re2-a276a8c738735a0fe45a6ee590fe2df69bcf4502",
urls = ["https://github.com/google/re2/archive/a276a8c738735a0fe45a6ee590fe2df69bcf4502.tar.gz"],
)
http_archive(
name = "com_google_googletest",
sha256 = "81964fe578e9bd7c94dfdb09c8e4d6e6759e19967e397dbea48d1c10e45d0df2",
strip_prefix = "googletest-release-1.12.1",
urls = ["https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz"],
)
http_archive(
name = "bazel_skylib",
sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
],
)
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace()
Note: The versions used above are not latest.
FYI: This issue has been fixed in https://github.com/bazelbuild/bazel-central-registry/pull/970 with the release of version 0.14.0.bcr.1 to the Bazel Central Registry if you are using bzlmod.