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

Use C++20. #2322

Merged
merged 3 commits into from
Apr 26, 2024
Merged

Use C++20. #2322

merged 3 commits into from
Apr 26, 2024

Conversation

tez011
Copy link
Contributor

@tez011 tez011 commented Mar 29, 2024

Description

#2149 was reverted in #2320 and needs to be split into three changes:

  • C++20 (this one!)
  • UCRT64
  • WGC

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Dependency update (updates to dependencies)
  • Documentation update (changes to documentation)
  • Repository update (changes to repository files, e.g. .github/...)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the in code docstring/documentation-blocks for new or existing methods/components

Branch Updates

LizardByte requires that branches be up-to-date before merging. This means that after any PR is merged, this branch
must be updated before it can be merged. You must also
Allow edits from maintainers.

  • I want maintainers to keep my branch updated

Copy link

codecov bot commented Mar 29, 2024

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 6.05%. Comparing base (9288775) to head (bdf643e).

Additional details and impacted files
@@            Coverage Diff             @@
##           nightly   #2322      +/-   ##
==========================================
- Coverage     6.17%   6.05%   -0.13%     
==========================================
  Files           86      86              
  Lines        17542   17536       -6     
  Branches      8179    8184       +5     
==========================================
- Hits          1083    1061      -22     
- Misses       15362   15434      +72     
+ Partials      1097    1041      -56     
Flag Coverage Δ
Linux 4.26% <0.00%> (+<0.01%) ⬆️
Windows 2.04% <0.00%> (-0.01%) ⬇️
macOS-12 ?
macOS-13 7.84% <0.00%> (-0.09%) ⬇️
macOS-14 8.16% <0.00%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/config.cpp 3.87% <ø> (-0.63%) ⬇️
src/httpcommon.cpp 2.12% <ø> (ø)
src/nvhttp.cpp 0.92% <ø> (-0.16%) ⬇️
src/platform/linux/cuda.cpp 1.65% <ø> (ø)
src/platform/linux/kmsgrab.cpp 2.30% <ø> (-0.01%) ⬇️
src/rtsp.cpp 1.34% <ø> (-0.34%) ⬇️
src/stream.h 0.00% <ø> (ø)
src/platform/linux/input.cpp 0.22% <0.00%> (ø)
src/platform/windows/input.cpp 0.39% <0.00%> (ø)
src/platform/windows/misc.cpp 1.07% <0.00%> (ø)
... and 1 more

... and 18 files with indirect coverage changes

@tez011
Copy link
Contributor Author

tez011 commented Mar 29, 2024

AppImage build fails because Ubuntu 20.04 provides only Boost 1.71, which is incompatible with C++20. https://stackoverflow.com/questions/62723053/boost-log-expressions-v1-71-will-not-compile-under-c20

There is a more recent LTS version. Could we drop 20.04? Every other distribution that Sunshine makes builds for provides 1.74 or higher, even Debian 11.

@tez011
Copy link
Contributor Author

tez011 commented Mar 30, 2024

What wonderful timing!
CI passes on my fork.

https://github.com/tez011/Sunshine/actions/runs/8486729110

@tez011
Copy link
Contributor Author

tez011 commented Mar 31, 2024

depends on #2327

@ReenigneArcher
Copy link
Member

depends on #2327

Merged.

