elmarco/msvc-cross

MSVC cross-compilation from Linux

★ 0Forks 0PythonGitHub ↗Compare

README

msvc-cross — MSVC cross-compilation from Linux

Download Microsoft Visual C++ headers and libraries, process them for case-sensitive filesystems, and package them for cross-compiling Windows applications from Linux using Clang.

What it fetches

Source Contents Format
VS installer manifest MSVC CRT headers (vcruntime.h, C++ STL), static libs (libcmt.lib), DLL import libs (msvcrt.lib) VSIX (zip)
NuGet Windows SDK headers (stdio.h, windows.h), UCRT libs, Win32 import libs (kernel32.lib) .nupkg (zip)

Supported architectures: x86_64 and ARM64.

All filenames are lowercased and #include directives are patched so headers work on ext4/btrfs/xfs.

Quick start (RPM)

Generate, build, and install the RPMs (downloads ~350 MB, cached for reruns):

./gen rpm --cache-dir .cache --install

Cross-compile with the installed helper scripts:

msvc-meson builddir
ninja -C builddir

msvc-cmake -B builddir
cmake --build builddir

msvc-config && msvc-make

Quick start (Meson subproject)

For projects that vendor the SDK instead of installing it system-wide:

./gen meson --cache-dir .cache --output-dir msvc-cross

Link it into your project:

ln -s /path/to/msvc-cross subprojects/msvc-cross
meson setup builddir --cross-file hello-msvc/x86_64-windows-msvc.txt
ninja -C builddir

In your meson.build:

msvc_cross_dep = dependency('msvc-cross')
executable('app', 'main.c', dependencies: msvc_cross_dep)

What the RPM provides

Each arch subpackage (msvc-cross-x64, msvc-cross-arm64) installs:

File x64 path
Import libraries /usr/x86_64-windows-msvc/lib/msvc/
pkg-config file /usr/x86_64-windows-msvc/lib/pkgconfig/msvc-cross.pc
Meson cross file /usr/share/msvc-cross/x86_64-windows-msvc.txt
CMake toolchain /usr/share/msvc-cross/toolchain-x86_64-windows-msvc.cmake
pkgconf personality /usr/share/pkgconfig/personality.d/x86_64-windows-msvc.personality
pkg-config wrapper /usr/bin/x86_64-windows-msvc-pkg-config
Helper: meson /usr/bin/msvc-meson
Helper: cmake /usr/bin/msvc-cmake
Helper: configure /usr/bin/msvc-config
Helper: make /usr/bin/msvc-make

ARM64 equivalents use the aarch64-windows-msvc triple and an msvc-arm64- prefix for helper scripts.

Headers are shared across architectures in msvc-cross-headers (/usr/share/msvc/include/).

The RPM pulls in clang, lld, and pkgconf-pkg-config as dependencies.

CRT linking

Both static and DLL CRT linking are supported — Meson's b_vscrt option works as expected (defaults to DLL CRT in debug, static in release).

For static CRT with no DLL dependencies beyond KERNEL32.dll:

msvc-meson builddir -Db_vscrt=mt

Requirements

  • Python 3 (for ./gen)

For the Meson subproject workflow you also need:

  • Clang + LLD (dnf install clang lld)
  • Meson + Ninja (dnf install meson ninja-build)

The RPM packages pull in clang and lld automatically.

Options

Common options (both ./gen rpm and ./gen meson):

--msvc-version VERSION    MSVC toolchain version slug (default: latest)
--sdk-version VERSION     Windows SDK NuGet version (default: latest)
--channel {2022,2022-pre} VS release channel (default: 2022)
--output-dir DIR          Output directory
--cache-dir DIR           Cache for downloads (default: temp)
--list-versions           List available MSVC versions and exit
--inspect                 Show package contents without generating output

RPM-only options:

--install                 Build and install RPMs after generation
--no-install              Skip RPM build/install (just generate spec + tarball)

License

The generator scripts are unlicensed. The downloaded MSVC and Windows SDK files are proprietary — see the generated LICENSE.txt. Do not upload the output to public repositories.

Contributors

elmarco

Issues