Skip to content

Commit 5f3018f

Browse files
authored
refactor(terminal)!: drop winpty, require Windows 10 neovim#18253
Problem: winpty is only needed for Windows 8.1. Removing it reduces our build and code complexity. Solution: - Remove winpty. - Require Windows 10. closes neovim#18252
1 parent 3933592 commit 5f3018f

File tree

8 files changed

+22
-187
lines changed

8 files changed

+22
-187
lines changed

CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,6 @@ endif()
509509
find_package(LIBVTERM 0.1 REQUIRED)
510510
include_directories(SYSTEM ${LIBVTERM_INCLUDE_DIRS})
511511

512-
if(WIN32)
513-
find_package(Winpty 0.4.3 REQUIRED)
514-
include_directories(SYSTEM ${WINPTY_INCLUDE_DIRS})
515-
endif()
516-
517512
option(CLANG_ASAN_UBSAN "Enable Clang address & undefined behavior sanitizer for nvim binary." OFF)
518513
option(CLANG_MSAN "Enable Clang memory sanitizer for nvim binary." OFF)
519514
option(CLANG_TSAN "Enable Clang thread sanitizer for nvim binary." OFF)

cmake/FindWinpty.cmake

Lines changed: 0 additions & 10 deletions
This file was deleted.

runtime/doc/api.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ nvim_get_chan_info({chan}) *nvim_get_chan_info()*
929929
• "pty" (optional) Name of pseudoterminal. On a POSIX
930930
system this is a device path like "/dev/pts/1". If the
931931
name is unknown, the key will still be present if a pty
932-
is used (e.g. for winpty on Windows).
932+
is used (e.g. for conpty on Windows).
933933
• "buffer" (optional) Buffer with connected |terminal|
934934
instance.
935935
• "client" (optional) Info about the peer (client on the

src/nvim/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,6 @@ endif()
465465

466466
if(WIN32)
467467
list(APPEND NVIM_LINK_LIBRARIES netapi32)
468-
list(APPEND NVIM_LINK_LIBRARIES ${WINPTY_LIBRARIES})
469468
endif()
470469

471470
# Use "luv" as imported library, to work around CMake using "-lluv" for
@@ -552,8 +551,6 @@ if(WIN32)
552551
diff.exe
553552
tee.exe
554553
win32yank.exe
555-
winpty-agent.exe
556-
winpty.dll
557554
xxd.exe
558555

559556
# Dependencies for neovim-qt

src/nvim/api/vim.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,7 @@ void nvim_set_client_info(uint64_t channel_id, String name, Dictionary version,
17401740
/// - "pty" (optional) Name of pseudoterminal. On a POSIX system this
17411741
/// is a device path like "/dev/pts/1". If the name is unknown,
17421742
/// the key will still be present if a pty is used (e.g. for
1743-
/// winpty on Windows).
1743+
/// conpty on Windows).
17441744
/// - "buffer" (optional) Buffer with connected |terminal| instance.
17451745
/// - "client" (optional) Info about the peer (client on the other end of
17461746
/// the RPC channel), if provided by it via

src/nvim/os/pty_process_win.c

Lines changed: 18 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <assert.h>
55
#include <stdbool.h>
66
#include <stdlib.h>
7-
#include <winpty_constants.h>
87

98
#include "nvim/ascii.h"
109
#include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8
@@ -23,11 +22,7 @@ static void CALLBACK pty_process_finish1(void *context, BOOLEAN unused)
2322
PtyProcess *ptyproc = (PtyProcess *)context;
2423
Process *proc = (Process *)ptyproc;
2524

26-
if (ptyproc->type == kConpty
27-
&& ptyproc->object.conpty != NULL) {
28-
os_conpty_free(ptyproc->object.conpty);
29-
ptyproc->object.conpty = NULL;
30-
}
25+
os_conpty_free(ptyproc->conpty);
3126
uv_timer_init(&proc->loop->uv, &ptyproc->wait_eof_timer);
3227
ptyproc->wait_eof_timer.data = (void *)ptyproc;
3328
uv_timer_start(&ptyproc->wait_eof_timer, wait_eof_timer_cb, 200, 200);
@@ -39,10 +34,6 @@ int pty_process_spawn(PtyProcess *ptyproc)
3934
{
4035
Process *proc = (Process *)ptyproc;
4136
int status = 0;
42-
winpty_error_ptr_t err = NULL;
43-
winpty_config_t *cfg = NULL;
44-
winpty_spawn_config_t *spawncfg = NULL;
45-
winpty_t *winpty_object = NULL;
4637
conpty_t *conpty_object = NULL;
4738
char *in_name = NULL;
4839
char *out_name = NULL;
@@ -56,38 +47,11 @@ int pty_process_spawn(PtyProcess *ptyproc)
5647

5748
assert(proc->err.closed);
5849

59-
if (os_has_conpty_working()) {
60-
if ((conpty_object =
61-
os_conpty_init(&in_name, &out_name, ptyproc->width, ptyproc->height)) != NULL) {
62-
ptyproc->type = kConpty;
63-
}
64-
}
65-
66-
if (ptyproc->type == kWinpty) {
67-
cfg = winpty_config_new(WINPTY_FLAG_ALLOW_CURPROC_DESKTOP_CREATION, &err);
68-
if (cfg == NULL) {
69-
emsg = "winpty_config_new failed";
70-
goto cleanup;
71-
}
72-
73-
winpty_config_set_initial_size(cfg, ptyproc->width, ptyproc->height);
74-
winpty_object = winpty_open(cfg, &err);
75-
if (winpty_object == NULL) {
76-
emsg = "winpty_open failed";
77-
goto cleanup;
78-
}
79-
80-
status = utf16_to_utf8(winpty_conin_name(winpty_object), -1, &in_name);
81-
if (status != 0) {
82-
emsg = "utf16_to_utf8(winpty_conin_name) failed";
83-
goto cleanup;
84-
}
85-
86-
status = utf16_to_utf8(winpty_conout_name(winpty_object), -1, &out_name);
87-
if (status != 0) {
88-
emsg = "utf16_to_utf8(winpty_conout_name) failed";
89-
goto cleanup;
90-
}
50+
if (!os_has_conpty_working()
51+
|| (conpty_object =
52+
os_conpty_init(&in_name, &out_name, ptyproc->width, ptyproc->height)) == NULL) {
53+
status = UV_ENOSYS;
54+
goto cleanup;
9155
}
9256

9357
if (!proc->in.closed) {
@@ -130,44 +94,15 @@ int pty_process_spawn(PtyProcess *ptyproc)
13094
goto cleanup;
13195
}
13296

133-
if (ptyproc->type == kConpty) {
134-
if (!os_conpty_spawn(conpty_object,
135-
&process_handle,
136-
NULL,
137-
cmd_line,
138-
cwd,
139-
env)) {
140-
emsg = "os_conpty_spawn failed";
141-
status = (int)GetLastError();
142-
goto cleanup;
143-
}
144-
} else {
145-
spawncfg = winpty_spawn_config_new(WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN,
146-
NULL, // Optional application name
147-
cmd_line,
148-
cwd,
149-
env,
150-
&err);
151-
if (spawncfg == NULL) {
152-
emsg = "winpty_spawn_config_new failed";
153-
goto cleanup;
154-
}
155-
156-
DWORD win_err = 0;
157-
if (!winpty_spawn(winpty_object,
158-
spawncfg,
159-
&process_handle,
160-
NULL, // Optional thread handle
161-
&win_err,
162-
&err)) {
163-
if (win_err) {
164-
status = (int)win_err;
165-
emsg = "failed to spawn process";
166-
} else {
167-
emsg = "winpty_spawn failed";
168-
}
169-
goto cleanup;
170-
}
97+
if (!os_conpty_spawn(conpty_object,
98+
&process_handle,
99+
NULL,
100+
cmd_line,
101+
cwd,
102+
env)) {
103+
emsg = "os_conpty_spawn failed";
104+
status = (int)GetLastError();
105+
goto cleanup;
171106
}
172107
proc->pid = (int)GetProcessId(process_handle);
173108

@@ -186,11 +121,8 @@ int pty_process_spawn(PtyProcess *ptyproc)
186121
uv_run(&proc->loop->uv, UV_RUN_ONCE);
187122
}
188123

189-
(ptyproc->type == kConpty) ?
190-
(void *)(ptyproc->object.conpty = conpty_object) :
191-
(void *)(ptyproc->object.winpty = winpty_object);
124+
ptyproc->conpty = conpty_object;
192125
ptyproc->process_handle = process_handle;
193-
winpty_object = NULL;
194126
conpty_object = NULL;
195127
process_handle = NULL;
196128

@@ -200,16 +132,7 @@ int pty_process_spawn(PtyProcess *ptyproc)
200132
ELOG("pty_process_spawn(%s): %s: error code: %d",
201133
proc->argv[0], emsg, status);
202134
status = os_translate_sys_error(status);
203-
} else if (err != NULL) {
204-
status = (int)winpty_error_code(err);
205-
ELOG("pty_process_spawn(%s): %s: error code: %d",
206-
proc->argv[0], emsg, status);
207-
status = translate_winpty_error(status);
208135
}
209-
winpty_error_free(err);
210-
winpty_config_free(cfg);
211-
winpty_spawn_config_free(spawncfg);
212-
winpty_free(winpty_object);
213136
os_conpty_free(conpty_object);
214137
xfree(in_name);
215138
xfree(out_name);
@@ -232,12 +155,7 @@ const char *pty_process_tty_name(PtyProcess *ptyproc)
232155
void pty_process_resize(PtyProcess *ptyproc, uint16_t width, uint16_t height)
233156
FUNC_ATTR_NONNULL_ALL
234157
{
235-
if (ptyproc->type == kConpty
236-
&& ptyproc->object.conpty != NULL) {
237-
os_conpty_set_size(ptyproc->object.conpty, width, height);
238-
} else if (ptyproc->object.winpty != NULL) {
239-
winpty_set_size(ptyproc->object.winpty, width, height, NULL);
240-
}
158+
os_conpty_set_size(ptyproc->conpty, width, height);
241159
}
242160

243161
void pty_process_close(PtyProcess *ptyproc)
@@ -255,11 +173,6 @@ void pty_process_close(PtyProcess *ptyproc)
255173
void pty_process_close_master(PtyProcess *ptyproc)
256174
FUNC_ATTR_NONNULL_ALL
257175
{
258-
if (ptyproc->type == kWinpty
259-
&& ptyproc->object.winpty != NULL) {
260-
winpty_free(ptyproc->object.winpty);
261-
ptyproc->object.winpty = NULL;
262-
}
263176
}
264177

265178
void pty_process_teardown(Loop *loop)
@@ -434,40 +347,6 @@ static void quote_cmd_arg(char *dest, size_t dest_remaining, const char *src)
434347
}
435348
}
436349

437-
/// Translate winpty error code to libuv error.
438-
///
439-
/// @param[in] winpty_errno Winpty error code returned by winpty_error_code
440-
/// function.
441-
///
442-
/// @returns Error code of libuv error.
443-
int translate_winpty_error(int winpty_errno)
444-
{
445-
if (winpty_errno <= 0) {
446-
return winpty_errno; // If < 0 then it's already a libuv error.
447-
}
448-
449-
switch (winpty_errno) {
450-
case WINPTY_ERROR_OUT_OF_MEMORY:
451-
return UV_ENOMEM;
452-
case WINPTY_ERROR_SPAWN_CREATE_PROCESS_FAILED:
453-
return UV_EAI_FAIL;
454-
case WINPTY_ERROR_LOST_CONNECTION:
455-
return UV_ENOTCONN;
456-
case WINPTY_ERROR_AGENT_EXE_MISSING:
457-
return UV_ENOENT;
458-
case WINPTY_ERROR_UNSPECIFIED:
459-
return UV_UNKNOWN;
460-
case WINPTY_ERROR_AGENT_DIED:
461-
return UV_ESRCH;
462-
case WINPTY_ERROR_AGENT_TIMEOUT:
463-
return UV_ETIMEDOUT;
464-
case WINPTY_ERROR_AGENT_CREATION_FAILED:
465-
return UV_EAI_FAIL;
466-
default:
467-
return UV_UNKNOWN;
468-
}
469-
}
470-
471350
typedef struct EnvNode {
472351
wchar_t *str;
473352
size_t len;
@@ -484,7 +363,7 @@ static int build_env_block(dict_T *denv, wchar_t **env_block)
484363
{
485364
const size_t denv_size = (size_t)tv_dict_len(denv);
486365
size_t env_block_len = 0;
487-
int rc;
366+
int rc = 0;
488367
char **env = tv_dict_to_env(denv);
489368

490369
QUEUE *q;

src/nvim/os/pty_process_win.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,15 @@
22
#define NVIM_OS_PTY_PROCESS_WIN_H
33

44
#include <uv.h>
5-
#include <winpty.h>
65

76
#include "nvim/event/process.h"
87
#include "nvim/lib/queue.h"
98
#include "nvim/os/pty_conpty_win.h"
109

11-
typedef enum {
12-
kWinpty,
13-
kConpty,
14-
} PtyType;
15-
1610
typedef struct pty_process {
1711
Process process;
1812
uint16_t width, height;
19-
union {
20-
winpty_t *winpty;
21-
conpty_t *conpty;
22-
} object;
23-
PtyType type;
13+
conpty_t *conpty;
2414
HANDLE finish_wait;
2515
HANDLE process_handle;
2616
uv_timer_t wait_eof_timer;
@@ -38,8 +28,7 @@ static inline PtyProcess pty_process_init(Loop *loop, void *data)
3828
rv.process = process_init(loop, kProcessTypePty, data);
3929
rv.width = 80;
4030
rv.height = 24;
41-
rv.object.winpty = NULL;
42-
rv.type = kWinpty;
31+
rv.conpty = NULL;
4332
rv.finish_wait = NULL;
4433
rv.process_handle = NULL;
4534
return rv;

third-party/CMakeLists.txt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,6 @@ set(WIN32YANK_X86_SHA256 62f34e5a46c5d4a7b3f3b512e1ff7b77fedd432f42581cbe825233a
191191
set(WIN32YANK_X86_64_URL https://github.com/equalsraf/win32yank/releases/download/v0.0.4/win32yank-x64.zip)
192192
set(WIN32YANK_X86_64_SHA256 33a747a92da60fb65e668edbf7661d3d902411a2d545fe9dc08623cecd142a20)
193193

194-
set(WINPTY_URL https://github.com/rprichard/winpty/releases/download/0.4.3/winpty-0.4.3-msvc2015.zip)
195-
set(WINPTY_SHA256 35a48ece2ff4acdcbc8299d4920de53eb86b1fb41e64d2fe5ae7898931bcee89)
196-
197194
set(GETTEXT_URL https://ftp.gnu.org/pub/gnu/gettext/gettext-0.20.1.tar.gz)
198195
set(GETTEXT_SHA256 66415634c6e8c3fa8b71362879ec7575e27da43da562c798a8a2f223e6e47f5c)
199196

@@ -284,18 +281,6 @@ if(WIN32)
284281
elseif(TARGET_ARCH STREQUAL "X86")
285282
set(TARGET_ARCH ia32)
286283
endif()
287-
288-
GetBinaryDep(TARGET winpty
289-
INSTALL_COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_INSTALL_DIR}/bin
290-
COMMAND ${CMAKE_COMMAND} -DFROM_GLOB=${DEPS_BUILD_DIR}/src/winpty/${TARGET_ARCH}/bin/*
291-
-DTO=${DEPS_INSTALL_DIR}/bin/
292-
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyFilesGlob.cmake
293-
COMMAND ${CMAKE_COMMAND} -DFROM_GLOB=${DEPS_BUILD_DIR}/src/winpty/include/*
294-
-DTO=${DEPS_INSTALL_DIR}/include/
295-
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyFilesGlob.cmake
296-
COMMAND ${CMAKE_COMMAND} -DFROM_GLOB=${DEPS_BUILD_DIR}/src/winpty/${TARGET_ARCH}/lib/*
297-
-DTO=${DEPS_INSTALL_DIR}/lib/
298-
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyFilesGlob.cmake)
299284
endif()
300285

301286
# clean-shared-libraries removes ${DEPS_INSTALL_DIR}/lib/nvim/parser/c.dll,

0 commit comments

Comments
 (0)