Skip to content

Conversation

asklar
Copy link
Member

@asklar asklar commented Mar 10, 2021

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::ofstream constructor does not throw on error. Instead, it will set its internal handle to null, and you have to check myofstream.good() before continuing. The alternative is to construct an empty ofstream, set a flag that says you want exceptions, and then call open(), 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:

image

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.

@kennykerr kennykerr merged commit 243f941 into master Mar 10, 2021
@kennykerr kennykerr deleted the longpaths branch March 10, 2021 22:36
int main(int const argc, char** argv)
{
// Dynamically enable long path support
((unsigned char*)(NtCurrentTeb()->ProcessEnvironmentBlock))[3] |= 0x80;
Copy link
Member

Choose a reason for hiding this comment

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

We should not be calling undocumented APIs from cppwinrt.exe.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there an alternative or do we pull it out?

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

PR to use the manifest here: #882

This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Long path support

3 participants