rust9x / rust

Empowering everyone to build reliable and efficient software, even for Windows 9x/Me/NT/2000/XP/Vista.
https://github.com/rust9x/rust/wiki
Other
319 stars 9 forks source link

stdin() Doesn't Work On Windows XP's cmd.exe #18

Closed nix-enthusiast closed 5 months ago

nix-enthusiast commented 5 months ago

I found this bug which was not mentioned in the wiki.

justfile:

set shell := ['powershell.exe', '-c']

r9x_toolchain := 'rust9x'
r9x_target := 'i586-rust9x-windows-msvc'
r9x_editbin := 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\bin\Hostx64\x64\editbin.exe'

subsystem := 'CONSOLE,4.0'
os_version := '3.1'

build *FLAGS: (do-build 'release' FLAGS)
release *FLAGS: (do-build 'release' '--release' FLAGS)
do-build PROFILE *FLAGS='': (r9x 'build' '--target' r9x_target FLAGS) (editbin 'target\'+r9x_target+'\'+PROFILE+'\r9x-stdin.exe')
run *FLAGS: (r9x 'run' '--target' r9x_target FLAGS)

r9x $COMMAND *FLAGS:
    $env:RUSTFLAGS='-C target-feature=+crt-static' ; cargo +{{ r9x_toolchain }} {{ COMMAND }} {{ FLAGS }}

editbin EXECUTABLE:
    & "{{ r9x_editbin }}" {{ EXECUTABLE }} /SUBSYSTEM:{{ subsystem }} /OSVERSION:{{ os_version }} /RELEASE

src/main.rs

fn main() {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).unwrap();
    println!("{}",buffer);
}

Cargo.toml is untouched.

Compilation is successful but running the executable on Windows XP ends with an error:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\VMUser>E:\r9x-stdin.exe
hello
thread 'main' panicked at src\main.rs:3:45:
called `Result::unwrap()` on an `Err` value: Error { kind: InvalidData, message:
 "Windows stdin in console mode does not support non-UTF-16 input; encountered unpaired surrogate" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

C:\Documents and Settings\VMUser>

Also unicows.dll is included alongside but not linked against the executable

total 1984
-rwxr-xr-x 1 spy spy 274944 Jan 28 17:24 convert_numbers.exe
-rw-r--r-- 1 spy spy    487 Jan 28  2024 error.txt
-rwxr-xr-x 1 spy spy 256512 Jan 28 20:00 hello_world.exe
-rw-r--r-- 1 spy spy  28027 Oct  4  2004 license.txt
-rwxr-xr-x 1 spy spy 594432 Jan 28 16:33 linkread.exe
-rwxr-xr-x 1 spy spy 248320 Jan 28 20:28 r9x-stdin.exe
-rw-r--r-- 1 spy spy    608 Oct  4  2004 redist.txt
-rw-r--r-- 1 spy spy 258352 Dec  7  2004 unicows.dll
-rw-r--r-- 1 spy spy 347136 Dec  7  2004 unicows.pdb
seritools commented 5 months ago

Oh, it uses WC_ERR_INVALID_CHARS, which isn't supported before Vista - I'll think of a fallback/workaround.

seritools commented 5 months ago

Fixed in release 4: https://github.com/rust9x/rust/releases/tag/rust9x-1.76-beta-v4