Skip to content
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

Add mingw documentation #17219

Merged
merged 9 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Vcpkg helps you manage C and C++ libraries on Windows, Linux and MacOS. This too
- [Binary Caching](users/binarycaching.md)
- [Versioning](users/versioning.md)
- [Usage with Android](users/android.md)
- [Usage with MinGW](users/mingw.md)
- [Host Dependencies](users/host-dependencies.md)

### Maintainer Help
Expand Down
113 changes: 113 additions & 0 deletions docs/users/mingw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Vcpkg and MinGW

**The latest version of this documentation is available on [GitHub](https://github.com/Microsoft/vcpkg/tree/master/docs/users/mingw.md).**

## MinGW community triplets

Vcpkg includes
[community triplets for MinGW](https://github.com/microsoft/vcpkg/tree/master/triplets/community)
for x64, x86, arm64 and arm. They don't depend on Visual Studio and
can be used natively on Windows as well as for cross-compiling on
other operating systems. There are two variants of each triplet,
selecting between static and dynamic linking:

- arm64-mingw-dynamic
- arm64-mingw-static
- arm-mingw-dynamic
- arm-mingw-static
- x64-mingw-dynamic
- x64-mingw-static
- x86-mingw-dynamic
- x86-mingw-static

These triplets are not tested by continuous integration, so many ports
do not build, and even existing ports may break on port updates.
Because of this, community involvement is paramount!

- [Discussions](https://github.com/microsoft/vcpkg/discussions?discussions_q=mingw)
- [Open issues](https://github.com/microsoft/vcpkg/issues?q=is%3Aissue+is%3Aopen+mingw)
- [Open pull requests](https://github.com/microsoft/vcpkg/pulls?q=is%3Apr+is%3Aopen+mingw)

## Using MinGW natively on Windows

With [MSYS2](https://www.msys2.org/), it is possible to easily create
a full environment for building ports with MinGW on a Windows PC.

Note that for building software for native windows environments, you
must use a mingw subsystem of MSYS2, and install some packages
(with a specific prefix) for this subsystem.

| architecture | vcpkg triplets | subsystem | package prefix |
|--------------|-------------------------------------|-----------|-------------------|
| x64 | x64-mingw-dynamic, x64-mingw-static | mingw64 | mingw-w64-x86_64- |
| x86 | x86-mingw-dynamic, x86-mingw-static | mingw32 | mingw-w64-i686- |

After the basic installation if MSYS2, you will need to install a few
additional packages for software development, e.g. for x64:

```bash
pacman -S git mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja
```

The active subsystem is selected by running the MSYS2 MinGW app, or
changed in a running terminal by

```bash
source shell mingw64 # or mingw32
```

The bootstrapping of vcpkg shall be done by running bootstrap-vcpkg.bat.
This will download the official vcpkg.exe.

```bash
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.bat
```

For building packages, you need to tell vcpkg that you want to use the
MinGW triplet. This can be done in different ways. When Visual Studio
is not installed, you must also set the host triplet to mingw. This is
needed to resolve host dependencies. For convenience, you can use
environment variables to set both triplets:

```bash
export VCPKG_DEFAULT_TRIPLET=x64-mingw-dynamic
export VCPKG_DEFAULT_HOST_TRIPLET=x64-mingw-dynamic
```

Now you can test your setup:

```bash
./vcpkg install zlib
```

## Using MinGW to build Windows programs on other systems

You can use the vcpkg mingw community triplets with toolchains on
non-Windows computers to cross-compile software to be run on Windows.
Many Linux distributions offer such toolchains in optional packages
with a special [suffix](https://repology.org/projects/?search=-mingw-w64)
or [prefix](https://repology.org/projects/?search=mingw-w64-).
As an example, for Debian-based distributions, you would start with
these installation commands for the x64 targets:

```
sudo apt-get install gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64
```

Note that the pre-installed cmake might be too old for vcpkg. Also the
packaged versions of MinGW and GCC might be older releases which lack
some useful features or bug fixes. An alternative independent toolchain
is offered by [MXE](https://mxe.cc/).

For vcpkg bootstrapping, clone the github repository and run the
bootstrap-vcpkg.sh script:

```bash
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg install zlib:x64-mingw-dynamic
```

3 changes: 3 additions & 0 deletions docs/users/triplets.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,6 @@ We recommend using a systematic naming scheme when creating new triplets. The An

## Android triplets
See [android.md](android.md)

## MinGW triplets
See [mingw.md](mingw.md)