diff --git a/assets/windows/conhost/OpenConsole.exe b/assets/windows/conhost/OpenConsole.exe new file mode 100644 index 00000000000..bb60af24e1f Binary files /dev/null and b/assets/windows/conhost/OpenConsole.exe differ diff --git a/assets/windows/conhost/README.md b/assets/windows/conhost/README.md new file mode 100644 index 00000000000..da9bcc1c6f2 --- /dev/null +++ b/assets/windows/conhost/README.md @@ -0,0 +1,22 @@ +# Console Host + +This directory contains a copy of built artifacts from the Microsoft +Terminal project which is provided by Microsoft under the terms +of the MIT license. + +Why are they here? At the time of writing, the conpty implementation +that ships with windows is lacking support for mouse reporting but +that support is available in the opensource project so it is desirable +to point to that so that we can enable mouse reporting in wezterm. + +It looks like we'll eventually be able to drop this once Windows +and/or the build for the terminal project make some more progress. + +https://github.com/microsoft/terminal/issues/1130 + +These assets were built by opening the solution in visual studio 2019 and +building the `Host.EXE` and `winconpty.DLL` projects. + +It's possible that you'll need to download this runtime support package +from MS in order for this to work: +https://www.microsoft.com/en-us/download/details.aspx?id=53175 diff --git a/assets/windows/conhost/conpty.dll b/assets/windows/conhost/conpty.dll new file mode 100644 index 00000000000..35b0fb80e41 Binary files /dev/null and b/assets/windows/conhost/conpty.dll differ diff --git a/build.rs b/build.rs index 7449dbe5fb8..de897c1092f 100644 --- a/build.rs +++ b/build.rs @@ -18,6 +18,23 @@ fn main() { println!("cargo:rustc-env=WEZTERM_CI_TAG={}", ci_tag); println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.9"); + #[cfg(windows)] + { + use std::path::Path; + let profile = std::env::var("PROFILE").unwrap(); + let exe_output_dir = Path::new("target").join(profile); + let exe_src_dir = Path::new("assets/windows/conhost"); + + for name in &["conpty.dll", "OpenConsole.exe"] { + let dest_name = exe_output_dir.join(name); + let src_name = exe_src_dir.join(name); + + if !dest_name.exists() { + std::fs::copy(src_name, dest_name).unwrap(); + } + } + } + #[cfg(windows)] embed_resource::compile("assets/windows/resource.rc"); } diff --git a/ci/deploy.sh b/ci/deploy.sh index 63b0d4fba1e..c525907f7ad 100755 --- a/ci/deploy.sh +++ b/ci/deploy.sh @@ -39,7 +39,11 @@ case $OSTYPE in fi rm -rf $zipdir $zipname mkdir $zipdir - cp $TARGET_DIR/release/wezterm.exe $TARGET_DIR/release/wezterm.pdb $zipdir + cp $TARGET_DIR/release/wezterm.exe \ + $TARGET_DIR/release/wezterm.pdb \ + assets/windows/conhost/conpty.dll \ + assets/windows/conhost/OpenConsole.exe \ + $zipdir cp -r assets/colors $zipdir/ 7z a -tzip $zipname $zipdir ;; diff --git a/pty/src/win/psuedocon.rs b/pty/src/win/psuedocon.rs index aa583c2d470..9cd0a235ed3 100644 --- a/pty/src/win/psuedocon.rs +++ b/pty/src/win/psuedocon.rs @@ -36,10 +36,25 @@ shared_library!(ConPtyFuncs, pub fn ClosePseudoConsole(hpc: HPCON), ); -lazy_static! { - static ref CONPTY: ConPtyFuncs = ConPtyFuncs::open(Path::new("kernel32.dll")).expect( - "this system does not support conpty. Windows 10 October 2018 or newer is required" +fn load_conpty() -> ConPtyFuncs { + // If the kernel doesn't export these functions then their system is + // too old and we cannot run. + let kernel = ConPtyFuncs::open(Path::new("kernel32.dll")).expect( + "this system does not support conpty. Windows 10 October 2018 or newer is required", ); + + // We prefer to use a sideloaded conpty.dll and openconsole.exe host deployed + // alongside the application. We check for this after checking for kernel + // support so that we don't try to proceed and do something crazy. + if let Ok(sideloaded) = ConPtyFuncs::open(Path::new("conpty.dll")) { + sideloaded + } else { + kernel + } +} + +lazy_static! { + static ref CONPTY: ConPtyFuncs = load_conpty(); } pub struct PsuedoCon {