Gentoo Archives: gentoo-alt

From: Michael Haubenwallner <haubi@g.o>
To: gentoo-alt@l.g.o
Subject: [gentoo-alt] Re: Future of x64-cygwin, x86-winnt?
Date: Tue, 19 Jan 2021 09:46:16
Message-Id: 529e02e0-22da-bb29-3007-f5120e932f44@gentoo.org
In Reply to: Re: [gentoo-alt] Future of x64-cygwin, x86-winnt? by Sid Spry
1 On 1/18/21 5:42 PM, Sid Spry wrote:
2 > On Thu, Jan 14, 2021, at 5:38 AM, Fabian Groffen wrote:
3 >> Please chime in if you have an opinion, info, interest, etc.
4 >>
5 >
6 > Chiming in to state the platforms are all subtly different. Cygwin
7 > is POSIX compliant (or tries to be) and allows access to the underlying
8 > Windows APIs while WSL does not generally allow access to the rest
9 > of the system.
10
11 Exactly. However, since some version, WSL seems to be able to execute
12 binaries from the underlying Windows system, quite similar to Cygwin.
13
14 > MSYS2 does not aim for full POSIX compliance but does
15 > try to offer a familiar build environment. It also supplies a package
16 > manager CLI.
17
18 AFAICT, the MSYS2 distro uses the Cygwin DLL, but configured a little
19 less POSIXly, so we have decided to stick with the Cygwin distro as the
20 POSIX system to run Gentoo Prefix on Windows when Interix phased out.
21 Meanwhile, as WSL becomes more mature, and for Cygwin it is getting
22 harder to retain a working fork() call, WSL is a real alternative now.
23
24 >
25 > When I help someone support Windows as a target I typically suggest
26 > using MSYS2. Server or containerized workloads are easily relocated
27 > to WSL2 but many user facing programs can not be moved to WSL2.
28 >
29 > I am not exactly sure this helps.
30 >
31 > I was not aware of the winnt target.
32 > I will see if it is useful for my purposes, as (as usual) I get annoyed
33 > by package managers not having the latest packages and needing
34 > to build them myself in MSYS2.
35 >
36 > Is it possible to briefly describe the challenges of the targets?
37
38 Thanks for this question! Feels like answering is some final task for me.
39
40 There is the Parity[1] wrapper around the MSVC toolchain that does allow
41 to use cl.exe, link.exe and others via GCCish commandline interface. For
42 example$ i686-msvc16-winnt-gcc -c hello.c -o hello.exe
43 uses cl.exe and link.exe behind the scenes to create an MSVC native exe.
44
45 This allows to use existing POSIX build ecosystems to create native Windows
46 binaries: Similar to MinGW, but with MSVC toolchain, allowing to call for
47 M$ support if necessary.
48
49 Also, Parity does provide some header files and a static library, to allow
50 for some POSIX functions to be used without #ifdef _WIN32 in the source
51 code, reducing the amount of code changes when porting to native MSVC.
52 An ultimative goal could be to compile LibreOffice with MSVC using Parity
53 (they do use MinGW right now).
54
55 However, unlike MinGW, Parity requires the POSIXish build system to be able
56 to execute the MSVC toolchain, installed as usual on the Windows host system.
57 This is true for Interix, Cygwin and MSYS, and WSL1/2 replacing Interix.
58 Furthermore, Gentoo Portage (the package manager) is written in Python and
59 Bash, and requires the fork() system call to survive binaries being replaced.
60
61 Hence, we use Portage running (in a Gentoo Prefix instance) on the POSIXish
62 system, to manage a "stacked" instance of Gentoo Prefix, containing the
63 Windows binaries built via Parity.
64
65 Later on, using the POSIXish build system again, the final application is
66 built via Parity as well, linked against the Windows libraries found in the
67 "stacked" Prefix instance.
68
69 Finally, the POSIXish system is not required to run the application binaries.
70
71 As the created Windows binaries can be executed within the build system,
72 we do not require all the additional effort around real "cross" compiling
73 as with MinGW on Linux (unless Wine is installed too).
74 Instead, one could think of additional "multilib" variants here.
75
76 For completion, MSVC provides 4 variants of the runtime libs:
77 dynamically linked ("msvc"), dynamically linked with debug info ("msvcd"),
78 statically linked ("libcmt"), statically linked with debug info ("libcmtd").
79 Mixing them within a single process is asking for troubles, so Parity does
80 select the runtime variant along the host triplet. As multiple MSVC versions
81 can be installed together on the same Windows machine, the MSVC version used
82 is also selected along the host triplet. For example:
83 i686-msvc16-winnt: 32bit, dynamically linked runtime, Visual Studio 2019
84 x86_64-msvcd15-winnt: 64bit, dynamically linked rt with debug info, VS 2017
85 x86_64-libcmt14.0-winnt: 64bit, statically linked runtime, Visual Studio 2015
86 i686-libcmtd10.0-winnt: 32bit, statically linked rt with debug info, VS 2010
87 The parity-setup script does detect the availability of Visual Studio versions
88 along the Windows registry, as well as vswhere.exe since Visual Studio 2017.
89
90 Also noteworthy: Parity source code does contain a cygwin/parity.cygport file,
91 allowing to create Cygwin binary packages. But inclusion into the upstream
92 Cygwin distro would require someone to maintain these binary packages.
93
94 [1] https://github.com/mduft/parity
95
96 HTH,
97 /haubi/