-
Notifications
You must be signed in to change notification settings - Fork 71
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
Posix-based windows implementation #497
Conversation
This issue is relevant here. Unix.select works well with sockets on Windows, but the emulation for non-sockets is not 100%. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Are some of the examples able to run on Windows (hello
, or even net
?).
Deleting everything marked as deprecated would shrink it a bit.
CI is failing to find Eio. Probably just needs opam pin --with-version=dev
.
lib_eio_windows/sched.ml
Outdated
let fd_map = Hashtbl.create 10 in | ||
let t = { run_q; poll; poll_maxi = (-1); fd_map; eventfd; eventfd_r; | ||
active_ops = 0; need_wakeup = Atomic.make false; sleep_q } in | ||
let eventfd_ri : int = Obj.magic eventfd_r in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think file descriptors are ints on Windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
definitely not an integer; https://github.com/ocaml/ocaml/blob/trunk/otherlibs/unix/unixsupport.h#L43
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's a little embarrassing ^^" Will fix soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The incorrect use of Obj.magic
has been removed in 3ab48ea -- I'm now relying on comparing Unix.file_descr
for the set of things to check to read and write.
Yep both work :)) And yes, I was a little too copy-paste happy and can remove all the bits that are not needed shortly. With regards to CI, I'm trying to get it working over on a different branch to avoid noise here https://github.com/patricoferris/eio/actions/runs/4829634872/jobs/8604900630. Setup-ocaml uses an old version of opam I think so I can't use
These are all probably prerequisites before an Eio_windows release? |
Where's the dependency on ocplib-endian coming from? We removed it from cstruct a while back, and it shouldn't be necessary these days. |
Crowbar I think https://ocaml.org/p/crowbar/latest |
On Windows OCaml uses flexdll / flexlink for DLLs. So, on Windows, if you want to be able to load a C library dynamically, e.g. to use it from the OCaml toplevel, utop, or mdx, for example, then that library needs to be compiled (with I ran into this problem when trying to run tests with the luv backend. See here for an ugly hack with which I managed to actually be able to build luv to support dynamic loading on Windows. |
Thanks @polytypic, I think that explains some of the errors I was seeing (which I've disabled I think). I'm not sure yet what's causing the new mdx errors in the CI (the stackoverflows with pretty bizarre line numbers). |
Hmm are we going to be bitten here by
|
@polytypic just for extra clarity this was the kind of error I was seeing with MDX -- it looks very similar to the one you had with Luv only but not quite the same maybe.
|
Yes, I saw those kinds of errors also. The functions that may/need to be dynamically loaded should be marked with |
We shouldn't have to manually annotate declspec(dllimport) in user stubs like cstruct these days. The full background is in ocaml/ocaml#1633, but I'm not sure what the current state of those tools are as Cygwin64 itself has been a moving target. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a few minor comments in-line, but basically good to merge once CI is passing. Currently, it says:
Error: Library "eio_windows" in _build/default/lib_eio_windows is hidden
Probably ocaml/dune#5505 again. The solution is to use (* -*- tuareg -*- *)
mode in the dune test file and disable the tests when not on Windows (see https://github.com/ocaml-multicore/eio/pull/475/files).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure yet what's causing the new mdx errors in the CI (the stackoverflows with pretty bizarre line numbers
[mdx] Fatal error: File "ctf.md", lines 33570790-33570791: Stack overflow
Does it work locally on Windows?
Given that ctf.md
is using almost no features of Eio (just Eio.Private.Ctf.mint_id
), this seems likely to be an MDX bug. If we can reproduce it without the #require "eio"
, we can report it there.
It's a good sign that the CI is able to build on Windows though, even if the tests fail. Just checking the build works is probably OK for this PR. We know many of the real tests will fail anyway.
It's working locally for me (it would be nice to have a second person verify that). I agree it seems to be something going wrong with MDX and Windows, but only appearing in the CI. I'll see if I can make a demo repo with MDX failing like that to report (and maybe fix ^^") upstream -- we really need mdx to work on Windows in the long run ! |
I threw a very simple md file into the tests that has zero dependencies and it also fails with the stackoverflow error see https://github.com/patricoferris/eio/actions/runs/4872160326/jobs/8689998313#step:5:22 EDIT: And so does macOS ^^" https://github.com/patricoferris/eio/actions/runs/4872160326/jobs/8689998021 EDIT EDIT: Also, I was probably meant to have done something with CRLF... Whilst investigating MDX issues I wrote a markdown file with this and it just hangs when you try to do things it seems. |
For the CRLF bits see realworldocaml/mdx#294 |
Yeah, so to summarise my thoughts, the MDX issues are:
So perhaps for this PR we can disable all MDX tests on Windows in the meantime and work to fix the declspec(dllimport) issues? To make up for the disable tests I can add more to the Alcotest tests on the windows backend? |
Sounds good to me! |
Co-authored-by: Thomas Leonard <talex5@gmail.com>
15a8db2
to
f3d7051
Compare
I just got this PR to build and test on my Windows machine. I'll try to take a moment to read through the changes today. |
lib_eio/unix/fork_action.c
Outdated
@@ -67,13 +70,17 @@ CAMLprim value eio_unix_fork_execve(value v_unit) { | |||
} | |||
|
|||
static void action_fchdir(int errors, value v_config) { | |||
#ifdef _WIN32 | |||
uerror("Unsupported operation on windows", Nothing); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't allocate OCaml exceptions here (or in the other actions) as we're in the child and anything involving GC isn't going to work.
uerror("Unsupported operation on windows", Nothing); | |
eio_unix_fork_error(errors, "action_fchdir", "Unsupported operation on windows"); | |
_exit(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh good catch thanks! Fixed the others too in cab124d
b56dfe3
to
cab124d
Compare
I do wonder if (when it is ready) we should merge this into a stable Windows branch instead of the |
We already can't cut a release, because we got rid of the Windows support from libuv and didn't replace it with anything yet. |
I understand that the POSIX backend for Windows is just a stopgap measure while waiting for a more performant IOCP backend, but just for future reference here's another issue with the emulation in |
This is a revised version of #490 (as part of #125). As mentioned in the previous PR, for an Eio 1.0 we're looking to have functional support for windows in a rigorous manner. To that end this PR implements a Windows backend using a mostly unchanged
Eio_posix
backend (directly copied over) with the following modifications and points of note:Unix.select
I started looking into adding a Windows backend toiomux
then I stumbled across poll and the use of Wepoll. I tried to simply useWSApoll
but of course that completely doesn't work for anything but sockets, so to minimise the diff and just get something working I went withUnix.select
which I believe should just work for files and sockets a like and is pretty well tested.Eio_main
tests. I'll look into that, it seemed to be something about a dll and flexlink or something.Unix_cstruct
unix: add Cstruct_unix.{read,write,writev,send,recv} mirage/ocaml-cstruct#302 -- if this can't be merged, we could probably vendor the stubs. We still need other functions implemented likepread
andpwrite
which is a bit awkward because of the differences in how the FD current offset is changed compared to Unix systems...This is an initial draft, I want to go over the Unix.select stuff and of course do more testing. Maybe then a follow-up PR can come in to add FS operations and the other missing pieces.