Skip to content

I/R: support native Windows - #261

Open
DanielMidgley wants to merge 1 commit into
awslabs:mainfrom
DanielMidgley:main
Open

I/R: support native Windows#261
DanielMidgley wants to merge 1 commit into
awslabs:mainfrom
DanielMidgley:main

Conversation

@DanielMidgley

Copy link
Copy Markdown

Description of changes:

Makes the I/R daemon run under native Windows Python (no WSL). Linux and macOS
behaviour is unchanged -- every platform branch is guarded by IS_WINDOWS /
os.name (ISABELLE_PLATFORM_FAMILY in ML), and the new helpers in
ir/win_compat.py are pass-throughs on POSIX.

What was broken on Windows:

  • isabelle is a Cygwin bash script → WinError 193 on every subprocess call.
    Now run via Isabelle's bundled bash, with /cygdrive/ conversion for
    arguments going in and Windows form for getenv values coming out.
  • os.killpg / start_new_session / SIGHUP unavailable → terminate_tree(),
    SPAWN_KW, guarded signal registration.
  • AF_UNIX not exposed by CPython on Windows → the mgmt console uses an
    ephemeral localhost port plus a rendezvous file at the same path. That port is
    reachable by any local user, unlike a 0600 socket, so the Windows path adds a
    token and a per-user ACL on the file.
  • Locale codepage (e.g. cp1252) → UTF-8 reads failed, and the in the status
    lines killed startup with UnicodeEncodeError. Explicit UTF-8 reads + stdio.
  • Native Poly/ML cannot open Cygwin's /dev/urandomgenerate_token prefers
    IR_REPL_AUTH_TOKEN, minted by Python's CSPRNG.
  • SO_REUSEADDR on Windows also permits binding a port another process is
    actively listening on → I/R announced a port it did not own and hung with no
    diagnostic. Not set there now.
  • Java's PrintWriter.println sends CRLF → every repl_* call failed auth while
    repl_connect (which never authenticates) reported success. Line parsing is
    now CRLF-tolerant.

Tested on Windows 11 / Isabelle2025-2 / CPython 3.12: standalone --daemon, the
I/Q --daemon --expect-ml path, mgmt console auth accept/reject, --kill-daemon.
Not run on Linux locally.

ir/test_repl.py is untouched and still POSIX-only (os.killpg), so this file still does not run on Windows.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

The daemon assumed POSIX and would not run under native Windows Python.
Make it work there without WSL. Linux and macOS are unchanged: every
platform branch is guarded by IS_WINDOWS / os.name
(ISABELLE_PLATFORM_FAMILY in ML), and the new helpers are pass-throughs.

Add ir/win_compat.py for the differences. The `isabelle` launcher is a
Cygwin bash script that CreateProcess rejects (WinError 193), so run it
through Isabelle's bundled bash, with Cygwin's bin on PATH and paths
converted both ways — /cygdrive/ form for arguments in, Windows form for
`isabelle getenv` values out. It also replaces os.killpg /
start_new_session, guards SIGHUP, and forces UTF-8 stdio, since the
locale codepage cannot encode the "●" in the status lines and killed
startup with UnicodeEncodeError.

Swap the AF_UNIX management console for an ephemeral localhost port plus
a rendezvous file at the same path, leaving mgmt_socket_path() and
discover_mgmt_sockets() untouched. That port is reachable by any local
user, unlike a 0600 socket, so Windows clients must send a token and the
file is ACL'd to the current user.

Three protocol fixes: generate_token prefers IR_REPL_AUTH_TOKEN, minted
by Python's CSPRNG since native Poly/ML cannot open /dev/urandom;
SO_REUSEADDR is not set on Windows, where it also permits binding a port
another process is actively listening on, so I/R announced a port it did
not own and hung with no diagnostic; and line parsing tolerates the CRLF
that Java's PrintWriter.println makes I/Q send, which failed every
repl_* auth while repl_connect still reported success.

Tested on Windows 11 / Isabelle2025-2 / CPython 3.12: standalone
--daemon, I/Q --expect-ml, mgmt auth accept/reject, --kill-daemon. Not
run on Linux locally; the existing I/R CI covers that.
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.

1 participant