Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Output library / schema versions in JSON context block #1742

Merged
merged 6 commits into from
Jan 29, 2024

Conversation

LebedevRI
Copy link
Collaborator

As discussed in #1741 (comment)

@LebedevRI LebedevRI requested a review from dmah42 January 23, 2024 23:43
#if defined(BENCHMARK_VERSION)
const char library_version[] = BENCHMARK_VERSION;
#else
const char library_version[] = "hello, bazel!";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite know what should be done for non-CMake.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in bazel we could add a define to the cc_library that maps to module_version() i think: https://bazel.build/rules/lib/toplevel/native#module_version

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, i have no idea how to actually write that though. I've tried the obvious approach, but it may not work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you try native.module_version()? i think you were close. if it doesn't work we'll go with cmake and i'll hack on bazel.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i tried that first.

src/json_reporter.cc Outdated Show resolved Hide resolved
@LebedevRI
Copy link
Collaborator Author

Let me look into that...

@LebedevRI LebedevRI force-pushed the json-version branch 2 times, most recently from 2737d16 to d4d344b Compare January 24, 2024 12:40
@LebedevRI
Copy link
Collaborator Author

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

@dmah42
Copy link
Member

dmah42 commented Jan 24, 2024

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

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

@LebedevRI
Copy link
Collaborator Author

With

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

we get

ERROR: /home/runner/work/benchmark/benchmark/BUILD.bazel:71:32: name 'native' is not defined

@LebedevRI
Copy link
Collaborator Author

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
Copy link
Member

dmah42 commented Jan 24, 2024

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
Copy link
Collaborator Author

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

@dmah42
Copy link
Member

dmah42 commented Jan 24, 2024

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.

out << ",\n";

// NOTE: our json schema is not strictly tied to the library version!
out << indent << FormatKV("json_schema_version", int64_t(1));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, do we want the original (current) version to be 1 or 0 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current version is v1.8.3 so v1 to match the major.

@dmah42 dmah42 merged commit 17bc235 into google:main Jan 29, 2024
77 of 80 checks passed
@dmah42
Copy link
Member

dmah42 commented Jan 29, 2024

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
Copy link
Collaborator Author

  • figure out why it's failing with:

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

@LebedevRI LebedevRI deleted the json-version branch January 29, 2024 13:23
@LebedevRI
Copy link
Collaborator Author

@dmah42 thank you!

@dmah42
Copy link
Member

dmah42 commented Jan 29, 2024

i just kept adding \ and it works.

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

LebedevRI added a commit to LebedevRI/benchmark that referenced this pull request May 24, 2024
google#1742 changed the placeholder version from `0.0.0` to `v0.0.0`,
but this line which was further dealing with it, was not updated.

Fixes google#1792
dmah42 added a commit that referenced this pull request May 28, 2024
#1742 changed the placeholder version from `0.0.0` to `v0.0.0`,
but this line which was further dealing with it, was not updated.

Fixes #1792

Co-authored-by: dominic <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants