Hacker News new | past | comments | ask | show | jobs | submit login
Cygwin 3.0.0-1 (cygwin.com)
107 points by andyonthewings 37 days ago | hide | past | web | favorite | 39 comments

Wow, major release.

I should rebase Cygnal to Cygwin 3.0.


Hadn't seen this until now. This project looks great.

As someone who has mostly used the MSVC environment on Windows, can you comment on how often Cygwin allows for a Linux port to compile and run with no source changes? I read a while back that the fork "emulation" is a performance hit. I wonder if Cygwin benefited from the WSL fork implementation [0]

0. https://news.ycombinator.com/item?id=11391797

Not all programs need to fork, obviously.

Programs that fork and immediately exec can be improved under Cygwin by using the spawn, family of system calls, like what I have here:


in this source file there is a version of the run function that uses _wspawnvp, support for which is detected in my ./configure script. Well, _wspawnlp, but they're in the same family:

  printf "Checking for _wspawnlp ... "

  cat > conftest.c <<!
  #include "config.h"
  #include <process.h>
  #include <wchar.h>

  int main(int argc, char **argv)
    wchar_t *wargv[] = { L"foo", L"bar", 0 };
    int r = _wspawnlp(_P_WAIT, L"foo", wargv);
    return 0;
  if conftest ; then
    printf "yes\n"
    printf "#define HAVE_WSPAWN 1\n" >> config.h
    printf "no\n"
The porting experience of Unix and Linux programs to Cygwin is pretty darn good. You can tell just from the large number of packages that are available under Cygwin.

Even programs that use termios to put the TTY in raw mode and use ANSI escape sequences to control the screen work in Cygwin. Cygwin's I/O system contains a layer that translates ANSI codes to Win32 Console API calls. This works inside the Windows CMD.EXE console, not only the Cygwin terminall.

> inside the Windows CMD.EXE console

You have a typo in conhost.exe there. The Windows console has native support for those escape sequences by now too, though.

I never distributed my binaries to other Windows users - I merely used Cygwin to get a familiar Unix environment on Windows since 2007 or so. Everything worked seamlessly. I remember compiling multiple versions of Python using it.

Cygwin used to be GPL-ed, so there was a licensing hurdle. You couldn't legally do this kind of redistribution with proprietary programs, only with GPL-compatible programs.

Two or three years ago there was an announcement on the mailing list that Cygwin it's switching to the LGPL. I kicked off the Cygnal project that very day, pretty much.

Not really. cygwin (the DLL) is MIT and cannot use any GPL sources. Hence most of the libc is taken from FreeBSD.

The Cygwin DLL is based on something called Newlib from BSD, but it contains considerable new code from the Cygwin project. As a whole, it is LGPL-ed, with a special exception that also allows static linking.


I missed that LPGL switch in 2016, but I obviously mixed that up somehow. We never could use any GPL sources in newlib, hence it was always far behind other libc's. And the biggest problem gone seems to be the mandatory CLA.

But nowadays cygwin lost it's dominant role from a decade ago.

Cygwin is the pioneer in Unix on Windows but it's been superseded by the MSYS2. I say this with caution though: MSYS2 is inspired by the Cygwin. But it's just more authentic because you use real Windows applications doing Unix jobs.

