Skip to content

Commit 2ddcadb

Browse files
tanzislamPezi777
authored andcommitted
Add guidance for using MSYS2 in Windows (travis-ci#2587)
There is [demand](https://travis-ci.community/t/3658) for MSYS2 in the Windows environment, but the installation and use of it is rather tricky. Document it for the time being, until the day it is incorporated into the image.
1 parent 5899d1f commit 2ddcadb

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

user/reference/windows.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,52 @@ VMs running Windows use the default file system, NTFS.
8686
- winscp 5.13.4
8787
- winscp.install 5.13.4
8888
- wsl 1.0.1
89+
90+
## How do I use MSYS2?
91+
92+
[MSYS2](https://www.msys2.org/) is a popular development environment for building GCC-based projects with Unix-style build systems. While it isn't included in the Windows image, it is fairly easy to install via [the Chocolatey package](https://chocolatey.org/packages/msys2) using the following additions to the sections of your `.travis.yml`:
93+
94+
```yaml
95+
before_install:
96+
- |-
97+
case $TRAVIS_OS_NAME in
98+
windows)
99+
[[ ! -f C:/tools/msys64/msys2_shell.cmd ]] && rm -rf C:/tools/msys64
100+
choco uninstall -y mingw
101+
choco upgrade --no-progress -y msys2
102+
export msys2='cmd //C RefreshEnv.cmd '
103+
export msys2+='& set MSYS=winsymlinks:nativestrict '
104+
export msys2+='& C:\\tools\\msys64\\msys2_shell.cmd -defterm -no-start'
105+
export mingw64="$msys2 -mingw64 -full-path -here -c \$\* --"
106+
export msys2+=" -msys2 -c \$\* --"
107+
$msys2 pacman --sync --noconfirm --needed mingw-w64-x86_64-toolchain
108+
## Install more MSYS2 packages from https://packages.msys2.org/base here
109+
taskkill //IM gpg-agent.exe //F # https://travis-ci.community/t/4967
110+
export PATH=/C/tools/msys64/mingw64/bin:$PATH
111+
export MAKE=mingw32-make # so that Autotools can find it
112+
;;
113+
esac
114+
115+
before_cache:
116+
- |-
117+
case $TRAVIS_OS_NAME in
118+
windows)
119+
# https://unix.stackexchange.com/a/137322/107554
120+
$msys2 pacman --sync --clean --noconfirm
121+
;;
122+
esac
123+
124+
cache:
125+
directories:
126+
- $HOME/AppData/Local/Temp/chocolatey
127+
- /C/tools/msys64
128+
```
129+
{: data-file=".travis.yml"}
130+
131+
This will download and install MSYS2 the first time, and store both the downloaded initial archive and the MSYS2 installation in your [build cache](/user/caching/#arbitrary-directories). Subsequent builds will avoid re-downloading the initial archive and will update the cached installation before use, and cache the updated installation upon success.
132+
133+
MSYS2 contains two noteworthy [subsystems](https://github.com/msys2/msys2/wiki/MSYS2-introduction#subsystems): "msys2" and "mingw64". The code above prepares the `$msys2` and `$mingw64` prefixes for entering the corresponding shells. As an example, the `$msys2` prefix is used to run `pacman` appropriately. Your build commands should use the `$mingw64` prefix to build native Windows programs, and the `$msys2` prefix to build POSIX-based programs requiring the MSYS2 DLL.
134+
135+
A point of caution: the pre-installed "mingw" Chocolatey package should **not** be used within any MSYS2 subsystem. (In fact, the above snippet uninstalls the "mingw" Chocolatey package to be safe.) Note that the [MSYS2 wiki](https://github.com/msys2/msys2/wiki/MSYS2-introduction#path) says:
136+
137+
>Beware that mixing in programs from other MSYS2 installations, Cygwin installations, compiler toolchains or even various other programs is not supported and will probably break things in unexpected ways.

0 commit comments

Comments
 (0)