jart / cosmopolitan

build-once run-anywhere c library
ISC License
18.36k stars 630 forks source link

o/test/net/echoserver.com: Does not launch on Windows #102

Closed IngwiePhoenix closed 3 years ago

IngwiePhoenix commented 3 years ago

I am quite positive I missed something - but basically I read that the binaries built with Cosmopolitan would run "anywhere". So, I gave it a spin. Under WSL2, I had to add to binfmt as suggested by the synitycheck tool. After doing so,t he build succeeded.

Copying the echoserver example into my Windows home folder and running it, made Windows tell me it was not compatible (Powershell and CMD both gave no usable output whatsoever). I am not surprised; Windows doesn't know how to handle ELF files as far as I know.

Is there a way to actually launch binaries built via cosmopolitan on Windows? It is listed in the README.

Kind regards, Ingwie

ahgamut commented 3 years ago

Possibly similar to #92 or #82?

The binaries built by cosmopolitan modify themselves after running the first time, and if run on Linux first, are thereafter ELF binaries that won't run on Windows.

jart commented 3 years ago

Thanks for helping our friend @ahgamut. Per https://github.com/jart/cosmopolitan/issues/82#issuecomment-787583973 your APE binaries assimilate themselves as conventional residents of your platform after the first run, so they can be fast and efficient. It's a little bit of a hiccup for folks getting started with distribution, since that's such a new concept. Please feel free to leave feedback on how we might improve our documentation to explain it better.

I ran echoserver.com on Windows to confirm. There turned out to be a different issue which is that it had SOCK_NONBLOCK for some strange reason, possibly troubleshooting a while back. I'm going to push a change to remove that line until I have time to look deeper into the issue. At the moment non-blocking i/o is on the backburner for me personally, since I don't use it. I believe the great strength of Cosmo is that it makes binaries so tiny that fork() can be cheap and we can therefore afford to write simple imperative business logic for networking, similar to Go's greenlet model, or the 64kb threading model used by a certain company on charleston road.

IngwiePhoenix commented 3 years ago

Per #82 (comment) your APE binaries assimilate themselves as conventional residents of your platform after the first run, so they can be fast and efficient.

That is quite important to know - could you please add this to the README? I totally fell for that. Deleting, re-compiling echoserver.com and just copying it over without running it first made it run immediately and just fine. Using the file command also showed the file to be a DOS/MBR boot sector.

"64kb threading model"? I never heared of that before. Would you mind linking me to an explanation or something?

Non-blocking I/O usually gets used in applications that are big enough that they merit a proper per-platform release anyway. So I guess it's fine.

jart commented 3 years ago

Sure we can do that!