Because of the MSYS2 venture, now there’s a simple solution to make the most of Clang to construct C/C++ software on Home windows. This works equally nicely for each 32-bit and 64-bit packages.
MSYS2 is a incredible (and higher) reimagination of Cygwin, it’s like taking the very best a part of a typical fashionable Unix setting (a well-known shell, a basic assortment of utilities, a porting layer, a package deal supervisor, and so forth) whereas nonetheless engaged on Home windows. Bootstrapping into MSYS2 is simple, both set up it immediately (utilizing the GUI installer) or use Chocolatey: choco set up msys2
. As soon as inside its shell, pacman
is the go-to, ever-so-powerful package manager, with hundreds of packages accessible at your disposal.
This in fact, contains the toolchain. Not solely the newest GCC is there, however we even have Clang! For instance the idea, allow us to return to the straightforward ANSI C/C90 program coated within the earlier weblog submit. As soon as we clone the repository, open MSYS2 32-bit shell and take a look at the next:
pacman -S msys/make mingw32/mingw-w64-i686-clang
It’s a easy step to put in each Make and Clang. Wait a bit and after that, do the same old magic:
CC=clang make
A caveat right here, Clang for Home windows doesn’t append the .exe
suffix for the executable. Thus, a fast rename to the rescue:
ren hi there hi there.exe
And now you’ll be able to run, examine, analyze the executable as normal.
To include it into the continual integration utilizing Azure Pipelines (once more, see the earlier weblog submit), we will assemble a brand new job. The fundamental step is as follows.
- job: 'i686_windows_clang'
pool:
vmImage: 'vs2017-win2016'
variables:
PACMAN_PACKAGES: C:toolsmsys64varcachepacmanpkg
CC: clang
First, programmatically set up MSYS2:
- script: choco set up --no-progress msys2
displayName: 'Set up MSYS2'
After that, carry out some pacman maintenances:
- script: |
pacman -Sy
pacman --noconfirm -S pacman-mirrors
workingDirectory: C:toolsmsys64usrbin
displayName: 'Test pacman'
After which, we set up the required packages. On the time of this writing, Clang version 9.0 (the newest) shall be put in.
- script: pacman --noconfirm -S msys/make mingw64/mingw-w64-x86_64-clang
workingDirectory: C:toolsmsys64usrbin
displayName: 'Set up necessities'
For the x86 structure (aka, 32-bit Intel/AMD), set up a unique package deal:
- script: pacman --noconfirm -S msys/make mingw32/mingw-w64-i686-clang
workingDirectory: C:toolsmsys64usrbin
displayName: 'Set up necessities'
And now, right down to the precise construct step:
- script: |
set PATH=C:toolsmsys64usrbin;C:toolsmsys64mingw64bin;%PATH%
make
ren hi there hi there.exe
displayName: 'make'
As a minor tweak, we will additionally cache pacman downloaded packages. Within the above instance, it hardly issues since we solely set up Make and Clang. However you probably have a bigger software, e.g. requiring Python, Qt, and so forth, it’s extensive to keep away from the CI run redownloading the identical packages repeatedly (saving bandwith, and likewise being good to these mirrors). We will obtain this by utilizing the Cache task from Azure Pipelines. Merely insert this after MSYS2 set up step.
- activity: Cache@2
inputs:
key: pacman
restoreKeys: pacman
path: $(PACMAN_PACKAGES)
displayName: 'Cache pacman packages'
For the whole illustration of such a job, check out the precise azure-pipelines.yml for the hello-c90 venture.
Clang in every single place, yay!
#Clang #Home windows