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

windows: add support for the glfw backend #773

Merged
merged 16 commits into from
Nov 6, 2023

Conversation

kcbanner
Copy link
Collaborator

@kcbanner kcbanner commented Oct 31, 2023

These changes depend on this libxev PR mitchellh/libxev#73. I will update the reference in build.zig.zon once merged.

Changes:

  • Add WindowsPty, which uses the ConPTY API to create a pseudo console
  • Pty now selects between PosixPty and WindowsPty
  • Windows support in Command, including the ability to launch a process with a pseudo console
  • Enable Command tests on windows
  • Add some environment variable abstractions to handle the missing libc APIs on Windows
  • Windows version of ReadThread

Remaining TODOs:

  • Figure out why ReleaseSafe crashes, but Debug is ok

@kcbanner kcbanner force-pushed the windows_prototype branch 4 times, most recently from 1ec8a97 to 073e5dc Compare October 31, 2023 06:25
@kcbanner
Copy link
Collaborator Author

kcbanner commented Oct 31, 2023

This is the crash that currently happens when starting up in a ReleaseSafe build. Debug is fine.

[0x0]   ntdll!memcmp+0x93   0xcba7a8098   0x7ffd9517db52   
[0x1]   ntdll!EtwpRegistrationCompare+0x22   0xcba7a80a0   0x7ffd951534dc   
[0x2]   ntdll!EtwpInsertRegistration+0x78   0xcba7a80d0   0x7ffd951530f3   
[0x3]   ntdll!EtwNotificationRegister+0xb3   0xcba7a8110   0x7ffd95152aaa   
[0x4]   ntdll!EtwRegisterTraceGuidsW+0x9a   0xcba7a8150   0x7ffd909f2131   
[0x5]   windows_storage!WppInitUm+0x75   0xcba7a81c0   0x7ffd90a32bd8   
[0x6]   windows_storage!DllMain+0x48   0xcba7a8230   0x7ffd90a291ef   
[0x7]   windows_storage!dllmain_dispatch+0x8f   0xcba7a8260   0x7ffd95129a1d   
[0x8]   ntdll!LdrpCallInitRoutine+0x61   0xcba7a82c0   0x7ffd9517c2c7   
[0x9]   ntdll!LdrpInitializeNode+0x1d3   0xcba7a8330   0x7ffd9517c05a   
[0xa]   ntdll!LdrpInitializeGraphRecurse+0x42   0xcba7a8480   0x7ffd9514d947   
[0xb]   ntdll!LdrpPrepareModuleForExecution+0xbf   0xcba7a84c0   0x7ffd9512fbae   
[0xc]   ntdll!LdrpLoadDllInternal+0x19a   0xcba7a8500   0x7ffd95126d40   
[0xd]   ntdll!LdrpLoadForwardedDll+0x138   0xcba7a8580   0x7ffd951266ee   
[0xe]   ntdll!LdrpGetDelayloadExportDll+0xa2   0xcba7a8890   0x7ffd95141927   
[0xf]   ntdll!LdrpHandleProtectedDelayload+0x87   0xcba7a89a0   0x7ffd95120446   
[0x10]   ntdll!LdrResolveDelayLoadedAPI+0xc6   0xcba7a8f70   0x7ffd937e91f2   
[0x11]   SHELL32!_delayLoadHelper2+0x32   0xcba7a9000   0x7ffd938568da   
[0x12]   SHELL32!_tailMerge_api_ms_win_shell_shellfolders_l1_1_0_dll+0x3f   0xcba7a9040   0x7ff79d8f4852   
[0x13]   ghostty!_get_real_paths_from_prefix+0x272   0xcba7a90b0   0x7ff79d8f11c5   
[0x14]   ghostty!FcParseDir+0x115   0xcba7a9500   0x7ff79d8f0d63   
[0x15]   ghostty!FcEndElement+0x173   0xcba7a9560   0x7ff79da41264   
[0x16]   ghostty!xmlParseEndTag1+0x2d4   0xcba7a95c0   0x7ff79da449cf   
[0x17]   ghostty!xmlParseTryOrFinish+0x9be   0xcba7a9660   0x7ff79d8f0500   
[0x18]   ghostty!xmlParseChunk+0xb6f   0xcba7a9660   0x7ff79d8f0500   
[0x19]   ghostty!FcConfigParseAndLoadFromMemoryInternal+0x1b0   0xcba7a9800   0x7ff79d8f033e   
[0x1a]   ghostty!FcConfigParseAndLoadFromMemory+0x1e   0xcba7aab60   0x7ff79d898cd0   
[0x1b]   ghostty!FcInitFallbackConfig+0x2a   0xcba7aab90   0x7ff79d898ecf   
[0x1c]   ghostty!FcInitLoadOwnConfig+0xd0   0xcba7aab90   0x7ff79d898ecf   
[0x1d]   ghostty!FcInitLoadOwnConfigAndFonts+0x7   0xcba7aabe0   0x7ff79d899051   
[0x1e]   ghostty!FcInitLoadConfigAndFonts+0xf   0xcba7aabe0   0x7ff79d899051   
[0x1f]   ghostty!FcConfigEnsure+0x11   0xcba7aac20   0x7ff79dc01122   
[0x20]   ghostty!FcConfigInit+0x21   0xcba7aac20   0x7ff79dc01122   
[0x21]   ghostty!init+0x8   0xcba7aac50   0x7ff79dbfd000   
[0x22]   ghostty!init+0x8   0xcba7aac50   0x7ff79dbfd000   
[0x23]   ghostty!fontDiscover+0x22   0xcba7aac50   0x7ff79dbfd000   
[0x24]   ghostty!init+0x72a   0xcba7aac90   0x7ff79dbd872f   
[0x25]   ghostty!init+0xfc0   0xcba7aac90   0x7ff79dbd872f   
[0x26]   ghostty!newSurface+0x32   0xcba7aea00   0x7ff79dbc9397   
[0x27]   ghostty!newWindow+0x32   0xcba7aea00   0x7ff79dbc9397   
[0x28]   ghostty!newWindow+0x9f   0xcba7aea00   0x7ff79dbc9397   
[0x29]   ghostty!drainMailbox+0xa7   0xcba7aea80   0x7ff79d7c13f5   
[0x2a]   ghostty!tick+0x14e   0xcba7aea80   0x7ff79d7c13f5   
[0x2b]   ghostty!run+0x15a   0xcba7aea80   0x7ff79d7c13f5   
[0x2c]   ghostty!main+0xf0b   0xcba7aea80   0x7ff79d7c13f5   
[0x2d]   ghostty!callMain+0xf0b   0xcba7aea80   0x7ff79d7c13f5   
[0x2e]   ghostty!initEventLoopAndCallMain+0xf0b   0xcba7aea80   0x7ff79d7c13f5   
[0x2f]   ghostty!callMainWithArgs+0xf0b   0xcba7aea80   0x7ff79d7c13f5   
[0x30]   ghostty!main+0xf57   0xcba7aea80   0x7ff79d7c13f5   
[0x31]   ghostty!__tmainCRTStartup+0x295   0xcba7ff7c0   0x7ff79d7c1446   
[0x32]   ghostty!mainCRTStartup+0x16   0xcba7ff880   0x7ffd94777344   
[0x33]   KERNEL32!BaseThreadInitThunk+0x14   0xcba7ff8b0   0x7ffd951626b1   
[0x34]   ntdll!RtlUserThreadStart+0x21   0xcba7ff8e0   0x0   

