-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
cygwin support #751
Comments
I think you might have better luck in the llvm6 branch, but there are some zig additions needed. LLD added a MinGW driver API which is probably what we should use for cygwin. |
LLVM 6 rc2 just came out today. It's scheduled to be released at the end of February. Zig will release 0.2.0 1 week after that, at which point master branch will depend on LLD 6 and we can focus on cygwin support. |
Interesting. I was looking for COFF diffs in llvm6 today, but I didn't notice the MinGW driver. It looks like in it's current state it's just doing some simple argument translation, so I'm doubtful it'll help too much since zig already deals with msvc-style linker args. I'll take a look at the llvm6 branch. |
we could also ask a question on the llvm mailing list. The LLD maintainers are pretty responsive when it comes to COFF. I believe there should be a lot of interest in getting this working since it benefits the entire LLVM community and not just zig. |
maybe we are supposed to use the ELF linker interface from LLD for cygwin? and the target triple would be x86_64-windows-gnu ? |
I think windows-gnu is mingw, and I'm pretty sure lld/ELF is only for elf format objects, but I could be wrong. https://llvm.org/doxygen/Triple_8h_source.html#l00542 I'll do a bit more digging. |
Ah right, of course, the cygnus environment. So we can use that to detect that we should link for cygwin. (I'm guessing you are already doing that in your branch.) I sent an email to the mailing list: http://lists.llvm.org/pipermail/llvm-dev/2018-February/121066.html |
It looks like the LLD team is willing to work with us to support cygwin. |
I was thinking that this probably is the case, I just need to figure out what's needed. In my branch I added
But even that's not entirely accurate, because we can target:
So it would be odd to call the first one MSVC when it doesn't have anything to do with MSVC. Another source of inspiration is how nixpkgs handles them: |
Thanks, this all makes sense. Can you show me the linker script that you would want to use, and maybe I can look at it and suggest how we can achieve it in a different way? |
Sure, what I have now:
The hello.o ones are probably just a missing library. The libcywin ones seem to be from the linker script. It's built into ld, so I dumped it with -verbose:
|
As you mentioned, the hello.o errors can be fixed by implementing the named functions in std/special/builtin.zig. I'll send an email to LLVM developers for the others. |
Thanks. There are a few examples of synthetic symbols in the COFF linker, so I'll see if I can get something working myself. |
I actually found a library that defines those symbols from hello.o. Linking then completed once I added:
Unsuprisingly the executable crashed immediately, but I think I've got an idea of how to hook up those symbols. |
|
That's a good question. My gut feeling is that there's a lot of subtleties about the cygwin linker script that will need to be carefully handled for e.g. tls, forking, C/C++ stuff. If I manage to get a working hello.exe from zig, I'll probably build a standalone lld and test some C/C++ stuff. |
Looks like it's going to need a fair amount of work to link What are your thoughts on certain platforms using an external linker (e.g. GNU ld)? |
I think it's really important that we do not depend on an external linker - it's one of the major design decisions that defines the Zig project. I think it's worth it to work through the problem by contributing to LLD, even if we have to delay proper cygwin support. I think the LLD team will be pretty helpful when working through this particular problem. |
Fair enough. At least it's probably something the LLD team will want, since the target is already working with clang/ld. |
FYI I'm still working on this here and there in my spare time, but I still haven't got the .idata stuff linking properly. On top of the linker script, there's a bunch of custom stuff in binutils, e.g. Next step is to read the COFF docs and figure out why the .idata inputs aren't linking to a valid import table. |
I want to re-evaluate this issue. What's the use case for cygwin anymore? Windows has a subsystem for linux. Zig can target Windows directly. At this point I don't think cygwin is worth supporting. |
Sorry for not updating. I got pretty stuck and haven't had a chance to go back to it. WSL has enough serious problems that IMO it's not a worthy replacement for cygwin, at least not yet, and they aren't making progress particularly quickly. We'll see about the WSL2 thing they just announced, but that just sounds like them giving up and going back to a traditional VM. Using windows apps from cygwin is possible, you just have issues with filesystem path conversion, signalling, forking doesn't work, etc. That being said, I'm probably not going to have time to finish this myself, and it's very niche, so I'll understand if you close it. |
Many open source libraries only work on windows in a cygwin environment. WSL feels like a totally different machine, and doesn't work well with GUI applications. Zig might be used to write a library to be used by other applications, or your zig application may want to link against other libraries that only work on windows via cygwin. I would keep the door open to support, but I don't think it's a priority. |
As it currently stands, there is no plan to support cygwin. |
@andrewrk commented on May 9, 2019:
These days Cygwin could be used at least to bootstrap Zig without LLVM, #17892. Now if I add the recognition into
... it fails with
Other implementations of POSIX environments for Windows (like MSYS2, Midipix) would be nice to have supported too. Using MinGW64 doesn't work either:
|
Fingers crossed. I am on Windows and I am not interested in WSL2. I prefer cygwin. Lots of software can be more maintainable if they move to Zig. e.g. libtecra, this is stuck in 2014. A classical C/autotools software. |
You don't need msys2, cygin, wsl, wsl2, nor midipix to use zig. Zig has native Windows support. |
Using zig with cygwin/msys2 has some advantages compared to native Windows support. For example:
|
Zig is not going to support Cygwin. Personally, I think the project should retire, because it's too much of a hack - fundamentally broken and too buggy for serious usage. A cute party trick that was taken too far. I'm going to lock the thread because the matter is settled and I want to have the last word be this criticism of Cygwin. |
I had a look at making zig target cygwin, and got most of the way there: cygwin target definition, stdlib changes, etc. but I got stuck on the linker.
The lld COFF linker doesn't support linker scripts, but the cygwin linker script is needed to set up
__data_start__
etc.Any thoughts on where to go from here? Is it a waste of time?
The text was updated successfully, but these errors were encountered: