diff --git a/crates/zed/build.rs b/crates/zed/build.rs index dd26a1152e965414abc102c37ff570a7ba7184d4..18139a679d6eb4990b039e1276062e3071cdd40f 100644 --- a/crates/zed/build.rs +++ b/crates/zed/build.rs @@ -53,22 +53,117 @@ fn main() { println!("cargo:rustc-link-arg=/stack:{}", 8 * 1024 * 1024); } - if cfg!(target_arch = "x86_64") { - println!("cargo::rerun-if-changed=resources\\windows\\bin\\x64\\conpty.dll"); - println!("cargo::rerun-if-changed=resources\\windows\\bin\\x64\\OpenConsole.exe"); - let conpty_target = std::env::var("OUT_DIR").unwrap() + "\\..\\..\\..\\conpty.dll"; - match std::fs::copy("resources/windows/bin/x64/conpty.dll", &conpty_target) { - Ok(_) => println!("Copied conpty.dll to {conpty_target}"), - Err(e) => println!("cargo::warning=Failed to copy conpty.dll: {}", e), - } - let open_console_target = - std::env::var("OUT_DIR").unwrap() + "\\..\\..\\..\\OpenConsole.exe"; - match std::fs::copy( - "resources/windows/bin/x64/OpenConsole.exe", - &open_console_target, - ) { - Ok(_) => println!("Copied OpenConsole.exe to {open_console_target}"), - Err(e) => println!("cargo::warning=Failed to copy OpenConsole.exe: {}", e), + if cfg!(target_arch = "x86_64") || cfg!(target_arch = "aarch64") { + let out_dir = std::env::var("OUT_DIR").unwrap(); + let out_dir: &std::path::Path = out_dir.as_ref(); + let target_dir = std::path::Path::new(&out_dir) + .parent() + .and_then(|p| p.parent()) + .and_then(|p| p.parent()) + .expect("Failed to find target directory"); + + let conpty_dll_target = target_dir.join("conpty.dll"); + let open_console_target = target_dir.join("OpenConsole.exe"); + + let conpty_url = "https://github.com/microsoft/terminal/releases/download/v1.23.13503.0/Microsoft.Windows.Console.ConPTY.1.23.251216003.nupkg"; + let nupkg_path = out_dir.join("conpty.nupkg"); + let extract_dir = out_dir.join("conpty"); + + let download_script = format!( + "$ProgressPreference = 'SilentlyContinue'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '{}' -OutFile '{}'", + conpty_url, + nupkg_path.display() + ); + + let download_result = Command::new("powershell") + .args([ + "-NoProfile", + "-NonInteractive", + "-Command", + &download_script, + ]) + .output(); + + match download_result { + Ok(output) if output.status.success() => { + println!("Downloaded conpty nupkg successfully"); + + let extract_script = format!( + "$ProgressPreference = 'SilentlyContinue'; Expand-Archive -Path '{}' -DestinationPath '{}' -Force", + nupkg_path.display(), + extract_dir.display() + ); + + let extract_result = Command::new("powershell") + .args(["-NoProfile", "-NonInteractive", "-Command", &extract_script]) + .output(); + + match extract_result { + Ok(output) if output.status.success() => { + let (conpty_dll_source, open_console_source) = + if cfg!(target_arch = "x86_64") { + ( + extract_dir.join("runtimes/win-x64/native/conpty.dll"), + extract_dir + .join("build/native/runtimes/x64/OpenConsole.exe"), + ) + } else { + ( + extract_dir.join("runtimes/win-arm64/native/conpty.dll"), + extract_dir + .join("build/native/runtimes/arm64/OpenConsole.exe"), + ) + }; + + match std::fs::copy(&conpty_dll_source, &conpty_dll_target) { + Ok(_) => { + println!("Copied conpty.dll to {}", conpty_dll_target.display()) + } + Err(e) => println!( + "cargo::warning=Failed to copy conpty.dll from {}: {}", + conpty_dll_source.display(), + e + ), + } + + match std::fs::copy(&open_console_source, &open_console_target) { + Ok(_) => println!( + "Copied OpenConsole.exe to {}", + open_console_target.display() + ), + Err(e) => println!( + "cargo::warning=Failed to copy OpenConsole.exe from {}: {}", + open_console_source.display(), + e + ), + } + } + Ok(output) => { + println!( + "cargo::warning=Failed to extract conpty nupkg: {}", + String::from_utf8_lossy(&output.stderr) + ); + } + Err(e) => { + println!( + "cargo::warning=Failed to run PowerShell for extraction: {}", + e + ); + } + } + } + Ok(output) => { + println!( + "cargo::warning=Failed to download conpty nupkg: {}", + String::from_utf8_lossy(&output.stderr) + ); + } + Err(e) => { + println!( + "cargo::warning=Failed to run PowerShell for download: {}", + e + ); + } } } diff --git a/crates/zed/resources/windows/bin/x64/OpenConsole.exe b/crates/zed/resources/windows/bin/x64/OpenConsole.exe deleted file mode 100644 index 8bb6ab2188fd7a56adc941c3f8449265e762cf06..0000000000000000000000000000000000000000 Binary files a/crates/zed/resources/windows/bin/x64/OpenConsole.exe and /dev/null differ diff --git a/crates/zed/resources/windows/bin/x64/conpty.dll b/crates/zed/resources/windows/bin/x64/conpty.dll deleted file mode 100644 index 555d6bf655a7cb0427b630f1052bb873c837a152..0000000000000000000000000000000000000000 Binary files a/crates/zed/resources/windows/bin/x64/conpty.dll and /dev/null differ diff --git a/script/bundle-windows.ps1 b/script/bundle-windows.ps1 index 48114a970ff272d52c9927c65788c65dc1a5c7e7..49024be70d7f1b8cdc3a430ef991718f60da276f 100644 --- a/script/bundle-windows.ps1 +++ b/script/bundle-windows.ps1 @@ -202,8 +202,8 @@ function DownloadAMDGpuServices { } function DownloadConpty { - $url = "https://github.com/microsoft/terminal/releases/download/v1.23.12811.0/Microsoft.Windows.Console.ConPTY.1.23.251008001.nupkg" - $zipPath = ".\Microsoft.Windows.Console.ConPTY.1.23.251008001.nupkg" + $url = "https://github.com/microsoft/terminal/releases/download/v1.23.13503.0/Microsoft.Windows.Console.ConPTY.1.23.251216003.nupkg" + $zipPath = ".\Microsoft.Windows.Console.ConPTY.1.23.251216003.nupkg" Invoke-WebRequest -Uri $url -OutFile $zipPath Expand-Archive -Path $zipPath -DestinationPath ".\conpty" -Force }