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

Prepare C++ code for Debian Bookworm, update C++ standard to C++-20 #1179

Closed
uweseimet opened this issue Jun 19, 2023 · 3 comments · Fixed by #1232
Closed

Prepare C++ code for Debian Bookworm, update C++ standard to C++-20 #1179

uweseimet opened this issue Jun 19, 2023 · 3 comments · Fixed by #1232
Assignees
Labels
code quality enhancement New feature or request

Comments

@uweseimet
Copy link
Contributor

uweseimet commented Jun 19, 2023

Debian Bookworm was released recently, and it's very likely just a matter of weeks until there is an official Raspberry Pi OS based on Bookworm. This is a list of changes and code improvements that can be applied:

  • Drop the support for gcc < 10. The Bullseye default compiler is gcc 10, with Bookworm it's gcc 12. clang-13 the latest clang release on Bullseye, clang-15 the latest on Bookworm.
  • With gcc 10 a C++-20 subset can be used as C++ standard level C++-20 provides several benefits see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2131r0.html and https://gcc.gnu.org/projects/cxx-status.html. Unfortunately gcc 10 does not support "using enum" and lacks some other C++-20 features.
  • Clean up the code and make it better readable/maintainable by using C++-20 features, as far as supported by gcc 10
  • Use filesystem::file_size(): bullseye 32 bit C++ toolchain supports files > 2 GiB
  • Replace containers by spans where possible
  • De-duplicate with templates
  • Fix C++-20 issues reported by SonarCloud, as far as fixing with gcc 10 is possible
  • Maybe use -flto for better optimization (binaries are much smaller, but compile/link time increases)

There is an "issue_1179" branch that reflects these changes. The code in this branch passes the test suite on a Pi with Bullseye and on a Pi that was updated from Bullseye to Bookworm.

>lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 12 (bookworm)
Release:        12
Codename:       bookworm
>gcc --version
gcc (Raspbian 12.2.0-14+rpi1) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Note: This SonarCloud rule (applied for C++-20 only)

Transparent comparator should be used with associative "std::string" containers

should be disabled. It's not helpful/relevant for PiSCSI but just leads to rather complicated declarations of unordered maps.

@uweseimet uweseimet self-assigned this Jun 19, 2023
@akuker
Copy link
Member

akuker commented Jun 20, 2023

Buster has been moved to "legacy" support, so seems like a reasonable change.

@uweseimet
Copy link
Contributor Author

The plan is to wait for the officlal Raspberry Pi OS based on bookworm before merging the changes. Testing can already be done on an upgraded bullseye distribution.

@uweseimet
Copy link
Contributor Author

I assume bookworm will be released together with the Pi 5, which is supposed to be released next month.

uweseimet added a commit that referenced this issue Oct 1, 2023
@uweseimet uweseimet linked a pull request Oct 1, 2023 that will close this issue
uweseimet added a commit that referenced this issue Oct 2, 2023
@uweseimet uweseimet linked a pull request Oct 2, 2023 that will close this issue
@uweseimet uweseimet linked a pull request Oct 2, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality enhancement New feature or request
Projects
None yet
2 participants