diff --git a/crates/client/build.rs b/crates/client/build.rs index ea13a8a..34caf8c 100644 --- a/crates/client/build.rs +++ b/crates/client/build.rs @@ -7,9 +7,16 @@ const COLORS: [&str; 10] = [ "ground", "raise", "hov", "press", "thread", "off", "faint", "dim", "paper", "bad", ]; const SCALES: [&str; 6] = ["space", "radius", "stroke", "text", "size", "leading"]; +const MEDIA_FOUNDATION: [&str; 3] = ["mf.dll", "mfplat.dll", "mfreadwrite.dll"]; fn main() { println!("cargo::rerun-if-changed={SOURCE}"); + if env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc") { + for dll in MEDIA_FOUNDATION { + println!("cargo::rustc-link-arg-bins=/DELAYLOAD:{dll}"); + } + println!("cargo::rustc-link-arg-bins=delayimp.lib"); + } let tokens: Table = fs::read_to_string(SOURCE) .expect("read tokens") .parse() diff --git a/crates/client/src/share/camera.rs b/crates/client/src/share/camera.rs index fa37387..e2a8150 100644 --- a/crates/client/src/share/camera.rs +++ b/crates/client/src/share/camera.rs @@ -57,6 +57,18 @@ impl Drop for Camera { } } +const MEDIA_FOUNDATION: [&str; 3] = ["mf.dll", "mfplat.dll", "mfreadwrite.dll"]; + +fn available() -> bool { + if !cfg!(windows) { + return true; + } + let system = std::env::var("SystemRoot").unwrap_or_else(|_| r"C:\Windows".to_string()); + MEDIA_FOUNDATION + .iter() + .all(|dll| std::path::Path::new(&system).join("System32").join(dll).exists()) +} + pub fn open(top: Quality) -> Result { if let Ok(spec) = std::env::var("YUMUSH_TEST_CAMERA") { let (width, height, refresh, frames, generator) = fake::start(&spec); @@ -73,6 +85,9 @@ pub fn open(top: Quality) -> Result { _fake: Some(generator), }); } + if !available() { + return Err("Camera needs the Media Feature Pack".to_string()); + } let (negotiated_tx, negotiated_rx) = sync_channel::>(1); let (frames_tx, frames_rx) = sync_channel(FRAME_QUEUE); let stop = Arc::new(AtomicBool::new(false)); @@ -123,6 +138,9 @@ pub fn list() -> Vec { .into_iter() .collect(); } + if !available() { + return Vec::new(); + } let any = RequestedFormat::new::(RequestedFormatType::None); Device::new(CameraIndex::Index(0), any) .and_then(|mut camera| camera.compatible_camera_formats()) diff --git a/harness/imports.sh b/harness/imports.sh new file mode 100755 index 0000000..2b3c25e --- /dev/null +++ b/harness/imports.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail +exe="${1:-$(dirname "$0")/../target/windows/yumush.exe}" +core="advapi32 api-ms-win-core-synch-l1-2-0 api-ms-win-core-winrt-error-l1-1-0 api-ms-win-core-winrt-l1-1-0 +api-ms-win-shcore-scaling-l1-1-1 bcrypt bcryptprimitives combase comctl32 coremessaging crypt32 d3d11 dcomp +dwmapi dwrite dxgi gdi32 gdiplus icuuc imm32 kernel32 mmdevapi msimg32 ntdll ole32 oleaut32 pdh powrprof +propsys psapi shell32 uiautomationcore user32 userenv winmm ws2_32" +extra=$(objdump -p "$exe" | sed -n 's/.*DLL Name: //p' | tr A-Z a-z | sed 's/\.dll$//' | sort -u | + grep -vxF -f <(tr ' ' '\n' <<<"$core" | grep .) || true) +[ -z "$extra" ] && { echo "imports ok"; exit 0; } +echo "not on every Windows, delay-load and guard it: $extra" +exit 1