google / benchmark

A microbenchmark support library
Apache License 2.0
8.93k stars 1.62k forks source link

Output library / schema versions in JSON context block #1742

Closed LebedevRI closed 8 months ago

LebedevRI commented 8 months ago

As discussed in https://github.com/google/benchmark/issues/1741#issuecomment-1906146318

LebedevRI commented 8 months ago

Let me look into that...

LebedevRI commented 8 months ago

Sorry, i have no clue how to do the bazel part.

dmah42 commented 8 months ago

Sorry, i have no clue how to do the bazel part.

blech ok. do cmake, i'll take bazel.

LebedevRI commented 8 months ago

With

        "BENCHMARK_VERSION=\""+native.module_version()+"\"",

we get

ERROR: /home/runner/work/benchmark/benchmark/BUILD.bazel:71:32: name 'native' is not defined
LebedevRI commented 8 months ago

With

        "BENCHMARK_VERSION=\""+module_version()+"\"",

(which is the right syntax i guess?) we get

ERROR: Traceback (most recent call last):
    File "/home/runner/work/benchmark/benchmark/BUILD.bazel", line 71, column 31, in <toplevel>
        "BENCHMARK_VERSION=\""+module_version()+"\"",
Error: unsupported binary operation: string + NoneType

Does that mean there is no version string? But MODULE.bazel has

module(
    name = "google_benchmark",
    version = "1.8.3",
)
dmah42 commented 8 months ago

With

        "BENCHMARK_VERSION=\""+module_version()+"\"",

(which is the right syntax i guess?) we get

ERROR: Traceback (most recent call last):
  File "/home/runner/work/benchmark/benchmark/BUILD.bazel", line 71, column 31, in <toplevel>
      "BENCHMARK_VERSION=\""+module_version()+"\"",
Error: unsupported binary operation: string + NoneType

Does that mean there is no version string? But MODULE.bazel has

module(
    name = "google_benchmark",
    version = "1.8.3",
)

https://bazel.build/rules/lib/toplevel/native#module_version

"If this package is from a repo defined in WORKSPACE instead of MODULE.bazel, this is empty. "

i guess we have both WORKSPACE and MODULE.bazel so it's returning no version?

LebedevRI commented 8 months ago

Right, i guess that makes sense, but it does not really tell me how to fix this. Sorry. :/

dmah42 commented 8 months ago

Right, i guess that makes sense, but it does not really tell me how to fix this. Sorry. :/

don't be. drop bazel, i'll deal with it. i think i know what we need to do.

dmah42 commented 8 months ago

just to confirm: with bzlmod enabled, this gets further. two things missing:

  1. convert "none" to an empty string in BUILD.bazel for when bzlmod is disabled
  2. figure out why it's failing with:
/usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++14' -MD -MF bazel-out/k8-fastbuild/bin/_objs/benchmark/benchmark.pic.d '-frandom-seed=bazel-out/k8-fastbuild/bin/_objs/benchmark/benchmark.pic.o' -fPIC -DBENCHMARK_STATIC_DEFINE '-DBENCHMARK_VERSION=1.8.3' '-D_FILE_OFFSET_BITS=64' -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -iquote . -iquote bazel-out/k8-fastbuild/bin -Ibazel-out/k8-fastbuild/bin/_virtual_includes/benchmark '-Werror=old-style-cast' -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c src/benchmark.cc -o bazel-out/k8-fastbuild/bin/_objs/benchmark/benchmark.pic.o)

<command-line>: error: too many decimal points in number
src/benchmark.cc:753:11: note: in expansion of macro 'BENCHMARK_VERSION'
  753 |   return {BENCHMARK_VERSION};
      |           ^~~~~~~~~~~~~~~~~
src/benchmark.cc: In function 'std::string benchmark::GetBenchmarkVersiom()':
src/benchmark.cc:753:28: error: could not convert '{<expression error>}' from '<brace-enclosed initializer list>' to 'std::string' {aka 'std::__cxx11::basic_string<char>'}
  753 |   return {BENCHMARK_VERSION};
      |                            ^
      |                            |
      |                            <brace-enclosed initializer list>
LebedevRI commented 8 months ago
  • figure out why it's failing with:

It needs to be -DBENCHMARK_VERSION="string" not -DBENCHMARK_VERSION=string.

LebedevRI commented 8 months ago

@dmah42 thank you!

dmah42 commented 8 months ago

i just kept adding \ and it works.

        "BENCHMARK_VERSION=\\\"" + module_version() + "\\\"",