Skip to content

Commit

Permalink
pty: windows: allow loading a newer conpty dll
Browse files Browse the repository at this point in the history
This commit allows loading the console functions from `conpty.dll`
instead of `kernel32.dll` which means that we can update and
track newer features than have been deployed to Windows.

In practical terms this means that we can now unlock mouse input
reporting in eg: VIM running under WSL.
refs: microsoft/terminal#376

We're jumping the gun on this issue, which is tracking making
a proper supportable way to deploy this sort of update:
refs: microsoft/terminal#1130

For now it seems easier just for us to bundle our own copy of
these bits.

This includes a speculative change to include those in our
Windows downloads also.

The binaries were built from
microsoft/terminal@4f8acb4
  • Loading branch information
wez committed Apr 6, 2020
1 parent d98fee9 commit 61e3545
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
Binary file added assets/windows/conhost/OpenConsole.exe
Binary file not shown.
22 changes: 22 additions & 0 deletions assets/windows/conhost/README.md
Original file line number Diff line number Diff line change
@@ -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
Binary file added assets/windows/conhost/conpty.dll
Binary file not shown.
17 changes: 17 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
6 changes: 5 additions & 1 deletion ci/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand Down
21 changes: 18 additions & 3 deletions pty/src/win/psuedocon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 61e3545

Please sign in to comment.