Conversation
kennykerr
reviewed
Mar 10, 2021
kennykerr
reviewed
Mar 10, 2021
kennykerr
reviewed
Mar 10, 2021
kennykerr
approved these changes
Mar 10, 2021
oldnewthing
reviewed
Mar 10, 2021
| int main(int const argc, char** argv) | ||
| { | ||
| // Dynamically enable long path support | ||
| ((unsigned char*)(NtCurrentTeb()->ProcessEnvironmentBlock))[3] |= 0x80; |
Member
There was a problem hiding this comment.
We should not be calling undocumented APIs from cppwinrt.exe.
Collaborator
There was a problem hiding this comment.
Is there an alternative or do we pull it out?
Member
Author
There was a problem hiding this comment.
An alternative is to create an app manifest; I had tried doing that, the manifest was getting embedded, but long path were still not working. We could pull out this one line from the code and leave the error reporting, and I can try to rework the manifest. LMK what you'd like to do.
This was referenced Mar 11, 2021
Merged
This was referenced Mar 15, 2021
This was referenced Mar 15, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #877
(moving from remote branch PR in #877)
Context
React Native for Windows creates apps that can end up with some paths that need to be built that are too long (e.g.
C:\users\myname\source\repos\MyAppProject\node_modules\react-native-windows\Microsoft.ReactNative\Generated Files\winrt\Insert.Your.Favorite.Long.Namespace.Here.h). We see lots of issues where people are creating their project starting in an already pretty deeply-nested folder, and the build fails.Root cause
The reason the build fails is because certain headers that cppwinrt is supposed to generate are not on disk. After tracing this down, it turns out that this comes from the fact that the
std::ofstreamconstructor does not throw on error. Instead, it will set its internal handle to null, and you have to checkmyofstream.good()before continuing. The alternative is to construct an emptyofstream, set a flag that says you want exceptions, and then callopen(), which is what I ended up doing.With that part of the fix, you now get an error instead of "silently failing and returning success" which today causes the build to fail later on:
The second part of the fix is to turn on Long Path support. This normally requires a manifest. I tried embedding the manifest through VS and jumping through all them hoopz, but in the end the alternative is one line in
main()to set a bit in the PEB. With that fix, at least long path errors won't be a thing (as long as you have the per-machine setting turned on too); but now also if we fail to write a file (e.g. file was held open exclusively), we will now correctly get an error instead of silently failing/succeeding.