andfoy / winpty-rs

Create and spawn processes inside a pseudoterminal in Windows from Rust
Other
23 stars 7 forks source link

Detect winpty presence more reliably #38

Open fghzxm opened 2 years ago

fghzxm commented 2 years ago

winpty-rs currently detects winpty library's presence by trying to run winpty-agent.exe from PATH. Some software on Windows, for example Neovim, ships with this executable; if the user puts such software on PATH, the build script is tricked into thinking the library exists where it may not.

I think to detect winpty's usability more reliably we just have to try to link something with winpty and see if it fails.

jakob-ledermann commented 3 months ago

Linking is probably the most reliable way to detect it. That linking should use the same linker the rest of the build is using. It seems like the msvc linker link.exe does not care about the PATH while searching for libraries. https://learn.microsoft.com/en-us/cpp/build/reference/libpath-additional-libpath?view=msvc-170#remarks

I had to specify LIB and make sure it pointed to the folder containing winpty.lib.