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

Replace using of internal fmt lib API with public API #3527

Merged

Conversation

keeper
Copy link
Contributor

@keeper keeper commented Sep 18, 2024

Related MDEV: https://jira.mariadb.org/browse/MDEV-31963

Description

The commit cd5808eb introduced a union as a storage for the format argument passed to the internal API fmt::detail::make_arg. This was done to solve the issue that the internal API no longer accepted temporary variables.

However, it's generally better to avoid using internal APIs, as they are more likely to have breaking changes in the future. Instead, we can use the public API fmt::dynamic_format_arg_store to dynamically build the argument list. This API accepts temporary variables, and its behavior is more stable than the internal API.

How can this PR be tested?

  • MTR tests passed

Basing the PR against the correct MariaDB version

  • This is a new feature and the PR is based against the latest MariaDB development branch.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

Copyright

All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.

@CLAassistant
Copy link

CLAassistant commented Sep 18, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@keeper keeper force-pushed the MDEV-31963-use-dynamic-format-arg-store branch from 5ffe8e8 to 8ba6ff0 Compare September 18, 2024 18:43
@grooverdan
Copy link
Member

Nice! Thanks for noticing.

Can you rebase this back to 10.11?

Are the libfmt versions supporting this public API back to the original minimum supported (v 8 something I think)?

FYI @ZhongRuoyu

Copy link
Contributor

@ZhongRuoyu ZhongRuoyu left a comment

Choose a reason for hiding this comment

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

Thanks! Logic looks good to me.

fmtlib/fmt@6012dc9 seems to be the commit that introduced fmt::dynamic_format_arg_store. It was then released in 6.2.0, so compatibility-wise it should be okay.

Though, for consistency, I believe cmake/libfmt.cmake needs to be updated too.

@vuvova
Copy link
Member

vuvova commented Sep 19, 2024

right, let's fix cmake/libfmt.cmake too, it is supposed to test the availability of the API that the code is using, not availability of something completely different

@keeper
Copy link
Contributor Author

keeper commented Sep 19, 2024

Good catch, I'll make the change as soon as possible, thanks!

@keeper keeper force-pushed the MDEV-31963-use-dynamic-format-arg-store branch from 8ba6ff0 to 0c2119d Compare September 20, 2024 00:13
@keeper keeper changed the base branch from main to 10.11 September 20, 2024 00:13
@keeper
Copy link
Contributor Author

keeper commented Sep 20, 2024

I've updated libfmt.cmake to reflect the changes. I also refactored it a bit so the source check can be reuse for both "system" and "bundled".

@grooverdan
Copy link
Member

Note the validation of the bundled version is failing - https://buildbot.mariadb.org/#/builders/1/builds/50345

-- Performing Test LIBFMT_AVAILBLE
-- Performing Test LIBFMT_AVAILBLE - Failed
-- Performing Test LIBFMT_AVAILBLE
-- Performing Test LIBFMT_AVAILBLE - Failed
CMake Error at cmake/libfmt.cmake:60 (MESSAGE):
  Bundled libfmt library is not found or unusable
Call Stack (most recent call first):
  CMakeLists.txt:413 (CHECK_LIBFMT)
-- Configuring incomplete, errors occurred!
See also "/home/buildbot/tarball-docker/build/mkdist/CMakeFiles/CMakeOutput.log".
See also "/home/buildbot/tarball-docker/build/mkdist/CMakeFiles/CMakeError.log".

@keeper
Copy link
Contributor Author

keeper commented Sep 20, 2024

Looks like the bundled libfmt is not downloading after my refactor of libfmt.cmake, working on it now.

@keeper keeper force-pushed the MDEV-31963-use-dynamic-format-arg-store branch from 0c2119d to 7f27be6 Compare September 20, 2024 22:15
@keeper
Copy link
Contributor Author

keeper commented Sep 20, 2024

I mistake that ExternalProject_Add happens at configuration time and actually it's build time. In this case bundled libfmt is not available at the time thus CHECK_CXX_SOURCE_RUN() failed. I've reverted back the refactor and only updated the test code and it should works now.

Copy link
Contributor

@ZhongRuoyu ZhongRuoyu left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@ottok
Copy link
Contributor

ottok commented Sep 22, 2024

Looks good to me!

Thanks @ZhongRuoyu! I apologize for accidentally pressing the re-review button, my GitHub tab had now reloaded properly, so I didn't see the approval you already gave.

@ZhongRuoyu
Copy link
Contributor

Thanks @ZhongRuoyu! I apologize for accidentally pressing the re-review button, my GitHub tab had now reloaded properly, so I didn't see the approval you already gave.

No problem, cheers!

Copy link
Contributor

@LinuxJedi LinuxJedi left a comment

Choose a reason for hiding this comment

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

Ooo... this one is quite important as a community project hit a problem with. Nice one.

The commit cd5808e introduced a union as a storage for the format
argument passed to the internal API fmt::detail::make_arg. This was done
to solve the issue that the internal API no longer accepted temporary
variables.

However, it's generally better to avoid using internal APIs, as they are
more likely to have breaking changes in the future. Instead, we can use
the public API fmt::dynamic_format_arg_store to dynamically build the
argument list. This API accepts temporary variables, and its behavior is
more stable than the internal API. `libfmt.cmake` is updated to reflect
the change as well.

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer Amazon Web
Services, Inc.
@LinuxJedi LinuxJedi force-pushed the MDEV-31963-use-dynamic-format-arg-store branch from f4925dc to b55ca66 Compare September 30, 2024 14:24
@LinuxJedi LinuxJedi merged commit 21b2071 into MariaDB:10.11 Sep 30, 2024
12 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

7 participants