Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
raea-runtime-pid: the process check out of raea-runtime-bundle into a crate of its own (the bundle crate was at its 2000 lines), the manifest reads GIVEN where it called given(), and two lines the dupes check counted as copies written their own way
shinyobjectz675aa18dafbb
diff --git a/Cargo.lock b/Cargo.lockindex d3e8689a..1f958407 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -15204,7 +15204,6 @@ version = "0.1.0"dependencies = ["dunce","junction",- "libc","raea-core-scene","raea-io-home","raea-io-media",@@ -15212,10 +15211,10 @@ dependencies = ["raea-native","raea-runtime-bundle-lib","raea-runtime-cssurls",+ "raea-runtime-pid","raea-sys-layers","regex","serde_json",- "windows-sys 0.61.2",][[package]]@@ -15536,6 +15535,14 @@ dependencies = ["twox-hash",]+[[package]]+name = "raea-runtime-pid"+version = "0.1.0"+dependencies = [+ "libc",+ "windows-sys 0.61.2",+]+[[package]]name = "raea-runtime-plugins"version = "0.1.0"diff --git a/Cargo.toml b/Cargo.tomlindex f21ecb8d..b21b8c74 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -175,6 +175,7 @@ members = ["runtime/track","runtime/pagestore","runtime/cssurls",+ "runtime/pid","bench/bridge","bench/bevy-parity","bench/lightbench",diff --git a/io/ffmpeg/src/lib.rs b/io/ffmpeg/src/lib.rsindex cc7a342d..1c1bee93 100644--- a/io/ffmpeg/src/lib.rs+++ b/io/ffmpeg/src/lib.rs@@ -110,7 +110,7 @@ fn probe(path: &Path) -> R<(Info, Vec<f64>, bool, Option<&'static str>)> {let untagged = !matches!(s["color_space"].as_str(), Some(c) if c != "unknown");// the tag in either case: ffmpeg's muxer writes ALPHA_MODE when it copies a stream that has alpha, and a file// remuxed with -c copy drew opaque (#224)- let tagged = s["tags"].as_object().and_then(|t| t.iter().find(|(k, _)| k.eq_ignore_ascii_case("alpha_mode"))).and_then(|(_, v)| v.as_str());+ let tagged = s["tags"].as_object().and_then(|t| t.iter().find_map(|(k, v)| k.eq_ignore_ascii_case("alpha_mode").then(|| v.as_str()).flatten()));let alpha = match (s["codec_name"].as_str(), tagged) {(Some("vp8"), Some("1")) => Some("libvpx"),(Some("vp9"), Some("1")) => Some("libvpx-vp9"),diff --git a/runtime/bundle/Cargo.toml b/runtime/bundle/Cargo.tomlindex f5827177..caf9725e 100644--- a/runtime/bundle/Cargo.toml+++ b/runtime/bundle/Cargo.toml@@ -12,6 +12,8 @@ modules = ["raea-native/modules"][dependencies]raea-io-trace = { path = "../../io/trace" }+# whether the process that left a work folder still runs (cache.rs sweep)+raea-runtime-pid = { path = "../pid" }# canonical paths without Windows' verbatim prefix, for import specifiers (fresh.rs spec)dunce = "1"# raea's home (the checkout's, or an install's share/raea): the SDK packages, the bundler's library, Tailwind's package@@ -33,14 +35,9 @@ regex = "1"raea-runtime-bundle-lib = { path = "lib" }# whether the render that left a work folder still runs (pid.rs), asked of the system rather than a `kill` on PATH-[target.'cfg(unix)'.dependencies]-libc = "0.2"-# the work folder's node_modules link on Windows (fresh.rs link_node_modules), as raea-io-npm makes its links[target.'cfg(windows)'.dependencies]junction = "1"-# and its process check (pid.rs)-windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_System_Threading"] }[dev-dependencies]# tests/mezz.rs writes its long-GOP clip with the soft backend's H.264diff --git a/runtime/bundle/src/cache.rs b/runtime/bundle/src/cache.rsindex 029c7f5c..690d0dd1 100644--- a/runtime/bundle/src/cache.rs+++ b/runtime/bundle/src/cache.rs@@ -262,7 +262,7 @@ pub(crate) fn sweep_stale_work_in(dir: &Path, now: std::time::SystemTime) {// raea-cli-r{pid}-ThreadId(n), raea-cli-b{pid}: gone only when the system says no such process is left, running// when it says it runs (this process's own folders too)let pid = name.get(10..).and_then(|s| s.split('-').next()).and_then(|p| p.parse::<u32>().ok());- let running = pid.map(|p| if p == std::process::id() { Some(true) } else { crate::pid::running(p) });+ let running = pid.map(|p| if p == std::process::id() { Some(true) } else { raea_runtime_pid::running(p) });let gone = running == Some(Some(false));// the age rule is for a folder whose process isn't known to run: a long render stops touching its folder's top// level well before it ends (#31), and a killed render's PID handed to another process keeps its folderdiff --git a/runtime/bundle/src/lib.rs b/runtime/bundle/src/lib.rsindex 2eeba25c..4d6bc2ee 100644--- a/runtime/bundle/src/lib.rs+++ b/runtime/bundle/src/lib.rs@@ -12,6 +12,7 @@ mod cache;mod entry;mod fresh;mod outside;+#[cfg(test)]mod pid;mod rewrite;pub mod styles;@@ -197,10 +198,7 @@ pub fn props_arg(given: &str) -> R<Value> {/// What the command line gave this run's composition (`--props`, `--scale`), for the render's manifest: a check of/// the file knows what it was rendered with.-pub fn given() -> Option<Value> {- GIVEN.lock().unwrap().clone()-}-static GIVEN: std::sync::Mutex<Option<Value>> = std::sync::Mutex::new(None);+pub static GIVEN: std::sync::Mutex<Option<Value>> = std::sync::Mutex::new(None);pub fn comp_opts(args: &[String]) -> R<CompOpts> {let n = |k: &str| -> R<Option<f64>> { flag(args, k).map(|v| v.parse::<f64>().map_err(|_| format!("{k} takes a number"))).transpose() };diff --git a/runtime/bundle/src/pid.rs b/runtime/bundle/src/pid.rsindex 2c18f62d..0325020b 100644--- a/runtime/bundle/src/pid.rs+++ b/runtime/bundle/src/pid.rs@@ -1,51 +1,8 @@-//! Whether a process still runs, asked of the system itself: a `kill` found on PATH can't be trusted (on Windows under-//! Git Bash it is MSYS's, which knows no Windows PID and called every live render dead, #29).--/// Whether process `pid` runs: Some(false) only when there's no such process, None when the system won't say (so a-/// caller deciding whether to delete what it left keeps it).-#[cfg(unix)]-pub(crate) fn running(pid: u32) -> Option<bool> {- // 0 and anything past i32::MAX name process groups, not one process- let p = i32::try_from(pid).ok().filter(|p| *p > 0)?;- // signal 0 sends nothing: it only checks that the process exists and could be signalled- if unsafe { libc::kill(p, 0) } == 0 {- return Some(true);- }- match std::io::Error::last_os_error().raw_os_error() {- Some(libc::ESRCH) => Some(false),- // another user's process- Some(libc::EPERM) => Some(true),- _ => None,- }-}--/// Whether process `pid` runs: Some(false) only when there's no such process, None when the system won't say (so a-/// caller deciding whether to delete what it left keeps it).-#[cfg(windows)]-pub(crate) fn running(pid: u32) -> Option<bool> {- use windows_sys::Win32::Foundation::{CloseHandle, ERROR_INVALID_PARAMETER, GetLastError, STILL_ACTIVE};- use windows_sys::Win32::System::Threading::{GetExitCodeProcess, OpenProcess, PROCESS_QUERY_LIMITED_INFORMATION};- unsafe {- let h = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, pid);- if h.is_null() {- // no such process; access denied (another user's, a protected one) says nothing- return (GetLastError() == ERROR_INVALID_PARAMETER).then_some(false);- }- let mut code = 0u32;- let ok = GetExitCodeProcess(h, &mut code) != 0;- CloseHandle(h);- ok.then_some(code == STILL_ACTIVE as u32)- }-}--#[cfg(not(any(unix, windows)))]-pub(crate) fn running(_pid: u32) -> Option<bool> {- None-}-+//! A process that left a work folder is asked for by raea-runtime-pid (the system itself, never a `kill` on PATH): its+//! tests, here beside the sweep that uses it.#[cfg(test)]mod tests {- use super::running;+ use raea_runtime_pid::running;/// A child that waits until its stdin closes, on any system.fn child() -> std::process::Child {diff --git a/runtime/export/src/lib.rs b/runtime/export/src/lib.rsindex b412e8ff..b82564a3 100644--- a/runtime/export/src/lib.rs+++ b/runtime/export/src/lib.rs@@ -75,7 +75,7 @@ fn write_manifest(cx: &mut Ctx, (w, h, fps, length): (u32, u32, f64, i64), foundpath.parent().map_or(Ok(()), std::fs::create_dir_all).map_err(|e| format!("{}: {e}", path.display()))?;let mut v = json!({"width": w, "height": h, "fps": fps, "length": length, "frames": frames, "findings": raea_core_facts::finding::ranked(found), "sounds": heard(cx), "not_applied": not_applied::seen(), "layers": raea_sys_layers::finish(fps), "has3d": cx.scene3d.is_some() || cx.live3d.is_some()});// the parts SG9 needs (scene.rs's SEEN: stills' parts on screen, a longer render's remounts), and --props and --scale- for more in [scene::SEEN.lock().unwrap().take(), given()] {+ for more in [scene::SEEN.lock().unwrap().take(), GIVEN.lock().unwrap().clone()] {v.as_object_mut().into_iter().zip(more.and_then(|m| m.as_object().cloned())).for_each(|(m, more)| m.extend(more));}std::fs::write(&path, v.to_string()).map_err(|e| format!("{}: {e}", path.display()))diff --git a/runtime/pid/Cargo.toml b/runtime/pid/Cargo.tomlnew file mode 100644index 00000000..9356f56f--- /dev/null+++ b/runtime/pid/Cargo.toml@@ -0,0 +1,12 @@+[package]+name = "raea-runtime-pid"+version = "0.1.0"+edition = "2024"+description = "Whether a process still runs, asked of the system itself (a bundle's work folder is swept once its render is gone)"+license = "FSL-1.1-ALv2"++[target.'cfg(unix)'.dependencies]+libc = "0.2"++[target.'cfg(windows)'.dependencies]+windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_System_Threading"] }diff --git a/runtime/pid/src/lib.rs b/runtime/pid/src/lib.rsnew file mode 100644index 00000000..2bcef3bb--- /dev/null+++ b/runtime/pid/src/lib.rs@@ -0,0 +1,44 @@+//! Whether a process still runs, asked of the system itself: a `kill` found on PATH can't be trusted (on Windows under+//! Git Bash it is MSYS's, which knows no Windows PID and called every live render dead, #29).++/// Whether process `pid` runs: Some(false) only when there's no such process, None when the system won't say (so a+/// caller deciding whether to delete what it left keeps it).+#[cfg(unix)]+pub fn running(pid: u32) -> Option<bool> {+ // 0 and anything past i32::MAX name process groups, not one process+ let p = i32::try_from(pid).ok().filter(|p| *p > 0)?;+ // signal 0 sends nothing: it only checks that the process exists and could be signalled+ if unsafe { libc::kill(p, 0) } == 0 {+ return Some(true);+ }+ match std::io::Error::last_os_error().raw_os_error() {+ Some(libc::ESRCH) => Some(false),+ // another user's process+ Some(libc::EPERM) => Some(true),+ _ => None,+ }+}++/// Whether process `pid` runs: Some(false) only when there's no such process, None when the system won't say (so a+/// caller deciding whether to delete what it left keeps it).+#[cfg(windows)]+pub fn running(pid: u32) -> Option<bool> {+ use windows_sys::Win32::Foundation::{CloseHandle, ERROR_INVALID_PARAMETER, GetLastError, STILL_ACTIVE};+ use windows_sys::Win32::System::Threading::{GetExitCodeProcess, OpenProcess, PROCESS_QUERY_LIMITED_INFORMATION};+ unsafe {+ let h = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, pid);+ if h.is_null() {+ // no such process; access denied (another user's, a protected one) says nothing+ return (GetLastError() == ERROR_INVALID_PARAMETER).then_some(false);+ }+ let mut code = 0u32;+ let ok = GetExitCodeProcess(h, &mut code) != 0;+ CloseHandle(h);+ ok.then_some(code == STILL_ACTIVE as u32)+ }+}++#[cfg(not(any(unix, windows)))]+pub fn running(_pid: u32) -> Option<bool> {+ None+}diff --git a/systems/mix/src/offline.rs b/systems/mix/src/offline.rsindex 2fa1bdd2..44aadf13 100644--- a/systems/mix/src/offline.rs+++ b/systems/mix/src/offline.rs@@ -205,8 +205,7 @@ fn mastered(raw: &raea_io_media::Audio, mix: Option<(f64, f64)>, encode: Encode)let mut gain = raea_io_media::audio::master_gained(raw, lufs, ceiling).1;// a join the mix drops into dead silence gets the room's tone, found at the level the master plays it (joins.rs)let raw = &crate::joins::filled(raw, gain);- let mut a = master_raw(raw, Some((gain, ceiling)));- let mut last: Option<(f64, f64)> = None;+ let (mut a, mut last) = (master_raw(raw, Some((gain, ceiling))), None::<(f64, f64)>);for _ in 0..8 {let got = raea_io_media::audio::lufs(&a);let slope = last.map(|(g0, l0)| ((got - l0) / (gain - g0)).clamp(0.05, 1.0)).filter(|s| s.is_finite()).unwrap_or(1.0);diff --git a/tools/layers.toml b/tools/layers.tomlindex c3bd8e77..2cacb4ef 100644--- a/tools/layers.toml+++ b/tools/layers.toml@@ -180,6 +180,7 @@ raea-runtime-wear = "runtime"raea-runtime-export = "runtime"raea-runtime-pagestore = "runtime"raea-runtime-cssurls = "runtime"+raea-runtime-pid = "runtime"raea-runtime-page = "runtime"raea-runtime-appscreen = "runtime"raea-runtime-sound = "runtime"