Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Latest commits have issues with absl/strings:string_view #782

Open
xansec opened this issue Nov 22, 2023 · 3 comments
Open

Latest commits have issues with absl/strings:string_view #782

xansec opened this issue Nov 22, 2023 · 3 comments

Comments

@xansec
Copy link

xansec commented Nov 22, 2023

Hello. When running with the commit referenced in the documentation (here: https://github.com/google/fuzztest/blob/main/doc/quickstart-bazel.md#set-up-a-bazel-workspace), fuzztest seems to work just fine:

bazel test //fuzz:my_fuzztest
Starting local Bazel server and connecting to it...
WARNING: Streamed test output requested. All tests will be run locally, without sharding, one at a time
DEBUG: Rule 'com_google_fuzztest' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "231a36c2d6cdfdfec3ef3b259be46d69eea2d8dc9a1a582b1ac3a9aa68412b70"
INFO: Analyzed target //fuzz:my_fuzztest (62 packages loaded, 927 targets configured).
INFO: Found 1 test target...
(etc...)

When updating to the most recent commit, as recommended:

bazel test //fuzz:my_fuzztest
WARNING: Streamed test output requested. All tests will be run locally, without sharding, one at a time
DEBUG: Rule 'com_google_fuzztest' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "3a01226622d2f13afd62b0cb093e175cedc8604c912277115aa3fccccd59a755"
...
ERROR: /home/.cache/bazel/_bazel/2ace5843c8a77dcebc05650431be8550/external/com_google_fuzztest/fuzztest/BUILD:354:11: no such target '@com_google_absl//absl/strings:string_view': target 'string_view' not declared in package 'absl/strings' defined by /home/.cache/bazel/_bazel/2ace5843c8a77dcebc05650431be8550/external/com_google_absl/absl/strings/BUILD.bazel (did you mean 'string_view.h'? Tip: use `query "@com_google_absl//absl/strings:*"` to see all the targets in that package) and referenced by '@com_google_fuzztest//fuzztest:io'
ERROR: Analysis of target '//fuzz:my_fuzztest' failed; build aborted: 
INFO: Elapsed time: 2.188s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (53 packages loaded, 325 targets configured)
    currently loading: @com_google_absl//absl
ERROR: Couldn't start the build. Unable to run tests

It appears there may be a typo in the abseil string_view reference?

@racko
Copy link

racko commented Jan 19, 2024

It always works with the version that fuzztest is using in their own builds:

fuzztest/WORKSPACE

Lines 23 to 28 in 4c3852b

http_archive(
name = "com_google_absl",
sha256 = "0ddd37f347c58d89f449dd189a645bfd97bcd85c5284404a3af27a3ca3476f39",
strip_prefix = "abseil-cpp-fad946221cec37175e762c399760f54b9de9a9fa",
url = "https://github.com/abseil/abseil-cpp/archive/fad946221cec37175e762c399760f54b9de9a9fa.tar.gz",
)

@thealberto
Copy link

thealberto commented Jan 20, 2024

Hi all,
I'm using the latest version of absl.

http_archive(
    name = "com_google_absl",
    sha256 = "59d2976af9d6ecf001a81a35749a6e551a335b949d34918cfade07737b9d93c5",
    strip_prefix = "abseil-cpp-20230802.0",
    url = "https://github.com/abseil/abseil-cpp/archive/refs/tags/20230802.0.tar.gz",
)

Unfortunately a couple of fixes are necessary:

End of search list.
In file included from external/com_google_fuzztest/fuzztest/internal/type_support.cc:15:
external/com_google_fuzztest/./fuzztest/internal/type_support.h:31:10: fatal error: 'absl/strings/has_absl_stringify.h' file not found
   31 | #include "absl/strings/has_absl_stringify.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

The path for has_absl_stringify has changed so it is necessary to change it to absl/strings/internal/has_absl_stringify.h so you have to modify type_support.h

Once done if you try again you should have the following error:

In file included from external/com_google_fuzztest/./fuzztest/internal/table_of_recent_compares.h:31:
external/com_google_fuzztest/./fuzztest/internal/type_support.h:90:46: error: no template named 'HasAbslStringify' in namespace 'absl'; did you mean 'absl::strings_internal::HasAbslStringify'?
   90 | inline constexpr bool has_absl_stringify_v = absl::HasAbslStringify<T>::value;
      |                                              ^~~~~~~~~~~~~~~~~~~~~~
      |                                              absl::strings_internal::HasAbslStringify
external/com_google_absl/absl/strings/internal/has_absl_stringify.h:42:8: note: 'absl::strings_internal::HasAbslStringify' declared here
   42 | struct HasAbslStringify : std::false_type {};
      |        ^
1 error generated.

This time add strings_internal:: on line 90 as suggested.

Now you should be able to use bazel test and bazel run

[==========] Running 0 tests from 0 test suites.
[==========] 0 tests from 0 test suites ran. (0 ms total)
[  PASSED  ] 0 tests.
INFO: Found 1 test target...
Target //:alberto up-to-date:
  bazel-bin/alberto
INFO: Elapsed time: 14.652s, Critical Path: 9.12s
INFO: 131 processes: 1 internal, 130 linux-sandbox.
INFO: Build completed successfully, 131 total actions
//:alberto                                                               PASSED in 0.0s

Executed 1 out of 1 test: 1 test passes.
There were tests whose specified size is too big. Use the --test_verbose_timeout_warnings command line option to see which ones these are.
➜  woff2 git:(ccbeb246d2) bazel run --copt=-I./include :alberto
INFO: Analyzed target //:alberto (0 packages loaded, 3 targets configured).
INFO: Found 1 target...
Target //:alberto up-to-date:
  bazel-bin/alberto
INFO: Elapsed time: 0.139s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: external/bazel_tools/tools/test/test-setup.sh ./alberto
exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //:alberto
-----------------------------------------------------------------------------
[==========] Running 0 tests from 0 test suites.
[==========] 0 tests from 0 test suites ran. (0 ms total)
[  PASSED  ] 0 tests.
➜  woff2 git:(ccbeb246d2) 

@racko is it worth a PR?

@racko
Copy link

racko commented Jan 20, 2024

@thealberto Don't ask me, I'm just another user 😂

That being said, as a reviewer I would comment that internal headers and APIs must not be used. Thus, for a proper solution, somebody needs to figure out how HasAbslStringify should be replaced without accessing internals.

Looking for a solution, I found that while you are using the latest release from Sep 18, 2023, fuzztest's main branch actually requires abseil/abseil-cpp@fad9462 from Dec 7, 2023 : At the time of writing I found absl/strings/has_absl_stringify.h in abseil's master branch:

// `HasAbslStringify<T>` detects if type `T` supports the `AbslStringify()`
// customization point (see
// https://abseil.io/docs/cpp/guides/format#abslstringify for the
// documentation).
//
// Note that there are types that can be `StrCat`-ed that do not use the
// `AbslStringify` customization point (for example, `int`).

template <typename T, typename = void>
struct HasAbslStringify : std::false_type {};

template <typename T>
struct HasAbslStringify<
    T, std::enable_if_t<std::is_void<decltype(AbslStringify(
           std::declval<strings_internal::UnimplementedSink&>(),
           std::declval<const T&>()))>::value>> : std::true_type {};

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants