I have a Kubernetes cluster running aarch64 linux workers.
I wanted to compile some apps on this cluster.
Mingw(64) is a fantastic tool but…
The main idea was to use the current Windows SDK and the MSVC runtime like you do with Visual Studio.
I found a fantastic tool https://github.com/Jake-Shadle/xwin made by Jake Shadle. His tool can download the CRT and the SDK directly from Microsoft servers.
And thanks to clang/llvm and its target x86_64-pc-windows-msvc , building Windows x86_64 apps on linux aarch64 is possible…
In /usr/share/msvc/test you'll find a minimal Windows application.
With /usr/share/msvc/test/test.sh you can test a full compilation and executable generation.
test.sh contains:
#!/bin/bash
$MSVC_CL /I include /c src/test.c
$MSVC_CL /I include /c src/MainWindow.c
$MSVC_CL /I include /c src/AboutDialog.c
$MSVC_LINK /subsystem:WINDOWS \
user32.lib kernel32.lib comctl32.lib \
test.obj MainWindow.obj AboutDialog.obj \
/out:test.exeI build this for my own use, it corresponds to my need, if you need to adapt it to your needs feel free to fork and adapt…
docker push highcanfly/llvm4msvc:latest
docker push highcanfly/llvm4msvc-x86:latest
| CC_x86_64_pc_windows_msvc | clang-cl |
| CXX_x86_64_pc_windows_msvc | clang-cl |
| LINK_x86_64_pc_windows_msvc | lld-link |
| LINK_FLAGS | /libpath:$MSVC_BASE/sdk/lib/um/x86_64 /libpath:$MSVC_BASE/sdk/lib/ucrt/x86_64 /libpath:$MSVC_BASE/crt/lib/x86_64 |
| MSVC_CL | ${CC_x86_64_pc_windows_msvc} --target=x86_64-pc-windows-msvc ${CL_FLAGS} |
| MSVC_LINK | ${LINK_x86_64_pc_windows_msvc} --target=x86_64-pc-windows-msvc ${LINK_FLAGS} |
CL and LINK are environment variables read by clang-cl and by recent lld-link themselves (like MSVC's cl.exe/link.exe): their content is prepended to the command line.
Exporting LINK="lld-link ..." made every lld-link invocation (cargo, cmake, ...) fail with lld-link: error: could not open 'lld-link'. The shortcuts are therefore named MSVC_CL and MSVC_LINK.