@barvirm
Copy link
Collaborator

barvirm commented Oct 31, 2023

@kcbanner Update, it's already merged. 😃

@mitchellh
Copy link
Contributor

Btw the macOS CI failure seems legit. I can fix that myself later today.

@barvirm
Copy link
Collaborator

barvirm commented Nov 1, 2023

Minor improvement for "more native" behavior: src\os\xdg.zig
image
This function should Windows path that points to something like this:
%APPDATA%/ghostty/... -> C:\Users\%USER%\AppData\Roaming\ghostty\...
%LOCALAPPDATA%/ghostty/... -> C:\Users\%USER%\AppData\Local\ghostty\...

I'm not sure which path better. I assume this will be another issue.

@mitchellh
Copy link
Contributor

This looks good. I want to get my windows environment up to verify this and that may take a few days but thanks for doing this, excited to review it! 😄

@mitchellh
Copy link
Contributor

Sorry taking a bit longer to find time to verify this and do some review. The newborn at home has required more attention recently so finding a long enough period to grab my windows machine has been a chore. I'll get there! Sorry.

@erf
Copy link
Collaborator

erf commented Nov 5, 2023

Sorry taking a bit longer to find time to verify this and do some review. The newborn at home has required more attention recently so finding a long enough period to grab my windows machine has been a chore. I'll get there! Sorry.

Maybe you know this but with Parallels you can install Windows on macOS.

Changes:
- Add WindowsPty, which uses the ConPTY API to create a pseudo console
- Pty now selects between PosixPty and WindowsPty
- Windows support in Command, including the ability to launch a process with a pseudo console
- Enable Command tests on windows
- Add some environment variable abstractions to handle the missing libc APIs on Windows
- Windows version of ReadThread
- Fixup macos compile error
@mitchellh
Copy link
Contributor

Okay got my win machine up and can confirm this works great. I'm going to make some tweaks but this is close!

@mitchellh
Copy link
Contributor

Okay, all cleaned up to my personal opinions :) I only found one actual bug: the locale fallback for macOS had some invalid logic (it should've also ran if lang == null but only ran if lang was not null and length zero). Other than that, everything was purely stylistic. Great job!

I also got CI running for windows builds via cross-compile, since the GLFW build can be cross-compiled. I'll work on native windows another time. Will merge once green.

@kcbanner
Copy link
Collaborator Author

kcbanner commented Nov 6, 2023

Awesome! Thanks for the fixups!

@mitchellh mitchellh mentioned this pull request Nov 6, 2023
19 tasks
@mitchellh mitchellh merged commit 044a9af into ghostty-org:main Nov 6, 2023
8 checks passed
@mitchellh mitchellh deleted the windows_prototype branch November 6, 2023 02:30
@mitchellh
Copy link
Contributor

I may have broken something somehow in my edits, "exit" out of the console seems to hang and I don't remember it doing that initially. I'll take a look sometime but just noting that...

@der-teufel-programming
Copy link
Collaborator

exit out of the console hanged for me before your edits iirc

@kcbanner
Copy link
Collaborator Author

kcbanner commented Nov 6, 2023

Do you happen to see error interrupting read thread err in your log? I suspect it's something going wrong terminating the read thread.

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.

5 participants