@@ -1510,7 +1510,7 @@ namespace platf {
std::stringstream ss;
ss << std::hex << std::setfill('0');
for (const auto &ch : str) {
ss << ch;
ss << static_cast<uint_least32_t>(ch);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

char32_t — type for UTF-32 character representation, required to be large enough to represent any UTF-32 code unit (32 bits). It has the same size, signedness, and alignment as std::uint_least32_t, but is a distinct type.
https://en.cppreference.com/w/cpp/language/types#char32_t

Therefore we should expect no data loss with a static_cast to uint_least32_t

@@ -614,7 +614,7 @@ namespace platf {
for (auto &entry : fs::directory_iterator { card_dir }) {
auto file = entry.path().filename();

auto filestring = file.generic_u8string();
auto filestring = file.generic_string();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

generic_u8string now returns basic_string<char8_t>. since char8_t is unsigned, this is now incompatible with std::string_view = std::basic_string_view<char>. Assuming this goes in with the UCRT64 change our locale is not exactly guaranteed to be utf-8 either, and the comparison we're immediately making is to an ANSI string so the u8-ness seems mostly irrelevant here. Therefore, making this change so compilation succeeds.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good thing is that we don't use file.generic_string(); on Windows. Yet...

@tez011
Copy link
Contributor Author

tez011 commented Apr 5, 2024

Is there anything else in this pull request I should handle before it's able to be merged?

@ReenigneArcher
Copy link
Member

Just needs testing and approval. It will be after v0.23.0.

@tez011
Copy link
Contributor Author

tez011 commented Apr 20, 2024

Hi! Just waiting for testing/approval results for this pull request. This first change is fairly small so I'm hoping there aren't too many obstacles!

@ReenigneArcher
Copy link
Member

ReenigneArcher commented Apr 20, 2024

@tez011 sorry for the delays. We have a lot of open PRs. It might take a little bit before the other approvals come in. I think we are going to try to put out another patch to get a few things fixed before merging these bigger ones.

In the meantime, can you rebase your branch on top of the latest nightly?

@@ -36,7 +36,7 @@ endif()

target_link_libraries(sunshine ${SUNSHINE_EXTERNAL_LIBRARIES} ${EXTRA_LIBS})
target_compile_definitions(sunshine PUBLIC ${SUNSHINE_DEFINITIONS})
set_target_properties(sunshine PROPERTIES CXX_STANDARD 17
set_target_properties(sunshine PROPERTIES CXX_STANDARD 20
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just below we have:

target_compile_options(sunshine PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${SUNSHINE_COMPILE_OPTIONS}>;$<$<COMPILE_LANGUAGE:CUDA>:${SUNSHINE_COMPILE_OPTIONS_CUDA};-std=c++17>)

This either need to be changed to c++20 or removed? @ReenigneArcher do you know why we need to specify the standard explicitly again?

^ This includes here and in other files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I settled on this change after trying both options you describe. The cuda compiler doesn't support c++20.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why it was originally specified explicitly. I guess because it would fail to compile if the wrong standard was used?

src/network.cpp Show resolved Hide resolved
@@ -1510,7 +1510,7 @@ namespace platf {
std::stringstream ss;
ss << std::hex << std::setfill('0');
for (const auto &ch : str) {
ss << ch;
ss << static_cast<uint_least32_t>(ch);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we casting? The char32_t is already unsigned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

stringstreams don't approve of mixing type char and type char32_t. (You can try this.) This cast is done to force the stringstream to recognize that this value is a 32-bit integer and to hex it accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/home/runner/work/Sunshine/Sunshine/src/platform/linux/input.cpp: In function ‘std::string platf::to_hex(const std::__cxx11::basic_string<char32_t>&)’:
/home/runner/work/Sunshine/Sunshine/src/platform/linux/input.cpp:1513:13: error: use of deleted function ‘std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char32_t) [with _Traits = std::char_traits<char>]’
 1513 |       ss << ch;
      |             ^~
In file included from /usr/include/c++/10/bits/unique_ptr.h:42,
                 from /usr/include/c++/10/bits/locale_conv.h:41,
                 from /usr/include/c++/10/locale:43,
                 from /usr/include/boost/locale/boundary/facets.hpp:17,
                 from /usr/include/boost/locale/boundary.hpp:12,
                 from /usr/include/boost/locale.hpp:11,
                 from /home/runner/work/Sunshine/Sunshine/src/platform/linux/input.cpp:21:
/usr/include/c++/10/ostream:553:5: note: declared here
  553 |     operator<<(basic_ostream<char, _Traits>&, char32_t) = delete;
      |     ^~~~~~~~
make[2]: *** [tests/CMakeFiles/test_sunshine.dir/build.make:665: tests/CMakeFiles/test_sunshine.dir/__/src/platform/linux/input.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:271: tests/CMakeFiles/test_sunshine.dir/all] Error 2

@@ -614,7 +614,7 @@ namespace platf {
for (auto &entry : fs::directory_iterator { card_dir }) {
auto file = entry.path().filename();

auto filestring = file.generic_u8string();
auto filestring = file.generic_string();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good thing is that we don't use file.generic_string(); on Windows. Yet...

@@ -3,6 +3,7 @@
* @brief todo
*/
#pragma once
#include <utility>
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are a lot of includes for this. Are they really needed? Especially here, in the header.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems they are needed before any boost includes, otherwise a lot of errors like this are observed:
https://github.com/tez011/Sunshine/actions/runs/8484576885/job/23247793427

If we can include a boost header in here, we can certainly include a system header above it, no?

Copy link
Collaborator

@FrogTheFrog FrogTheFrog Apr 26, 2024

Choose a reason for hiding this comment

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

No problems with that, it's just that currently the "includes" state in Sunshine is a mess. For example, in this file even we include asio, but it not used anywhere in the header...

But that's out of scope for this PR.

@FrogTheFrog
Copy link
Collaborator

@ReenigneArcher LGTM

@ReenigneArcher ReenigneArcher merged commit 7fb8c76 into LizardByte:nightly Apr 26, 2024
50 of 53 checks passed
qiin2333 pushed a commit to qiin2333/Sunshine-Foundation that referenced this pull request Apr 27, 2024
KuleRucket pushed a commit to KuleRucket/Sunshine that referenced this pull request Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants