forge
Explore
Log in

Don't you dare go Hollow

Build sets up the Windows VM itself: creates yumush-win (dockurr/windows, ports on 127.0.0.1 only, ssh key + OEM install.bat generated), waits for the OEM install, and pins the VM's rustc to the host's version each build like the Linux container. Drops the Missing/Broken VM states

Browse files at this commit

e84dda0ca59408a845de34363019cabc0e0a38e3Ahmet Kaan GümüşParent: e81ccb7
  • feat
    • Build sets up the Windows VM itself: creates yumush-win (dockurr/windows, ports on 127.0.0.1 only, ssh key + OEM install.bat generated), waits for the OEM install, and pins the VM's rustc to the host's version each build like the Linux container. Drops the Missing/Broken VM states
Show full message
✨ feat: Build sets up the Windows VM itself: creates yumush-win (dockurr/windows, ports on 127.0.0.1 only, ssh key + OEM install.bat generated), waits for the OEM install, and pins the VM's rustc to the host's version each build like the Linux container. Drops the Missing/Broken VM states
crates/client/src/release.rsmodified+125 -41
@@ -70,6 +70,10 @@ const LINUX_CACHE: &str = ".cache/yumush-build";
70 const LINUX_PACKAGES: &str = "ca-certificates curl git build-essential pkg-config clang cmake nasm libpipewire-0.3-dev libspa-0.2-dev libva-dev libdrm-dev libgbm-dev libxkbcommon-x11-dev libxkbcommon-dev libxcb1-dev libwayland-dev libvulkan-dev libfontconfig-dev libfreetype-dev libasound2-dev";70 const LINUX_PACKAGES: &str = "ca-certificates curl git build-essential pkg-config clang cmake nasm libpipewire-0.3-dev libspa-0.2-dev libva-dev libdrm-dev libgbm-dev libxkbcommon-x11-dev libxkbcommon-dev libxcb1-dev libwayland-dev libvulkan-dev libfontconfig-dev libfreetype-dev libasound2-dev";
71 const ARCHIVE: &str = "dist/source.tgz";71 const ARCHIVE: &str = "dist/source.tgz";
72 const VM: &str = "yumush-win";72 const VM: &str = "yumush-win";
73+const VM_DIR: &str = "vm/yumush-win";
74+const VM_IMAGE: &str = "docker.io/dockurr/windows";
75+const VM_AUDIO: &str = "ARGUMENTS=-audiodev none,id=snd0 -device ich9-intel-hda,id=hda1 -device hda-duplex,bus=hda1.0,audiodev=snd0 -device ich9-intel-hda,id=hda2 -device hda-duplex,bus=hda2.0,audiodev=snd0";
76+const INSTALL: &str = include_str!("release/install.bat");
73 const TARGET: &str = "yumush@127.0.0.1";77 const TARGET: &str = "yumush@127.0.0.1";
74 const PORT: &str = "2222";78 const PORT: &str = "2222";
75 const EXTRACT: &str = "Remove-Item -Recurse -Force release -ErrorAction SilentlyContinue; New-Item -ItemType Directory release | Out-Null; tar -xmzf release.tgz -C release";79 const EXTRACT: &str = "Remove-Item -Recurse -Force release -ErrorAction SilentlyContinue; New-Item -ItemType Directory release | Out-Null; tar -xmzf release.tgz -C release";
@@ -156,20 +160,11 @@ impl Cx {
156 }160 }
157 }161 }
158 162
159-enum Vm {
160- Missing,
161- Running,
162- Started,
163- Broken(String),
164-}
165-
166 fn run(source: &Path, lanes: &[Cx]) {163 fn run(source: &Path, lanes: &[Cx]) {
167- let key = dirs::home_dir()164+ let key = vm_dir().join("id_ed25519");
168- .unwrap_or_default()
169- .join("vm/yumush-win/id_ed25519");
170 let first = &lanes[0];165 let first = &lanes[0];
171- let vm = match preflight(source) {166+ let vm_was_running = match preflight(source) {
172- Ok(vm) => vm,167+ Ok(running) => running,
173 Err(e) => {168 Err(e) => {
174 first.send(Event::Failed(LANES[0].1[0], e));169 first.send(Event::Failed(LANES[0].1[0], e));
175 first.send(Event::Done);170 first.send(Event::Done);
@@ -178,23 +173,23 @@ fn run(source: &Path, lanes: &[Cx]) {
178 };173 };
179 thread::scope(|scope| {174 thread::scope(|scope| {
180 for ((_, jobs), cx) in LANES.iter().zip(lanes) {175 for ((_, jobs), cx) in LANES.iter().zip(lanes) {
181- let (key, vm) = (&key, &vm);176+ let key = &key;
182- scope.spawn(move || run_lane(jobs, source, key, cx, vm));177+ scope.spawn(move || run_lane(jobs, source, key, cx));
183 }178 }
184 });179 });
185- if let Vm::Started = vm {180+ if !vm_was_running {
186 podman_ok(&["stop", VM]);181 podman_ok(&["stop", VM]);
187 }182 }
188 podman_ok(&["stop", "-t", "2", LINUX]);183 podman_ok(&["stop", "-t", "2", LINUX]);
189 first.send(Event::Done);184 first.send(Event::Done);
190 }185 }
191 186
192-fn run_lane(jobs: &[Job], source: &Path, key: &Path, cx: &Cx, vm: &Vm) {187+fn run_lane(jobs: &[Job], source: &Path, key: &Path, cx: &Cx) {
193 for &job in jobs {188 for &job in jobs {
194 let result = if cx.cancelled() {189 let result = if cx.cancelled() {
195 Err("cancelled".to_string())190 Err("cancelled".to_string())
196 } else {191 } else {
197- run_job(job, source, key, cx, vm)192+ run_job(job, source, key, cx)
198 };193 };
199 if let Err(e) = result {194 if let Err(e) = result {
200 let e = if cx.cancelled() {195 let e = if cx.cancelled() {
@@ -208,7 +203,7 @@ fn run_lane(jobs: &[Job], source: &Path, key: &Path, cx: &Cx, vm: &Vm) {
208 }203 }
209 }204 }
210 205
211-fn preflight(source: &Path) -> Result<Vm, String> {206+fn preflight(source: &Path) -> Result<bool, String> {
212 let dirty = Command::new("git")207 let dirty = Command::new("git")
213 .arg("-C")208 .arg("-C")
214 .arg(source)209 .arg(source)
@@ -219,23 +214,17 @@ fn preflight(source: &Path) -> Result<Vm, String> {
219 return Err("uncommitted changes".into());214 return Err("uncommitted changes".into());
220 }215 }
221 snapshot(source)?;216 snapshot(source)?;
222- if !podman_ok(&["container", "exists", VM]) {217+ Ok(container_running(VM))
223- return Ok(Vm::Missing);218+}
224- }219+
225- let state = Command::new("podman")220+fn container_running(container: &str) -> bool {
226- .args(["inspect", "-f", "{{.State.Running}}", VM])221+ Command::new("podman")
222+ .args(["inspect", "-f", "{{.State.Running}}", container])
227 .output()223 .output()
228- .map_err(|e| e.to_string())?;224+ .is_ok_and(|out| String::from_utf8_lossy(&out.stdout).trim() == "true")
229- if String::from_utf8_lossy(&state.stdout).trim() != "false" {
230- return Ok(Vm::Running);
231- }
232- Ok(match check(Command::new("podman").args(["start", VM])) {
233- Ok(()) => Vm::Started,
234- Err(error) => Vm::Broken(error),
235- })
236 }225 }
237 226
238-fn run_job(job: Job, source: &Path, key: &Path, cx: &Cx, vm: &Vm) -> Result<(), String> {227+fn run_job(job: Job, source: &Path, key: &Path, cx: &Cx) -> Result<(), String> {
239 match job {228 match job {
240 Job::LinuxStart => {229 Job::LinuxStart => {
241 if !cfg!(target_os = "linux") {230 if !cfg!(target_os = "linux") {
@@ -259,19 +248,13 @@ fn run_job(job: Job, source: &Path, key: &Path, cx: &Cx, vm: &Vm) -> Result<(),
259 build_server(job, source, cx)248 build_server(job, source, cx)
260 }249 }
261 Job::WindowsStart => {250 Job::WindowsStart => {
262- if let Vm::Missing = vm {251+ if !cfg!(target_os = "linux") {
263- return skip(cx, job, "no yumush-win");252+ return skip(cx, job, "not linux");
264 }253 }
265 cx.send(Event::Started(job));254 cx.send(Event::Started(job));
266- if let Vm::Broken(error) = vm {
267- return Err(error.clone());
268- }
269 start_windows(job, source, key, cx)255 start_windows(job, source, key, cx)
270 }256 }
271 Job::Windows(level) => {257 Job::Windows(level) => {
272- if let Vm::Missing = vm {
273- return skip(cx, job, "no yumush-win");
274- }
275 cx.send(Event::Started(job));258 cx.send(Event::Started(job));
276 build_windows(job, level, source, key, cx)259 build_windows(job, level, source, key, cx)
277 }260 }
@@ -421,8 +404,105 @@ fn build_server(job: Job, source: &Path, cx: &Cx) -> Result<(), String> {
421 )404 )
422 }405 }
423 406
407+fn vm_dir() -> PathBuf {
408+ dirs::home_dir().unwrap_or_default().join(VM_DIR)
409+}
410+
411+fn create_windows(job: Job, key: &Path, cx: &Cx) -> Result<(), String> {
412+ if !Path::new("/dev/kvm").exists() {
413+ return Err("no /dev/kvm".into());
414+ }
415+ let dir = vm_dir();
416+ for sub in ["storage", "oem", "shared"] {
417+ fs::create_dir_all(dir.join(sub)).map_err(|e| e.to_string())?;
418+ }
419+ if !key.exists() {
420+ check(
421+ Command::new("ssh-keygen")
422+ .args(["-q", "-t", "ed25519", "-N", "", "-C", "yumush-vm", "-f"])
423+ .arg(key),
424+ )?;
425+ }
426+ let public = fs::read_to_string(key.with_extension("pub")).map_err(|e| e.to_string())?;
427+ fs::write(
428+ dir.join("oem/install.bat"),
429+ INSTALL.replace("{key}", public.trim()),
430+ )
431+ .map_err(|e| e.to_string())?;
432+ let cores = thread::available_parallelism().map_or(4, |n| n.get());
433+ let mount = |sub: &str| format!("{}:/{sub}:Z", dir.join(sub).display());
434+ cx.send(Event::Line(job, "creating Windows VM".into()));
435+ check(
436+ Command::new("podman")
437+ .args(["run", "-d", "--name", VM])
438+ .args([
439+ "-e",
440+ "VERSION=11",
441+ "-e",
442+ "RAM_SIZE=12G",
443+ "-e",
444+ "DISK_SIZE=96G",
445+ ])
446+ .args(["-e", &format!("CPU_CORES={cores}")])
447+ .args([
448+ "-e",
449+ "USERNAME=yumush",
450+ "-e",
451+ "PASSWORD=yumush",
452+ "-e",
453+ "USER_PORTS=22",
454+ ])
455+ .args(["-e", VM_AUDIO])
456+ .args([
457+ "--device",
458+ "/dev/kvm",
459+ "--device",
460+ "/dev/net/tun",
461+ "--cap-add",
462+ "NET_ADMIN",
463+ ])
464+ .args(["-p", "127.0.0.1:8006:8006", "-p", "127.0.0.1:3389:3389"])
465+ .args(["-p", &format!("127.0.0.1:{PORT}:22")])
466+ .args([
467+ "-v",
468+ &mount("storage"),
469+ "-v",
470+ &mount("oem"),
471+ "-v",
472+ &mount("shared"),
473+ ])
474+ .args(["--stop-timeout", "120", VM_IMAGE]),
475+ )
476+}
477+
424 fn start_windows(job: Job, source: &Path, key: &Path, cx: &Cx) -> Result<(), String> {478 fn start_windows(job: Job, source: &Path, key: &Path, cx: &Cx) -> Result<(), String> {
479+ if !podman_ok(&["container", "exists", VM]) {
480+ create_windows(job, key, cx)?;
481+ } else if !container_running(VM) {
482+ check(Command::new("podman").args(["start", VM]))?;
483+ }
425 wait_ssh(job, key, cx)?;484 wait_ssh(job, key, cx)?;
485+ while !ssh_ok_with(
486+ key,
487+ "if (Test-Path C:\\OEM\\finished.txt) { exit 0 } else { exit 1 }",
488+ ) {
489+ if cx.cancelled() {
490+ return Err("cancelled".into());
491+ }
492+ cx.send(Event::Line(job, "installing build tools".into()));
493+ thread::sleep(Duration::from_secs(15));
494+ }
495+ let rust = host_rust()?;
496+ stream(
497+ &mut ps(
498+ key,
499+ &format!(
500+ "$env:Path += \";$env:USERPROFILE\\.cargo\\bin\"\nrustup toolchain install {rust} --profile minimal\nrustup default {rust}"
501+ ),
502+ ),
503+ job,
504+ cx,
505+ )?;
426 check(506 check(
427 scp(key)507 scp(key)
428 .arg(source.join(ARCHIVE))508 .arg(source.join(ARCHIVE))
@@ -519,8 +599,12 @@ fn ps(key: &Path, script: &str) -> Command {
519 }599 }
520 600
521 fn ssh_ok(key: &Path) -> bool {601 fn ssh_ok(key: &Path) -> bool {
602+ ssh_ok_with(key, "echo ok")
603+}
604+
605+fn ssh_ok_with(key: &Path, command: &str) -> bool {
522 ssh(key)606 ssh(key)
523- .args(["echo", "ok"])607+ .arg(command)
524 .stdout(Stdio::null())608 .stdout(Stdio::null())
525 .stderr(Stdio::null())609 .stderr(Stdio::null())
526 .status()610 .status()
crates/client/src/release/install.batadded+7 -0
@@ -0,0 +1,7 @@
1+@echo off
2+powershell -NoProfile -ExecutionPolicy Bypass -Command "Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0; Set-Service sshd -StartupType Automatic; Start-Service sshd; New-NetFirewallRule -Name sshd -DisplayName sshd -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -ErrorAction SilentlyContinue; Set-Content -Path C:\ProgramData\ssh\administrators_authorized_keys -Value '{key}'; icacls C:\ProgramData\ssh\administrators_authorized_keys /inheritance:r /grant 'Administrators:F' /grant 'SYSTEM:F'; New-ItemProperty -Path 'HKLM:\SOFTWARE\OpenSSH' -Name DefaultShell -Value 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -PropertyType String -Force"
3+curl.exe -L -o C:\vs_BuildTools.exe https://aka.ms/vs/17/release/vs_BuildTools.exe
4+C:\vs_BuildTools.exe --quiet --wait --norestart --nocache --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended
5+curl.exe -L -o C:\rustup-init.exe https://win.rustup.rs/x86_64
6+C:\rustup-init.exe -y --default-toolchain none --profile minimal
7+echo done > C:\OEM\finished.txt