-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Build React Native Windows with C++ 20 #12219
Conversation
a4bfa2c
to
e56614a
Compare
This should allow removal of the patches mentioned in #12195, but some of the listed ones there were unrelated to C++ 20, and were related to casting instead. So it might be better to just remove everything at once in a future round of integrating changes. |
Failures for universal playground debug are also showing on last continuous: https://dev.azure.com/ms/react-native-windows/_build/results?buildId=504190 Hermes + Fabric E2ETest crash visiting the "TextInputs with key prop" RNTester page seems new though, and awfully strange. Looks like the job was able to upload a crash dump I can take a look at though. Edit: The symbols weren't uploaded though 🤔. |
vnext/Shared/Utils.h
Outdated
@@ -20,6 +20,6 @@ struct Url { | |||
std::string Target(); | |||
}; | |||
|
|||
std::future<std::string> getApplicationDataPath(const wchar_t *childfolder); | |||
concurrency::task<std::string> getApplicationDataPath(const wchar_t *childfolder); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I understand the need for this change, it is very unfortunate one since we do not want to use the ConcRT library in Office (unless something changed recently). We must follow up on it and replace it with Mso::Future. Mso::Future does not support coroutines yet. Thus, we cannot use it here yet. @JunielKatarn, let's follow up on it. Until that this code cannot be adopted in Office.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have checked our internal C++ alias and they do not recommend using std::future
, ConcRT, or PPL (std::future is based on PPL).
I guess it was a reason why Raymond Chen created a new library that works well with C++/WinRT.
https://github.com/microsoft/wil/blob/master/include/wil/coroutine.h
This way we would need to add dependency on WIL, which we were avoiding so far.
Anyway, the change is good for now. We must follow up on that after the PR is merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have few enough cases that we could also likely convert these to WinRT types and just use IAsyncOperation. It's also not entirely ideal, but would avoid concurrency runtime usage. Let me know what you think of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, in the current situation it would be the best to use IAsyncOperation
, but I do not know how difficult to apply it. I will leave it up to your judgement.
@NickGerleman, thank you for bringing the C++20 support to RNW! It must be good to go as soon as it can pass the tests. |
Found a couple of issues that were filed the last time we looked into upgrading to C++20. @NickGerleman before merging can you check that these concerns are adressed? |
I think we should be able to close these out. I think they were likely addressed during a previous cppwinrt bump. |
/azp run |
Azure Pipelines failed to run 1 pipeline(s). |
@@ -0,0 +1,968 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
facebook/folly#2086 should hopefully land before next weeks Folly release, and also let us remove the fork of Hash.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is great to see changes to be done in Folly repo!
Just nitpicking on your folly PR: did you consider using "if constexpr" for signed/unsigned instead of cloning the constexpr_ipow
template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Folly targets C++ 14 as a minimum I believe.
I plan to break apart this change into multiple smaller ones. |
A revision of the all-in-one C++ 20 PR caused a crash n Fabric E2E tests. I wanted to look at the crash dump, alongside the pdb and DLL used by the build. The previous copy of this logic, reused for Fabric, was dependent on the structure for a C# appx build. This updates the direcotry based on what I locally observed for the Fabric E2E test build.
These projects make use of ts-specific `std::experimental` coroutine APIs. Bump to C++ 20, and C++ 20 standard coroutines. These both have WinRT binary boundaries, so this should have no interaction with other projects (and should have no impact to MSRN interop.
This sets a couple new preprocessor conditions: 1. `FOLLY_CFG_NO_COROUTINES` to prevent types like `folly::optional` from bringing in Folly's coroutine stack when Folly detects C++ 20 coroutines as available. 2. `_SILENCE_CXX20_U8PATH_DEPRECATION_WARNING`: Because the deprecation came before a suitable replacement API. This is more scoped than the `_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS` used by `React.Cpp.props`.
This API was deprecated in C++ 17, and removed from C++ 20. Replace it with placement new.
1. Both WinRT and std::filesystem use system-native UTF-16 paths on Windows. Defaulting to UTF16 lets us avoid conversion until needed, and fixes some instances of round-tripping between formats. 2. We rely on `path.u8string()` to return a Unicode representation of a path, but that API in C++ 20 returns `std::u8string` which is incompatible with every other existing utf-8 API. `path.string()` may convert to system codepage instead. 3. This makes coroutine usage more efficient when using `IAsyncOperation<winrt::hstring>`, the pattern to replace `std::future<std::string>` usage mechanically. `std::filesystem::path` internally uses Windows native UTF-16 path. We use `u8string()` to convert to UTF-8.
`u8` is needed to portably ensure source is parsed as UTF-8 (though RNW already has build settings to do this) In C++ 20, these are represented using `char8_t` instead of `char`, which makes them incompatible with the other UTF-8 string APIs. This wraps C string literals with `reinterpret_cast`, to keep the portablility benefits of `u8` but also store into a `std::string`.
…lass" Fixes "[Explicit template specialization cannot have a storage class](https://stackoverflow.com/questions/29041775/explicit-template-specialization-cannot-have-a-storage-class-member-method-spe)" in C++ 20 by moving a function outside of a struct.
This bumps Folly to 2023.10.16.00, and cherry-picks facebook/folly@e65afc9 which fixes some strict MSVC warnings seen in a new code, and one of the existing patches. We can remove ConstexprMath.h`, `CacheLocality.cpp`, and the existing patch for `Hash.h` upon intake of `2023.11.06.` when that is pushed. Folly is still being removed opportunistically from RN. We no longer use folly containers build folly futures on Android/iOS.
This moves projects in vnext to build with C++ 20 and C++ 20 coroutines. This should not impact the ABI of MSRN DLLs, but may need care for cases of Folly at legacy ABI boundary. 1. Set `<CppStandard>stdcpp20</CppStandard>` in `React.cpp.props` 2. Remove explicit usages of `/await` to opt into coroutines TS 3. Replace `std::experimental::coroutine_handle` with `std::coroutine_handle`
Changes:
Build flags:
/await
flag which was used to enable experimental coroutines TS support in C++ 17stdcpp20
it looks likeintegration-test-app
andautomation-channel
with C++ 20, so we can get rid of their legacy coroutine usage (not strictly required)Coroutines:
std::experimental::coroutine_handle
withstd::coroutine_handle
std::future
usage in coroutines withconcurrency:task
since the former relies on coroutine extensions not part of the C++ 20 standard (provided previously by/await
)C++ 20 breaking changes
allocator.construct()
(deprecated in C++ 17 but silenced in RNW, removed in C++ 20) with placement new.wstring
when passing unicode file paths.u8string()
is now its own type in C++ 20, that doesn't play nice with libraries not meant to support it, and there isn't a zero-cost way to convert between it andstd::string
. Using wstring APIs for fs path sink lets us avoid that, and ends up avoiding extra conversions/allocations since the path is already UTF-16 internally, and we previously converted to utf8, to convert back to utf16.u8
strings in test data aschar*
usingreinterepret_cast
. This is sadly the portable way to do this, without relying on MSVC setting/utf-8
(which this project does).Folly:
FOLLY_CFG_NO_COROUTINES
to avoid building Folly coroutine bits, not used by RN (consistent with Android/iOS build)/sdl
in follyTEMP_UntilFollyUpdate
Before merging
ContexprMath.h
is on PTO until the end of the month, but I might be able to wrangle someone to accept it (RNW could otherwise fork, like done in other places, but best to avoid the debt)Effect to RNW consumers
This change should not require updates to any of the consumers of Microsoft.ReactNative. Some care might need to be taken for Office/Win32 build with Folly at the ABI boundary in order to be sure we avoid any ODR violations (though, we're likely to be fine).
Microsoft Reviewers: Open in CodeFlow