This post shows how to build Windows programs on Ubuntu 26.04 and run their tests on Windows without a Windows build machine: Rust cross-compiles with llvm-mingw (x86_64-pc-windows-gnullvm), a Windows 11 VM runs in Docker via dockur/windows on KVM, and cargo-nextest runs the tests inside it over SSH.
The build needs no Visual Studio and no Windows SDK: llvm-mingw brings its own Windows headers and libraries, and the .exe imports only DLLs that ship with Windows.
Note: not every language can build Windows programs on Linux. Rust, C/C++ (MinGW) and Go can; flutter build windows runs only on Windows hosts, and PyInstaller bundles only for the OS it runs on. Those need a Windows build machine, but the test VM from steps 6–8 still works for testing them.
Lab context
- Build host
- OS: Ubuntu 26.04.1 (x86-64), 8 vCPU, 20 GB RAM, KVM (
/dev/kvm) - Rust:
1.100.0(rustup), targetx86_64-pc-windows-gnullvm - llvm-mingw:
20261020(UCRT), clang23.1.4 - cargo-nextest:
0.9.152
- OS: Ubuntu 26.04.1 (x86-64), 8 vCPU, 20 GB RAM, KVM (
- Windows test VM
- Image:
dockurr/windows:6.06on Docker29.1.3 - Windows 11 Enterprise evaluation 26H2 (build 26300): 4 cores, 6 GB RAM, 64 GB qcow2 disk
- SSH:
127.0.0.1:2222→ VM port22(this host only)
- Image:
- Tested on: a clean Ubuntu 26.04.1 VM on Hyper-V (nested virtualization), not on bare-metal KVM
What you’ll build
notes.exe: a Rust program with a C dependency (SQLite), built on Linux- A Windows 11 VM with OpenSSH and a
cleancheckpoint run-tests.sh: one command that runs a project’s tests on Windows
Prerequisites
- x86-64 Ubuntu 26.04 with KVM:
ls -l /dev/kvmExpected:
crw-rw---- 1 root kvm 10, 232 Nov 20 08:59 /dev/kvm- About 6 GB of free RAM for the VM and 25 GB of free disk (the 64 GB VM disk grows as Windows fills it; this run used 19 GB in total).
- Step 7 downloads Windows 11 Enterprise evaluation from Microsoft, and running it accepts the evaluation terms: test use only, no commercial, non-profit or revenue-generating work, no live environment, and 90 days at most. For anything else, use a licensed Windows.
1. Install Rust + the Windows target
Install rustup (Rust’s toolchain installer) from Ubuntu’s packages, plus a host C compiler for build scripts:
sudo apt update
sudo apt install -y rustup build-essentialThe package doesn’t include a toolchain. Install stable, which brings rustc and cargo, then add the Windows target:
rustup default stable
rustup target add x86_64-pc-windows-gnullvmExpected:
info: installing component 'cargo'
info: installing component 'rustc'
stable-x86_64-unknown-linux-gnu installed - rustc 1.100.0 (0ef1bc386 2026-11-09)2. Install llvm-mingw (example: 20261020)
Download the Linux UCRT build (the C runtime Rust’s gnullvm targets use) and check its SHA-256 (listed on the release page):
cd /tmp
curl -fLO https://github.com/mstorsjo/llvm-mingw/releases/download/20261020/llvm-mingw-20261020-ucrt-ubuntu-22.04-x86_64.tar.xz
echo '55064b60b991a1e1e8090b8c2f84e82b22cfe5903d12c159d65064cf5e8ae335 llvm-mingw-20261020-ucrt-ubuntu-22.04-x86_64.tar.xz' | sha256sum -cExpected:
llvm-mingw-20261020-ucrt-ubuntu-22.04-x86_64.tar.xz: OKUnpack it to /opt:
sudo tar -xJf llvm-mingw-20261020-ucrt-ubuntu-22.04-x86_64.tar.xz -C /opt
sudo ln -s /opt/llvm-mingw-20261020-ucrt-ubuntu-22.04-x86_64 /opt/llvm-mingw
/opt/llvm-mingw/bin/x86_64-w64-mingw32-clang --versionExpected:
clang version 23.1.4 (https://github.com/llvm/llvm-project.git …)
Target: x86_64-w64-windows-gnu3. Point Cargo at llvm-mingw
Ubuntu’s rustup package doesn’t create ~/.cargo. Create it:
mkdir -p ~/.cargoCreate ~/.cargo/config.toml. We use full paths, so llvm-mingw stays off PATH:
[target.x86_64-pc-windows-gnullvm]
linker = "/opt/llvm-mingw/bin/x86_64-w64-mingw32-clang"
[env]
CC_x86_64_pc_windows_gnullvm = "/opt/llvm-mingw/bin/x86_64-w64-mingw32-clang"
AR_x86_64_pc_windows_gnullvm = "/opt/llvm-mingw/bin/x86_64-w64-mingw32-ar"linker→ llvm-mingw’s clang links the.exe.CC_…/AR_…→ the C compiler and archiver for crates that build C (via thecccrate), for this target only.
4. Create a sample project
The sample stores notes in SQLite. rusqlite with bundled compiles SQLite’s C source, so the cross-build has to compile C as well. One test is Windows-only (#[cfg(windows)]).
Create the project:
cd ~
cargo new notes
cd notes
cargo add rusqlite --features bundled
cargo add --dev tempfileExpected:
Creating binary (application) `notes` package
Adding rusqlite v0.43.0 to dependencies
Adding tempfile v3.27.0 to dev-dependenciesCreate src/lib.rs:
use rusqlite::Connection;
use std::path::Path;
pub fn open(dir: &Path) -> rusqlite::Result<Connection> {
let db = Connection::open(dir.join("notes.db"))?;
db.execute("CREATE TABLE IF NOT EXISTS notes (body TEXT NOT NULL)", ())?;
Ok(db)
}
pub fn add(db: &Connection, body: &str) -> rusqlite::Result<usize> {
db.execute("INSERT INTO notes (body) VALUES (?1)", [body])
}
pub fn count(db: &Connection) -> rusqlite::Result<i64> {
db.query_row("SELECT count(*) FROM notes", (), |row| row.get(0))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn adds_a_note() {
let dir = tempfile::tempdir().unwrap();
let db = open(dir.path()).unwrap();
add(&db, "hello").unwrap();
assert_eq!(count(&db).unwrap(), 1);
}
// Windows won't delete a file another handle has open; Linux will.
#[cfg(windows)]
#[test]
fn open_database_cannot_be_deleted() {
let dir = tempfile::tempdir().unwrap();
let _db = open(dir.path()).unwrap();
let err = std::fs::remove_file(dir.path().join("notes.db")).unwrap_err();
assert_eq!(err.raw_os_error(), Some(32)); // ERROR_SHARING_VIOLATION
}
}Replace src/main.rs:
fn main() {
let db = notes::open(&std::env::current_dir().unwrap()).unwrap();
notes::add(&db, "built on Linux").unwrap();
let count = notes::count(&db).unwrap();
println!("notes.db: {count} note(s), SQLite {}", rusqlite::version());
}On Linux, the Windows-only test is compiled out:
cargo testExpected:
running 1 test
test tests::adds_a_note ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s5. Build notes.exe for Windows
Build:
cargo build --release --target x86_64-pc-windows-gnullvmCheck what it imports:
/opt/llvm-mingw/bin/llvm-objdump -p target/x86_64-pc-windows-gnullvm/release/notes.exe | grep 'DLL Name'Expected:
DLL Name: KERNEL32.dll
DLL Name: api-ms-win-crt-stdio-l1-1-0.dll
DLL Name: api-ms-win-crt-runtime-l1-1-0.dll
DLL Name: api-ms-win-crt-locale-l1-1-0.dll
DLL Name: api-ms-win-crt-heap-l1-1-0.dll
DLL Name: api-ms-win-crt-private-l1-1-0.dll
DLL Name: api-ms-win-crt-string-l1-1-0.dll
DLL Name: api-ms-win-crt-time-l1-1-0.dll
DLL Name: api-ms-win-crt-utility-l1-1-0.dll
DLL Name: api-ms-win-crt-math-l1-1-0.dll
DLL Name: api-ms-win-core-synch-l1-2-0.dll
DLL Name: ntdll.dll
DLL Name: api-ms-win-crt-environment-l1-1-0.dll
DLL Name: api-ms-win-crt-filesystem-l1-1-0.dll
DLL Name: api-ms-win-crt-convert-l1-1-0.dllAll of them ship with Windows (api-ms-win-crt-* is its Universal C Runtime): there’s no libunwind.dll, libc++.dll or Visual C++ runtime to copy along.
Check and lint the Windows-only code on Linux (clippy comes with the stable toolchain):
cargo clippy --all-targets --target x86_64-pc-windows-gnullvm -- -D warningsExpected:
Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.60s6. Install Docker
Install Docker and join the docker and kvm groups:
sudo apt install -y docker.io
sudo usermod -aG docker,kvm $USERLog out and back in, so the new groups apply.
7. Create the Windows 11 VM (dockur/windows)
Make an SSH key for the VM, and a random password for its user tester:
mkdir -p ~/wintest/oem
ssh-keygen -t ed25519 -N '' -f ~/.ssh/wintest
cp ~/.ssh/wintest.pub ~/wintest/oem/authorized_keys
(umask 077; printf 'PASSWORD=%s\n' "$(openssl rand -base64 18)" > ~/wintest/secret.env)dockur copies the folder mounted at /oem to C:\OEM and runs its install.bat at the end of the unattended install.
Create ~/wintest/oem/install.bat:
@echo off
powershell -NoProfile -ExecutionPolicy Bypass -File C:\OEM\setup.ps1 > C:\OEM\setup.log 2>&1Create ~/wintest/oem/setup.ps1:
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
New-Item -ItemType Directory -Force -Path C:\ProgramData\ssh
Copy-Item C:\OEM\authorized_keys C:\ProgramData\ssh\administrators_authorized_keys
icacls.exe C:\ProgramData\ssh\administrators_authorized_keys /inheritance:r /grant Administrators:F /grant SYSTEM:F
New-ItemProperty -Path HKLM:\SOFTWARE\OpenSSH -Name DefaultShell -PropertyType String -Force -Value C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private
reg.exe add HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU /v NoAutoUpdate /t REG_DWORD /d 1 /f
Set-Service -Name sshd -StartupType Automatic
Start-Service sshdadministrators_authorized_keys→ where sshd reads keys for administrators (testeris one)- Private network profile → the one the OpenSSH firewall rule allows
Start the VM:
docker run -d --name wintest \
--device /dev/kvm --device /dev/net/tun --cap-add NET_ADMIN \
-e VERSION=11e -e USERNAME=tester --env-file ~/wintest/secret.env \
-e RAM_SIZE=6G -e CPU_CORES=4 -e DISK_SIZE=64G -e DISK_FMT=qcow2 \
-v wintest:/storage -v ~/wintest/oem:/oem:ro \
-p 127.0.0.1:2222:22 --stop-timeout 120 \
dockurr/windows:6.06VERSION=11e→ Windows 11 Enterprise evaluationDISK_FMT=qcow2→ a disk format with snapshots (the checkpoint in step 8)- Only SSH is published, on
127.0.0.1 --stop-timeout 120→docker stopgives Windows 120 s to shut down
Add to ~/.ssh/config:
Host wintest
HostName 127.0.0.1
Port 2222
User tester
IdentityFile ~/.ssh/wintest
StrictHostKeyChecking accept-new
WarnWeakCrypto noWarnWeakCrypto no → hides OpenSSH 10’s post-quantum warning, which the VM’s OpenSSH triggers on every connection.
Wait for SSH. The download and install take 30–40 minutes in this lab (docker logs -f wintest shows the progress):
until ssh -o ConnectTimeout=5 wintest exit 2> /dev/null; do sleep 30; done
ssh wintest '(Get-CimInstance Win32_OperatingSystem).Caption'Expected:
Microsoft Windows 11 Enterprise EvaluationRun the program from step 5 there:
scp ~/notes/target/x86_64-pc-windows-gnullvm/release/notes.exe wintest:
ssh wintest '.\notes.exe; Remove-Item notes.exe, notes.db'Expected:
notes.db: 1 note(s), SQLite 3.54.18. Take a clean checkpoint
Shut Windows down and snapshot its disk with the image’s own qemu-img:
docker stop wintest
docker run --rm --entrypoint qemu-img -v wintest:/storage dockurr/windows:6.06 snapshot -c clean /storage/data.qcow2
docker run --rm --entrypoint qemu-img -v wintest:/storage dockurr/windows:6.06 snapshot -l /storage/data.qcow2Expected:
Snapshot list:
ID TAG VM_SIZE DATE VM_CLOCK ICOUNT
1 clean 0 B 2026-11-20 01:41:23 0000:00:00.000 09. Run the tests on Windows (cargo-nextest)
Install cargo-nextest, and build it for Windows too (the published Windows build needs the Visual C++ runtime, VCRUNTIME140.dll, which a fresh Windows doesn’t have):
cargo install --locked cargo-nextest
cargo install --locked cargo-nextest --target x86_64-pc-windows-gnullvm --root ~/wintest/nextestCreate ~/wintest/run-tests.sh:
#!/bin/bash
# Runs this Cargo project's tests in the Windows VM, from its clean checkpoint.
set -euo pipefail
name=$(basename "$PWD")
work=$(mktemp -d)
trap 'docker stop wintest > /dev/null; rm -rf "$work"' EXIT
cargo nextest archive --target x86_64-pc-windows-gnullvm --archive-file "$work/tests.tar.zst"
tar -C .. -cf "$work/src.tar" --exclude="$name/target" "$name"
docker stop wintest > /dev/null
docker run --rm --entrypoint qemu-img -v wintest:/storage dockurr/windows:6.06 \
snapshot -a clean /storage/data.qcow2
docker start wintest > /dev/null
until ssh -n -o ConnectTimeout=5 wintest exit 2> /dev/null; do sleep 5; done
scp -q "$work/tests.tar.zst" "$work/src.tar" ~/wintest/nextest/bin/cargo-nextest.exe wintest:
ssh -n wintest "tar -xf src.tar; .\cargo-nextest.exe nextest run --archive-file tests.tar.zst --workspace-remap $name; exit \$LASTEXITCODE"- The source tree goes along because nextest runs each test in its package folder (
--workspace-remappoints to it) - The VM stops when the script exits
Make it executable:
chmod +x ~/wintest/run-tests.shRun it from the project:
cd ~/notes
~/wintest/run-tests.shExpected:
Extracting 2 binaries and 1 linked path to \\?\C:\Users\tester\AppData\Local\Temp\nextest-archive-qqUpvx
Starting 2 tests across 2 binaries
PASS [ 0.030s] (1/2) notes tests::open_database_cannot_be_deleted
PASS [ 0.032s] (2/2) notes tests::adds_a_note
Summary [ 0.032s] 2 tests run: 2 passed, 0 skippedA failing test makes run-tests.sh exit non-zero (nextest’s 100).
Summary
You now have Windows programs built on Ubuntu with llvm-mingw, a Windows 11 test VM that starts from a clean checkpoint, and one command that runs a project’s tests on Windows.
