-
-
Notifications
You must be signed in to change notification settings - Fork 645
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
Building Cosmopolitan on Windows #117
Comments
Tried again with a debug version of
|
Earlier on this project's history I took certain liberties with functions like |
I've now addressed the issue you encountered. Thanks for the report. It's amazing how easily code compiles on Windows when you have the canonical GNU/Linux compiler. It'd do much to attract contributors to this project if Windows and Mac users didn't need to SSH into a Linux box and write code in a terminal like me. I posted further thoughts on this subject in the associated PR here: #116 (comment) |
Thanks for the new Some short notes of problems I have hit or worked around so far.
Regarding VS Code-related comments on the PR:
I would be happy to include a
I think we can definitely do something like this to bootstrap VS Code IntelliSense. It might even work right now on Linux. Regarding cross9:
Good idea. If we can get the build working as a proof of concept, the next step will be to make it as simple as possible. I think it'd be nice to provide an experience that's as easy for Windows-based developers as it currently is for Linux-based developers. That is: install Git, clone the repo, install make, type Question on I really like the idea of using a "small" static binary for cross-compiling. If we can't get there with chibi yet then gcc is a decent substitute. I suspect that on Windows you could install the whole MSYS2 stack to get further, but that feels rather heavyweight to me. What drew me to this project is the idea of stripping C back to the bare essentials, especially on Windows where it quickly gets messy after going beyond the bundled |
Another data point on the |
Cross9 is the result of trial and error last year using artifacts sourced from gnu / msys2 / mingw64 / etc. That's documented by the accompanying zipped work directory which contains sources and patches. I don't want to be in the business of distributing GCC long term. I posted the experiment upon request because no one else distributes an elf compiler for windows and chibicc doesn't have a linker yet. As soon as that happens we'll have a ~350kb C11 toolchain that'll satisfy your retro nostalgia without requiring you to sacrifice modern features. It may not be as good as GCC and Clang at multiplying matrices, but a tiny compiler is better than no compiler. GNU Make is less of an issue since it's stable, easy to compile, and the prebuilt binaries distributed by other channels work fine, although it might be nice to vendor someday simply for the sake of total hermeticity. It's likely the vfork() + execve() polyfills used by compile.com need to be improved. For example, we've needed to use exponential backoff in our rmdir() polyfill thanks to the limitless peculiarities of the new technology executive. Argument limits can be worked around using tricks like |
Okay, I have tried to create a load test which will recreate these I started with a tiny fake C compiler, compiled with the using System;
class FakeCc {
static void Main(string[] args) {
if (Array.Exists(args, arg => arg == "--version")) {
Console.WriteLine("fakecc.exe (.net) 0.0.1");
return;
}
string c = Array.Find(args, arg => arg.EndsWith(".c") || arg.EndsWith(".S"));
string o = Array.Find(args, arg => arg.EndsWith(".o"));
System.IO.File.Copy(c, o, true);
}
} Then, in Git Bash: $ pwd
/c/Users/alicl/git/cosmopolitan
$ mkdir tmp
$ cd tmp
$ cp ../fakecc.exe ../build/bootstrap/compile.com .
$ dd if=/dev/urandom bs=1024 count=5 of=blob.c
5+0 records in
5+0 records out
5120 bytes (5.1 kB, 5.0 KiB) copied, 0.0102543 s, 499 kB/s
$ for i in `seq 1 1000`; do cp blob.c blob-$i.c; done
$ for i in *.c; do ./compile.com ./fakecc.exe $i $i.o; done
./fakecc.exe blob.c blob.c.o
./fakecc.exe blob-1.c blob-1.c.o
./fakecc.exe blob-10.c blob-10.c.o
# ... eventually the EXITED WITH 5 error occurs I tried it with empty files (0 bytes) and the error did not occur. I also tried on Powershell PS C:\Users\alicl\git\cosmopolitan\tmp> foreach ($f in gi ".\*.c") {
>> .\compile.com .\fakecc.exe "$f" "$f.o"
>> }
.\fakecc.exe C:\Users\alicl\git\cosmopolitan\tmp\blob-1.c C:\Users\alicl\git\cosmopolitan\tmp\blob-1.c.o
.\fakecc.exe C:\Users\alicl\git\cosmopolitan\tmp\blob-10.c C:\Users\alicl\git\cosmopolitan\tmp\blob-10.c.o
.\fakecc.exe C:\Users\alicl\git\cosmopolitan\tmp\blob-100.c C:\Users\alicl\git\cosmopolitan\tmp\blob-100.c.o
# etc ... No error! Two possibilities:
The problem is that to use GNU Make on Windows, we need to go through MINGW64 anyway. So I made a Makefile... PS C:\Users\alicl\git\cosmopolitan\tmp> cat .\Makefile
SRCS = $(wildcard *.c)
OBJS = $(patsubst %.c,%.c.o,$(SRCS))
all: $(OBJS)
%.c.o: %.c
./compile.com ./fakecc.exe -o $@ $<
PS C:\Users\alicl\git\cosmopolitan\tmp> make
./compile.com ./fakecc.exe -o blob-971.c.o blob-971.c
./fakecc.exe -o blob-971.c.o blob-971.c
./compile.com ./fakecc.exe -o blob-972.c.o blob-972.c
./fakecc.exe -o blob-972.c.o blob-972.c
./compile.com ./fakecc.exe -o blob-973.c.o blob-973.c
./fakecc.exe -o blob-973.c.o blob-973.c
# etc Works. Both inside Powershell and also inside Git Bash. It seems this is really some kind of laggy race condition type thing. Does any of this help @jart ? I'm not really sure where to start looking for the problem with the NT fork/exec. |
I know that MinGW and Cygwin I'm pretty sure set up special infrastructure for handling things like posix signals, so it could be possible that some code on their end is upset with compiler.com for not interacting with that. It sounds like a tough nut to crack. It would be nice to have this fixed. But one thing worth noting is that in my personal experience, the fastest possible native build on Windows is still going to go slower than than a build that runs inside a Linux VM on Windows, due to the multiprocessing model tools like make assume. One avenue that might be worth exploring is getting GNU Make to build with Cosmopolitan. Then we could rule out the influence of msys. |
Just to log my status on this, I have been noodling around with various different things on Windows in my spare time. Obviously WSL is the easy solution, but I'd still like to get it built once all the way through as a proof of concept. It's a good learning experience to dig through all the problems. I've switched to experimenting with LLVM to try to remove another MingW/MSYS layer from the stack. The make problem outside of Git Bash is tricky, because GNU make on Windows is also tied to the existence of Anyway, my latest tack has been seeing what kind of minimal shell I could get to work on Windows. It doesn't need to be interactive or have job control to be usable by make. I got oksh (https://github.com/ibara/oksh) compiling under Cosmopolitan, which was cool. Crashes hard on Windows, though. Then I switched to Unbourne shell in the examples directory. I've made some small changes in my local to get it not completely and utterly failing on Windows due to different TLDR, it's a work in progress. If I find anything that is easy to isolate and might also improve other platforms, I'll send a PR. |
Yeah the git debian almquist shell in examples/unbourne.c is the shell of shells, so getting that to work better on Windows would be a good area of focus. The first thing Ken Thompson built when he created the UNIX operating system was its shell, since that's what made everything else possible. Would you permit me to order you a W. Richard Stevens book that can help you accomplish this task? If so, please email me your address. |
I'm interested in this as well, as I'm running windows8 and have attempted to compile redbean using cross9; I ran into several issues that I haven't been able to resolve, so ended up going the WSL route on a different machine, but it would still be great to be able to compile using cross9 binaries (I have mingw/msys and clang installed as well). My main issue was that the make scripts have -musl- binaries hardcoded, so it was difficult to reorganize them. There are also dependencies on |
Issue #180 also offers new hope for LLVM builds on Windows if we can git bisect a regression since the 0.2 release. As for compiling the cosmo repo itself on Windows, I've gotten it to come pretty close in the distant past. However in my experience, even if that works, it still goes faster to build cosmo inside a Linux VM or container on Windows than it does to build on Windows itself, due to the way Windows is. The same is true of MacOS. I'm open to patches that help us improve. It'd be nice to be build-anywhere run-anywhere if it can be done elegantly and particularly if there's a way to set up GitHub workflows so it's tested. It would however be sad if the Windows workflow ended up being ten minutes when the Travis Linux workflow currently takes 2 minutes. |
Unfortunately the past few months I haven't really had the time to look at this project, but I did find the LLVM approach more promising than cross9 gcc back in March. I still feel like the main sticking point is the Makefile and associated build scripts and binaries. We could probably get it all building if we wrote a custom build just for Windows, but it'd be nice if it was a bit more one size fits all, in the spirit of the project. Hopefully I will have a chance to get back to this at some point. |
couldnt you do it in msys2 enviroment, yeah it is heavy but, it should be possible? |
It's now possible to compile the mono repo on Windows. It's a little rough around the edges until we fix #1010 so you can't use the latest release. But you should be able to use https://github.com/jart/cosmopolitan/releases/tag/3.2. Here's what you do. You grab the cosmocc.zip. Extract that into |
After having a look at the cross9 gcc from https://justine.lol/cosmopolitan/windows-compiling.html it occurred to me that we should be able to compile Cosmopolitan libc itself on Windows. The main missing piece is GNU make, which there is a small static version of inside Chocolatey at https://chocolatey.org/packages/make
I just had a quick experiment and had to add
-Wno-attributes
, but it actually succeeded in building a couple of the bootstrap binaries, and they Just Work. (Update Alas, the bootstrap binaries were vendored.) First bug happens here...This seems promising to me. I would really love to be able to build end-to-end all on Windows without spinning up a WSL VM. Is this something worth pursuing? It will need a few Makefile tweaks, which we could probably do same way as LLVM mode.
The text was updated successfully, but these errors were encountered: