From a903f710ea5281faffee78cfd9d7c7a255d9e249 Mon Sep 17 00:00:00 2001 From: Jonathan Gilbert Date: Mon, 3 Nov 2025 20:19:13 -0600 Subject: [PATCH] Eliminate build warnings from the Scrap crate (#13383) * Updated build.rs to tell RustC that dxgi, quartz and x11 are expected configurations. Added lifetime annotations to various methods in common/aom.rs and common/vpxcodec.rs. Updated common/vpx.rs to allow unused_imports in the generated bindings. Updated dxgi/mag.rs to allow non_snake_case identifiers like "dwFilterMode". * Added lifetime annotations to methods in common/hwcodec.rs and common/vram.rs. * Switched syntax for the rustc-check-cfg directive emitted by build.rs in the scrap crate to use syntax compatible with Rust toolchain version 1.75. The double-colon syntax requires 1.77 or newer, but the older single-colon syntax works fine on newer versions for this directive. * Update libs/scrap/build.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Revert apparently-erroneous AI suggestion. It's usually pretty good, but not always right it seems. :-) This reverts commit bf862b13f6f97347249918aa5b1836d70f66483c. * Removed redundant configuration directives from libs/scrap/build.rs. --------- Co-authored-by: RustDesk <71636191+rustdesk@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- libs/scrap/build.rs | 18 +++--------------- libs/scrap/src/common/aom.rs | 6 +++--- libs/scrap/src/common/hwcodec.rs | 2 +- libs/scrap/src/common/vpx.rs | 1 + libs/scrap/src/common/vpxcodec.rs | 8 ++++---- libs/scrap/src/common/vram.rs | 2 +- libs/scrap/src/dxgi/mag.rs | 2 ++ 7 files changed, 15 insertions(+), 24 deletions(-) diff --git a/libs/scrap/build.rs b/libs/scrap/build.rs index 5332b568f..73765055d 100644 --- a/libs/scrap/build.rs +++ b/libs/scrap/build.rs @@ -227,24 +227,12 @@ fn ffmpeg() { */ fn main() { + // in this crate, these are also valid configurations + println!("cargo:rustc-check-cfg=cfg(dxgi,quartz,x11)"); + // there is problem with cfg(target_os) in build.rs, so use our workaround let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap(); - // We check if is macos, because macos uses rust 1.8.1. - // `cargo::rustc-check-cfg` is new with Cargo 1.80. - // No need to run `cargo version` to get the version here, because: - // The following lines are used to suppress the lint warnings. - // warning: unexpected `cfg` condition name: `quartz` - if cfg!(target_os = "macos") { - if target_os != "ios" { - println!("cargo::rustc-check-cfg=cfg(android)"); - println!("cargo::rustc-check-cfg=cfg(dxgi)"); - println!("cargo::rustc-check-cfg=cfg(quartz)"); - println!("cargo::rustc-check-cfg=cfg(x11)"); - // ^^^^^^^^^^^^^^^^^^^^^^ new with Cargo 1.80 - } - } - // note: all link symbol names in x86 (32-bit) are prefixed wth "_". // run "rustup show" to show current default toolchain, if it is stable-x86-pc-windows-msvc, // please install x64 toolchain by "rustup toolchain install stable-x86_64-pc-windows-msvc", diff --git a/libs/scrap/src/common/aom.rs b/libs/scrap/src/common/aom.rs index 4bf17a2fe..e5093e54b 100644 --- a/libs/scrap/src/common/aom.rs +++ b/libs/scrap/src/common/aom.rs @@ -287,7 +287,7 @@ impl EncoderApi for AomEncoder { } impl AomEncoder { - pub fn encode(&mut self, ms: i64, data: &[u8], stride_align: usize) -> Result { + pub fn encode<'a>(&'a mut self, ms: i64, data: &[u8], stride_align: usize) -> Result> { let bpp = if self.i444 { 24 } else { 12 }; if data.len() < self.width * self.height * bpp / 8 { return Err(Error::FailedCall("len not enough".to_string())); @@ -461,7 +461,7 @@ impl AomDecoder { Ok(Self { ctx }) } - pub fn decode(&mut self, data: &[u8]) -> Result { + pub fn decode<'a>(&'a mut self, data: &[u8]) -> Result> { call_aom!(aom_codec_decode( &mut self.ctx, data.as_ptr(), @@ -476,7 +476,7 @@ impl AomDecoder { } /// Notify the decoder to return any pending frame - pub fn flush(&mut self) -> Result { + pub fn flush<'a>(&'a mut self) -> Result> { call_aom!(aom_codec_decode( &mut self.ctx, ptr::null(), diff --git a/libs/scrap/src/common/hwcodec.rs b/libs/scrap/src/common/hwcodec.rs index baec39577..17eda7f3c 100644 --- a/libs/scrap/src/common/hwcodec.rs +++ b/libs/scrap/src/common/hwcodec.rs @@ -364,7 +364,7 @@ impl HwRamDecoder { } } } - pub fn decode(&mut self, data: &[u8]) -> ResultType> { + pub fn decode<'a>(&'a mut self, data: &[u8]) -> ResultType>> { match self.decoder.decode(data) { Ok(v) => Ok(v.iter().map(|f| HwRamDecoderImage { frame: f }).collect()), Err(e) => Err(anyhow!(e)), diff --git a/libs/scrap/src/common/vpx.rs b/libs/scrap/src/common/vpx.rs index eb655314b..d627dcf6c 100644 --- a/libs/scrap/src/common/vpx.rs +++ b/libs/scrap/src/common/vpx.rs @@ -3,6 +3,7 @@ #![allow(non_upper_case_globals)] #![allow(improper_ctypes)] #![allow(dead_code)] +#![allow(unused_imports)] impl Default for vpx_codec_enc_cfg { fn default() -> Self { diff --git a/libs/scrap/src/common/vpxcodec.rs b/libs/scrap/src/common/vpxcodec.rs index 244f38ed5..f41dfb134 100644 --- a/libs/scrap/src/common/vpxcodec.rs +++ b/libs/scrap/src/common/vpxcodec.rs @@ -231,7 +231,7 @@ impl EncoderApi for VpxEncoder { } impl VpxEncoder { - pub fn encode(&mut self, pts: i64, data: &[u8], stride_align: usize) -> Result { + pub fn encode<'a>(&'a mut self, pts: i64, data: &[u8], stride_align: usize) -> Result> { let bpp = if self.i444 { 24 } else { 12 }; if data.len() < self.width * self.height * bpp / 8 { return Err(Error::FailedCall("len not enough".to_string())); @@ -268,7 +268,7 @@ impl VpxEncoder { } /// Notify the encoder to return any pending packets - pub fn flush(&mut self) -> Result { + pub fn flush<'a>(&'a mut self) -> Result> { call_vpx!(vpx_codec_encode( &mut self.ctx, ptr::null(), @@ -473,7 +473,7 @@ impl VpxDecoder { /// The `data` slice is sent to the decoder /// /// It matches a call to `vpx_codec_decode`. - pub fn decode(&mut self, data: &[u8]) -> Result { + pub fn decode<'a>(&'a mut self, data: &[u8]) -> Result> { call_vpx!(vpx_codec_decode( &mut self.ctx, data.as_ptr(), @@ -489,7 +489,7 @@ impl VpxDecoder { } /// Notify the decoder to return any pending frame - pub fn flush(&mut self) -> Result { + pub fn flush<'a>(&'a mut self) -> Result> { call_vpx!(vpx_codec_decode( &mut self.ctx, ptr::null(), diff --git a/libs/scrap/src/common/vram.rs b/libs/scrap/src/common/vram.rs index c003fa698..22645d92b 100644 --- a/libs/scrap/src/common/vram.rs +++ b/libs/scrap/src/common/vram.rs @@ -367,7 +367,7 @@ impl VRamDecoder { } } } - pub fn decode(&mut self, data: &[u8]) -> ResultType> { + pub fn decode<'a>(&'a mut self, data: &[u8]) -> ResultType>> { match self.decoder.decode(data) { Ok(v) => Ok(v.iter().map(|f| VRamDecoderImage { frame: f }).collect()), Err(e) => Err(anyhow!(e)), diff --git a/libs/scrap/src/dxgi/mag.rs b/libs/scrap/src/dxgi/mag.rs index cc36b3c23..75fc892cf 100644 --- a/libs/scrap/src/dxgi/mag.rs +++ b/libs/scrap/src/dxgi/mag.rs @@ -1,4 +1,6 @@ // logic from webrtc -- https://github.com/shiguredo/libwebrtc/blob/main/modules/desktop_capture/win/screen_capturer_win_magnifier.cc +#![allow(non_snake_case)] + use lazy_static; use std::{ ffi::CString,