How does MYSYS2 supersede cygwin? From the wiki (https://github.com/msys2/msys2/wiki/How-does-MSYS2-differ-fr...) that's not really clear:

> Cygwin tries to bring a POSIX-compatible environment to Windows so that most software that runs on unices will build and run on Cygwin without any significant modifications. Cygwin provides a large collection of packages containing such software, and libraries for their development.

> MSYS2 tries to provide an environment for building native Windows software. MSYS2 provides a large collection of packages containing such software, and libraries for their development. As a large portion of the software uses GNU build tools which are tightly coupled to the unix world, this environment is also POSIX-compatible, and is in fact based on Cygwin.

For someone that uses cygwin (still on windows 7) heavily everyday what benefit would I get from MYSYS2?

> MSYS2 tries to provide an environment for building native Windows software.

And that is pretty darn useless. People writing for Windows fall into two camps: FOSS people (and perhaps proprietary SW people also) who develop on Linux and Macs using POSIX API's. They need decent POSIX for porting the programs to Windows more easily. And then we have people who develop for Windows. They use Microsoft Visual Studio. Windows is proprietary; the idea that you need some free tools to write code that only works on a proprietary OS is absurd. Visual Studio with basic features can be obtained free-as-in-beer. The last time I developed a Windows-only program, I just used VS2008.

Cygwin provides a decent POSIX porting experience to Windows. My "Cygnal" project, consiting of a small number of patches to Cygwin, allows programs ported to Windows via Cygwin to have more Windows-like personality. For path handling is Windows-style: drive letter names work, "currently logged directory" (per drive) works. The system() function in Cygnal uses cmd.exe, not /bin/sh, and even programs that try to fork and exec /bin/sh (reimplmeenting their own system, effectively) are redirected to cmd.exe. The PATH environment variable is semicolon-delimited; no conversion takes place on env vars. Various little things like this are fixed. And you don't have to rebuild anything; just compile a program for Cygwin, then deploy it with the patched cygwin1.dll. Programs can easily detect which one they are running with, in case it's useful to provide some alternative logic.

The MinGW family provide a good solution for programs that are highly platform-independent, like certain kinds of "non-POSIX-heavy" utilities.

MSYS2 is based on a fork of recent Cygwin, just like MSYS is a fork of ancient Cygwin.

The idea behin MSYS was to create a stripped down Cygwin that doesn't provide a complete Unix or Linux-like environment on Windows, but provides only a toolchain: compilers and some common tools for building programs. That toolchain cross-compiles programs to Windows, using the system library MSVCRT.DLL as their run-time. That toolchain, supported by the MSYS run-time, is called "MinGW". MinGW-copmiled programs are not MSYS programs. MSYS is not so easy to extend.

The MinGW toolchain (or rather just its compilers) are available under Cygwin as a package. If you want to build MinGW programs, Cygwin with the MinGW package is a way better way to go: you can easily use any build tool that you need. Adding new utilities to Cygwin is easier than extending MSYS. You have the host environment there with the host compiler. Does your MinGW program need Ninja or CMAKE? or AntLR? Just build them and use them.

MSYS2 is basically more of the same as MSYS, just forking from a newer Cygwin. The cross-toolchain is now called MinGW-Win64 or something. Programs built with this now don't just link to MSVCRT.DLL; there is now some run-time library material, like a package of POSIX threads and whatnot.

MinGW and MinGW64 are not very good systems if your software requires a significant POSIX layer. I couldn't port the TXR Language to Windows using either of these. The Cygnal project is much smarter for this requirement area: about twenty or so well-targeted patches to the Cygwin DLL to bring about more Windows-y behaviors where Cygwin goes overboard with the POSIX simulation.

For instance, one thing that my program needs from the environment is a working POSIX termios: #include <termios.h>, tcsettattr/tcgetattr and so on. Plus working ANSI/VT100 escape sequences.

All that stuff ports to Windows with Cygwin/Cygnal.

The fact that "termios" isn't a "native" component in Windows is a completely immaterial, emotional argument. A Python list comprehension isn't native Windows either, and neither is a C++ std::map.

If my program relies on "termios", then a run-time which provides a faithful rendition of it is more convenient than one where I have to port all that console handling code to use the Win32 Console API.

Looks cool. I'm, however, very happy no attempt to make me use Windows was made since 2008 or so and, therefore, I didn't have much use for either system.

When I had to work under Windows I maintained >200 cygwin packages. Only about 10% needed trivial fixes for linux'isms or BSD'isms.

fork has its own implementation, cygwin is entirely unrelated to WSL (as before the Interix subsystem). It's extremely slow though. WSL or mingw are much faster. But mingw is a pain.

MinGW has a fork function?

Maybe that newer MinGW-W64 project or whatever it is called.

The original MinGW that just links programs to the system library called MSVCRT.DLL.

It provides POSIX porting only the extent of the meagre support for a few POSIX functions in MSVCRT.DLL. That has things like open, read and dup2, and a half-baked stat and such.

No, only cygwin (and WSL) can emulate fork, mingw needs the slower spawn, without COW. Or mingw programs emulate fork via threads.

I remember doing C development and noticing performance issues when using the posix functions versus the win32 api equivalent functions...

There is a layer there. The POSIX API's in Cygwin drive a framework of C++ objects, underneath which are ultimately Win32 functions. So that's not going to be faster than just those Win32 functions.

The Win32 functions are available to Cygwin programs.

What is the use case for Cygwin vs. WSL at this point?

Cygwin programs are (almost) native Windows programs. You can compile a POSIX-y program under Cygwin and it becomes a Windows program; you can ship it to a user if you just include a few DLL's that it needs.

I forked Cygwin's main DLL (cygwin1.dll) to create "Cygnal": an drop-in alternative that provides more Windows-like behaviors in various areas. Programs built under Cygwin can be bundled with Cygnal. Then (for instance) they have path handling that is familiar to Windows users.

WSL is great for when you can tolerate's WSL's incorrect, broken floating point math. [1]

If you need your math to be correct, use Cygwin.

[1] https://github.com/Microsoft/WSL/issues/830

What's broken is code that relies on long double offering more precision than double and expects to be portable. That's not guaranteed by the standard and isn't going to be true on all architectures.

To be fair, WSL claims to be (x86) Linux binary compatible. It's giving different results from actual Linux for the same binary.

Or pressure MS to fix it. They are rolling updates to WSL quite fast.

There's been pressure, it's not a priority.

It does seem a little niche, to be honest.

WSL filesystem performance is garbage, for one thing. Chances are good that if you're using Windows but you want to be using a Unix OS, it's your work that's forcing you to use Windows. And, if that's the case, chances are also good that the reason for that has something to do with a slew of legacy software that only runs on Windows. If both of those things are the case and you're trying desperately to develop a Unixy workflow, very clean integration with native Windows binaries is an unfortunate must. Cygwin delivers in that area much more effectively than WSL. Obviously Unix is my preference, but if I can't have Unix than I'd rather have Unix tools on the OS I'm being forced to use than a Unix sandbox will always be less than a real Linux/BSD install but fails to integrate properly with the OS I'm using by necessity.

The funny thing about both Cygwin and WSL is that, in my experience, many of the people who make use of them wish that they didn't have to make use of them. For me, Cygwin makes it a little easier for me to forget I'm not where I want to be (especially with things like winpty and apt-cyg). In Cygwin I can run URxvt just like at home, and run all the nonsense legacy software I need to for work, just like it were actually reasonable. In WSL, I can do none of that. It just doesn't work. I have a few co-workers who run WSL alongside cmd.exe. If I'm going to have to do that, I'd rather just stick to Cygwin.

There's also Msys/gnuwin32 which has some advantages over cygwin.

Supporting Windows <10

Need to support Windows 7, for example.


Access to Win32 APIs.

Static link and distribute to any windows user.

Better interoperability with Windows/cmd/powershell

Its nice to have alternatives.

You may consider that WSL is to Cygwin as Wine is to Winelib.

> - Support for case sensitive directories. mkdir(2) automatically creates directories within the Cygwin installation dir as case sensitive now.

> This feature requires Windows 10 1803 or later and WSL installed!

Interesting, so is cygwin going to be based on WSL?

The attributes to set and unset per-directory case sensitivity have always been available to Win32 processes. It is not specific to WSL (though Windows won't allow it unless you tick the WSL box in the Features dialog. You don't need to install any Linux distro after that.)

Used to use Cygwin at work, where I was not allowed to use Linux, just Windows.

Remember putting all the usr binaries (cat,ls,sed,etc.) in the windows path and it was great!

Among other significat changes - using kerberos over LSA... Interesting!

Applications are open for YC Summer 2019

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact