Repository navigation
rust: Port util/pipe-windows.c to obs-util - #259
Conversation
The process cases of test_pipe were POSIX-only. Add Windows versions with cmd.exe children: - read and write mode, stderr, and exit codes returned as (int)DWORD (255 and 256 stay, -1 is -1; there is no char cast as in pipe-posix.c) - how os_process_pipe_create2 quotes arguments into one command line, read back through cmd's echo: empty args and args with a space or tab are quoted, quotes are escaped, and backslashes before a quote or the closing quote are doubled - a missing program and an empty command line fail to spawn - only a leading 'r' or 'w' is accepted as the type, unlike POSIX - NULL arguments read_all moves out of the POSIX-only block. All cases pass against the current C. Refs obs-rust#258 Co-Authored-By: Claude Opus 5.5 <[email protected]>
- oracle: pipe-windows.c compiled on Windows as oracle_* (build.rs now skips *_windows.c wrappers elsewhere, like *_posix.c) - obs-util: the process shims are built on Windows too, over a Windows Pipe with the POSIX API, plus create_logged/create2_logged so the shim logs a failed CreateProcessW like C. windows_command_line, the create2 quoting, is platform-neutral. All of it is todo!() here. - Tier 1 (tests/pipe.rs): the quoting on every OS, and the Windows cases of test_pipe with cmd.exe children - Tier 3 (tests/pipe_parity.rs): commands, create2 (including random arguments read back through cmd's echo), chunked reads, writes, a write to an exited child and nulls against the oracle. Spawning is serialized: children inherit every inheritable handle, as in C. - util/pipe-windows.c is left out of libobs with ENABLE_RUST_LIBOBS, and the process exports lose their `unix` marker Refs obs-rust#258 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Windows half of the pipe port, in obs_util::pipe::windows. It calls Win32 as the C does rather than std::process::Command, which resolves the program itself (so the search order differs), cannot set STARTF_FORCEOFFFEEDBACK and limits the handles a child inherits: - CreatePipe with inheritable ends, our ends made private, then CreateProcessW with no application name, CREATE_NO_WINDOW and every inheritable handle inherited; the command line is converted like os_utf8_to_wcs_ptr (BOM dropped, invalid UTF-8 as U+FFFD) - only a leading 'r' or 'w' is a type; one ReadFile/WriteFile per call with the length cast to DWORD; the exit code is (int)DWORD - a failed CreateProcessW is logged by the shim through blog, with the error code and not the command line - windows_command_line is create2's quoting Intentional difference: C leaks the handles it already made when creating a pipe fails half-way; they are closed here. Mutation check: dropping the doubling of backslashes before a closing quote fails the Tier 1 quoting tests and, on its own, Tier 3 (process_create2_matches_oracle and create2_quoting_matches_oracle); casting the exit code through char fails pipe_exit_code_mirrors_test_pipe_exit_code. Closes obs-rust#258 Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=1d7a4a40811e727ab14814994b9beb8590952992 secs=94 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791749583,"gate":"rust/all/fmt","host":"linux-x86_64","key":"c3a46f924323191e2d7625457f29decef671038145e924d6ec011a5df3c33a29","lane":"lint","parents":["340f5d17a4c5669de1b98bdc148f020f02ac1361"],"secs":17,"stamp":"5560b1ab6fce619b9f21ab0bc74f4b8c","tree":"1d7a4a40811e727ab14814994b9beb8590952992","v":1,"via":"run"} Ci-Attestation: {"at":1791749583,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"c3a46f924323191e2d7625457f29decef671038145e924d6ec011a5df3c33a29","lane":"lint","parents":["340f5d17a4c5669de1b98bdc148f020f02ac1361"],"secs":17,"stamp":"85996a0237e52f789a6703c174255a75","tree":"1d7a4a40811e727ab14814994b9beb8590952992","v":1,"via":"run"} Ci-Attestation: {"at":1791749583,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"6001cd1e5f0967967f9b5f93e55ff2f3633af2a4b47e59dcf9d83beebfefda36","lane":"rust-test","parents":["340f5d17a4c5669de1b98bdc148f020f02ac1361"],"secs":27,"stamp":"fe48744c5b06f180730a270fb14c0f8f","tree":"1d7a4a40811e727ab14814994b9beb8590952992","v":1,"via":"run"} Ci-Attestation: {"at":1791749583,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"0522de807392758f6c3e6a0289978640974392ba6079361c612e39def8dc6d30","lane":"tier2-linux","parents":["340f5d17a4c5669de1b98bdc148f020f02ac1361"],"secs":49,"stamp":"21380b44553346a5d921f6ced545ee9a","tree":"1d7a4a40811e727ab14814994b9beb8590952992","v":1,"via":"run"}
7409652 to
306ec7a
Compare
|
Rebased onto current master, Linux-verified and stamped. The new head is
Merging once CI, including both Windows jobs, is green. |
|
Thanks for the rebase and the Linux run. The Windows Tier 2 failure was mine. The core now declares its ten Locally on Windows: the |
|
Windows Rust Tests pass, but Rust Tier 2 windows fails to link with Likely cause: Options, roughly in order of effort:
I can't reproduce this on Linux, so I'll leave the fix to you, since you're on Windows. It's ready to merge as soon as the Windows Tier 2 job is green. |
|
This merged at |
#259 merged with the core taking its Win32 calls from windows-sys 0.61, which links through windows-link's raw-dylib import records. std imports api-ms-win-core-synch-l1-2-0 the same way, and libobs links libobs_rust.lib with WHOLEARCHIVE, so obs.dll gets both records and the Windows ENABLE_RUST_LIBOBS=ON build fails: libobs_rust.lib(api-ms-win-core-synch-l1-2-0.dll) : error LNK2005: __IMPORT_DESCRIPTOR_api-ms-win-core-synch-l1-2-0 already defined obs.dll : fatal error LNK1169 The module now declares its ten kernel32 functions and three structs itself, against kernel32.lib like ffi::bmem declares malloc, with size checks against the SDK, and obs-util no longer depends on windows-sys. Behavior is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes #258. This is the
pipe-windows.citem of #153; the POSIX half was #78. With it, the pipe port covers every OS.Commits
C characterization (
test/cmocka/test_pipe.c). The process cases were POSIX-only; this adds Windows versions withcmd.exechildren:(int)DWORD: 255 and 256 stay as they are,exit -1is -1, and there is no char cast as in pipe-posix.cr/wis accepted, unlike POSIXos_process_pipe_create2quotes arguments, read back throughcmd /c echo, which prints its command line as givenAll pass against the current C.
RED.
oracle/pipe_windows.ccompilespipe-windows.casoracle_*on Windows.build.rsskips*_windows.celsewhere, as it does*_posix.c.Pipewith the POSIX API.create_logged/create2_loggedlet the shim log a failedCreateProcessWthroughblog, like C.windows_command_line(create2's quoting) is platform-neutral, so the quoting is tested on every OS.pipe-windows.cis behindENABLE_RUST_LIBOBS, and the process exports lose theirunixmarker.export_list.rskeeps the marker check for future per-OS ports but no longer expects a Unix-only shim.GREEN:
obs_util::pipe::windows.Why Win32 and not
std::process::CommandCommanddiffers fromCreateProcessW(NULL, cmd_line, …, bInheritHandles=TRUE, CREATE_NO_WINDOW, …)in ways a caller can see:STARTF_FORCEOFFFEEDBACKSo the core calls the same Win32 functions in the same order. They're declared in the module against
kernel32.lib, with size checks on the three structs, rather than taken fromwindows-sys. A first version usedwindows-sys, and its import records for DLLs thatstdalso imports ended up twice inlibobs_rust.lib, so the Rust-ONobs.dlllink failed withLNK2005 __IMPORT_DESCRIPTOR_api-ms-win-core-synch-l1-2-0. The command line is converted likeos_utf8_to_wcs_ptron Windows: BOM dropped,MultiByteToWideChar(CP_UTF8, 0, …), so invalid UTF-8 becomes U+FFFD.Intentional difference: when creating a pipe fails half-way, C leaks the handles it already made (both stderr ends, or the stdio pair if the second
CreatePipefails). The port closes them. Only the handle count can tell.Tests
tests/pipe.rs): the quoting (the cmocka case, runs of backslashes before a quote and at the end, empty and lone programs) on every OS. On Windows, the cmocka process cases, the logged error codes (2 for a missing program, 87 for an empty command line) and the BOM.tests/pipe_parity.rs, Windows), against the oracle:create2casescmd /c echoMutation check:
process_create2_matches_oracle,create2_quoting_matches_oracle).charfailspipe_exit_code_mirrors_test_pipe_exit_code.Run locally on Windows (MSVC):
test_pipe.cagainst the realpipe-windows.c: 14/14test_pipe.clinked againstlibobs_rust.lib: 14/14, with theCreateProcessW failed: 2/87lines fromblogcargo test --workspace-D warningsfor Windows, x86_64 Linux and aarch64 macOSaarch64 Linux shows only the existing
ffi/dstr.rscasts. Windows CI is the real gate for the CMake side.🤖 Generated with Claude Code