From 3d9f28dd464db4e1e0b7fbc636e7af73346dc078 Mon Sep 17 00:00:00 2001 From: can1357 Date: Mon, 27 Jul 2026 17:00:31 +0200 Subject: [PATCH] refactor: resolved cross-platform build warnings and add windows-sys features - Add conditional attributes to silence dead-code warnings on platform-specific code and fields. - Update target dependencies in pi-walker/Cargo.toml with explicit windows-sys feature sets. - Simplify time cast expressions in linux_reflink and rcopy modules. --- crates/pi-iso/src/linux_reflink.rs | 10 ++-------- crates/pi-iso/src/rcopy.rs | 9 ++++----- crates/pi-shell/src/coreutils.rs | 5 ++++- crates/pi-shell/src/fd.rs | 3 +++ crates/pi-uutils-ctx/src/lib.rs | 1 + crates/pi-walker/Cargo.toml | 8 +++++++- crates/vendor/uu-find/src/find/matchers/group.rs | 1 + crates/vendor/uu-find/src/find/matchers/user.rs | 1 + crates/vendor/uu-stat/src/stat.rs | 6 ++++++ .../coding-agent/src/extensibility/extensions/types.ts | 1 - packages/coding-agent/src/extensibility/hooks/types.ts | 1 - packages/natives/CHANGELOG.md | 1 + scripts/run-rs-task.ts | 4 ++-- 13 files changed, 32 insertions(+), 19 deletions(-) diff --git a/crates/pi-iso/src/linux_reflink.rs b/crates/pi-iso/src/linux_reflink.rs index cdfe49ce7..d0a23fe79 100644 --- a/crates/pi-iso/src/linux_reflink.rs +++ b/crates/pi-iso/src/linux_reflink.rs @@ -248,14 +248,8 @@ mod imp { fn set_times_nofollow(path: &Path, meta: &fs::Metadata) -> std::io::Result<()> { let times = [ - libc::timespec { - tv_sec: meta.atime() as libc::time_t, - tv_nsec: meta.atime_nsec() as libc::c_long, - }, - libc::timespec { - tv_sec: meta.mtime() as libc::time_t, - tv_nsec: meta.mtime_nsec() as libc::c_long, - }, + libc::timespec { tv_sec: meta.atime() as _, tv_nsec: meta.atime_nsec() as libc::c_long }, + libc::timespec { tv_sec: meta.mtime() as _, tv_nsec: meta.mtime_nsec() as libc::c_long }, ]; let c_path = CString::new(path.as_os_str().as_bytes())?; // SAFETY: `c_path` and `times` live until the syscall returns; the diff --git a/crates/pi-iso/src/rcopy.rs b/crates/pi-iso/src/rcopy.rs index 000ba0ef1..876d36358 100644 --- a/crates/pi-iso/src/rcopy.rs +++ b/crates/pi-iso/src/rcopy.rs @@ -413,11 +413,10 @@ fn filetime_set(path: &Path, mtime: std::time::SystemTime) -> std::io::Result<() let dur = mtime .duration_since(std::time::UNIX_EPOCH) .map_err(std::io::Error::other)?; - let times = - [libc::timespec { tv_sec: dur.as_secs() as libc::time_t, tv_nsec: 0 }, libc::timespec { - tv_sec: dur.as_secs() as libc::time_t, - tv_nsec: dur.subsec_nanos() as libc::c_long, - }]; + let times = [libc::timespec { tv_sec: dur.as_secs() as _, tv_nsec: 0 }, libc::timespec { + tv_sec: dur.as_secs() as _, + tv_nsec: dur.subsec_nanos() as libc::c_long, + }]; let c_path = std::ffi::CString::new(path.as_os_str().as_bytes())?; // SAFETY: `c_path` and `times` outlive the syscall; the kernel does // not retain the pointers. diff --git a/crates/pi-shell/src/coreutils.rs b/crates/pi-shell/src/coreutils.rs index 69b1c3d79..17fe7221b 100644 --- a/crates/pi-shell/src/coreutils.rs +++ b/crates/pi-shell/src/coreutils.rs @@ -7,9 +7,11 @@ //! thread-local context isolated across concurrent pipeline stages and avoids //! blocking the async runtime on synchronous utility I/O. +#[cfg(unix)] +use std::ffi::OsStr; use std::{ collections::HashMap, - ffi::{OsStr, OsString}, + ffi::OsString, io::{self, Read, Write}, panic::catch_unwind, sync::{ @@ -106,6 +108,7 @@ async fn run_uutil( // brush passes the command name as the first `CommandArg`, which is exactly // the argv[0] uutils' argument parsing expects. + #[cfg_attr(not(unix), allow(unused_mut))] let mut argv: Vec = args .iter() .map(|arg| OsString::from(arg.to_string())) diff --git a/crates/pi-shell/src/fd.rs b/crates/pi-shell/src/fd.rs index 021b8856f..42aba7736 100644 --- a/crates/pi-shell/src/fd.rs +++ b/crates/pi-shell/src/fd.rs @@ -511,12 +511,14 @@ struct SizeFilter { bytes: u64, } +#[cfg_attr(not(unix), allow(dead_code))] #[derive(Clone, Copy)] enum OwnerSide { Include(u32), Exclude(u32), } +#[cfg_attr(not(unix), allow(dead_code))] #[derive(Clone, Copy)] struct OwnerMatcher { user: Option, @@ -1183,6 +1185,7 @@ fn matches_owner_filters(filters: &[OwnerMatcher], _metadata: Option<&Metadata>) filters.is_empty() } +#[cfg(unix)] const fn owner_side_matches(side: OwnerSide, actual: u32) -> bool { match side { OwnerSide::Include(expected) => actual == expected, diff --git a/crates/pi-uutils-ctx/src/lib.rs b/crates/pi-uutils-ctx/src/lib.rs index 31c18e912..edd9d8c26 100644 --- a/crates/pi-uutils-ctx/src/lib.rs +++ b/crates/pi-uutils-ctx/src/lib.rs @@ -29,6 +29,7 @@ struct Ctx { stdin: Box, /// Raw fd backing `stdin` when it is a real OS file/pipe, used for /// cancellable readiness polling on unix. `None` for non-fd readers. + #[cfg_attr(not(unix), allow(dead_code))] stdin_fd: Option, /// Whether stdin is a shell pipe/stream that should be searched implicitly. stdin_is_search_input: bool, diff --git a/crates/pi-walker/Cargo.toml b/crates/pi-walker/Cargo.toml index 858680fa1..170b2ee6e 100644 --- a/crates/pi-walker/Cargo.toml +++ b/crates/pi-walker/Cargo.toml @@ -20,4 +20,10 @@ rayon.workspace = true libc.workspace = true [target.'cfg(windows)'.dependencies] -windows-sys = { workspace = true, features = ["Wdk_Storage_FileSystem"] } +windows-sys = { workspace = true, features = [ + "Wdk_Storage_FileSystem", + "Win32_Foundation", + "Win32_Security", + "Win32_Storage_FileSystem", + "Win32_System_IO", +] } diff --git a/crates/vendor/uu-find/src/find/matchers/group.rs b/crates/vendor/uu-find/src/find/matchers/group.rs index dee07ee32..b97cec695 100644 --- a/crates/vendor/uu-find/src/find/matchers/group.rs +++ b/crates/vendor/uu-find/src/find/matchers/group.rs @@ -12,6 +12,7 @@ use nix::unistd::Group; use super::{ComparableValue, Matcher, MatcherIO, WalkEntry}; pub struct GroupMatcher { + #[cfg_attr(not(unix), allow(dead_code))] gid: ComparableValue, } diff --git a/crates/vendor/uu-find/src/find/matchers/user.rs b/crates/vendor/uu-find/src/find/matchers/user.rs index c042168e8..d9c788fb2 100644 --- a/crates/vendor/uu-find/src/find/matchers/user.rs +++ b/crates/vendor/uu-find/src/find/matchers/user.rs @@ -12,6 +12,7 @@ use nix::unistd::User; use super::{ComparableValue, Matcher, MatcherIO, WalkEntry}; pub struct UserMatcher { + #[cfg_attr(not(unix), allow(dead_code))] uid: ComparableValue, } diff --git a/crates/vendor/uu-stat/src/stat.rs b/crates/vendor/uu-stat/src/stat.rs index 04f7a22cf..6b23ed9ad 100644 --- a/crates/vendor/uu-stat/src/stat.rs +++ b/crates/vendor/uu-stat/src/stat.rs @@ -146,8 +146,10 @@ for details about the options it supports."; #[error("{directive}: invalid directive")] InvalidDirective { directive: String }, #[error("cannot read table of mounted file systems: {error}")] + #[cfg_attr(not(unix), allow(dead_code))] CannotReadFilesystem { error: String }, #[error("using '-' to denote standard input does not work in file system mode")] + #[cfg_attr(not(unix), allow(dead_code))] StdinFilesystemMode, #[error("cannot read file system information for {file}: {error}")] CannotReadFilesystemInfo { file: String, error: String }, @@ -275,6 +277,7 @@ for details about the options it supports."; #[derive(Debug)] pub enum OutputType<'a> { Str(String), + #[cfg_attr(not(unix), allow(dead_code))] OsStr(&'a OsString), Integer(i64), Unsigned(u64), @@ -413,9 +416,12 @@ for details about the options it supports."; show_fs: bool, from_user: bool, files: Vec, + #[cfg_attr(not(unix), allow(dead_code))] mount_list: OnceCell>>, + #[cfg_attr(not(unix), allow(dead_code))] mount_list_needed: bool, default_tokens: Vec, + #[cfg_attr(not(unix), allow(dead_code))] default_dev_tokens: Vec, } diff --git a/packages/coding-agent/src/extensibility/extensions/types.ts b/packages/coding-agent/src/extensibility/extensions/types.ts index 0d7493b68..8bcd246bb 100644 --- a/packages/coding-agent/src/extensibility/extensions/types.ts +++ b/packages/coding-agent/src/extensibility/extensions/types.ts @@ -1044,7 +1044,6 @@ export interface RegisteredCommand { // ============================================================================ /** Handler function type for events */ -// biome-ignore lint/suspicious/noConfusingVoidType: void allows bare return statements export type ExtensionHandler = (event: E, ctx: ExtensionContext) => Promise | R | void; /** Service tiers accepted by each provider family. */ diff --git a/packages/coding-agent/src/extensibility/hooks/types.ts b/packages/coding-agent/src/extensibility/hooks/types.ts index 19fb55c4d..6fe44f305 100644 --- a/packages/coding-agent/src/extensibility/hooks/types.ts +++ b/packages/coding-agent/src/extensibility/hooks/types.ts @@ -444,7 +444,6 @@ export type { * Handler function type for each event. * Handlers can return R, undefined, or void (bare return statements). */ -// biome-ignore lint/suspicious/noConfusingVoidType: void allows bare return statements in handlers export type HookHandler = (event: E, ctx: HookContext) => Promise | R | void; export interface HookMessageRenderOptions { diff --git a/packages/natives/CHANGELOG.md b/packages/natives/CHANGELOG.md index cedea7213..0cfaf1bdb 100644 --- a/packages/natives/CHANGELOG.md +++ b/packages/natives/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed - napi binding build failures now surface the exit code and the tail of stdout/stderr instead of a bare "napi build failed" message ([#6799](https://github.com/can1357/oh-my-pi/pull/6799)). +- Silenced cross-platform Rust build warnings: dead-code on unix-only fields/helpers in `pi-uutils-ctx`, `pi-shell` (fd owner filters, coreutils argv), and vendored `uu-find`/`uu-stat` when compiling for Windows, and deprecated `libc::time_t` casts in `pi-iso` on musl. `pi-walker` now declares the `windows-sys` features it uses (`Win32_Foundation`, `Win32_Security`, `Win32_Storage_FileSystem`, `Win32_System_IO`) instead of relying on workspace-wide feature unification. ### Changed diff --git a/scripts/run-rs-task.ts b/scripts/run-rs-task.ts index c385381c5..fe8c1df40 100644 --- a/scripts/run-rs-task.ts +++ b/scripts/run-rs-task.ts @@ -26,7 +26,7 @@ const VENDORED_FORK_EXCLUDES = [ const TASK_COMMANDS = { "check:rs": [ ["cargo", "fmt", "--all", "--", "--check"], - ["cargo", "clippy", "--workspace", ...VENDORED_FORK_EXCLUDES, "--", "-D", "warnings"], + ["cargo", "clippy", "--workspace", ...VENDORED_FORK_EXCLUDES, "--no-deps", "--", "-D", "warnings"], ], "fix:rs": [ ["cargo", "fmt", "--all"], @@ -43,7 +43,7 @@ const TASK_COMMANDS = { ], ], "fmt:rs": [["cargo", "fmt", "--all"]], - "lint:rs": [["cargo", "clippy", "--workspace", ...VENDORED_FORK_EXCLUDES, "--", "-D", "warnings"]], + "lint:rs": [["cargo", "clippy", "--workspace", ...VENDORED_FORK_EXCLUDES, "--no-deps", "--", "-D", "warnings"]], "test:rs": [ [ "cargo",