From 630b44b352dd08eea48a3388d474bf708077c6a0 Mon Sep 17 00:00:00 2001 From: Erica Z Date: Tue, 5 Nov 2024 09:27:13 +0100 Subject: [PATCH] use cargo to compile blueprints --- build.rs | 42 +++++++++++++++++++++++++++++++++++++----- meson.build | 2 -- resources/meson.build | 24 ------------------------ src/mpv/wait_event.rs | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 31 deletions(-) delete mode 100644 resources/meson.build create mode 100644 src/mpv/wait_event.rs diff --git a/build.rs b/build.rs index 50803f2..24a5a6b 100644 --- a/build.rs +++ b/build.rs @@ -1,20 +1,52 @@ +use std::path::PathBuf; + fn main() { - let meson_build_root = - std::env::var("MESON_BUILD_ROOT").expect("build this through meson please!!"); + std::env::var("MESON_BUILD_ROOT").expect("build this through meson please!!"); + let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()); + + // compile blueprints + { + let mut command = std::process::Command::new("blueprint-compiler"); + + command + .arg("batch-compile") + .arg(out_path.join("resources")) + .arg("resources"); + + for source in [ + "play_queue.blp", + "play_queue_song.blp", + "playbar.blp", + "setup.blp", + "window.blp", + ] { + command.arg(format!("resources/{source}")); + } + + let output = command.output().unwrap(); + assert!( + output.status.success(), + "blueprint-compiler failed with exit status {} and stderr:\n{}", + output.status, + String::from_utf8_lossy(&output.stderr) + ); + + println!("cargo::rerun-if-changed=resources"); + } + glib_build_tools::compile_resources( - &["resources", &format!("{meson_build_root}/resources")], + &[PathBuf::from("resources"), out_path.join("resources")], "resources/audrey.gresource.xml", "audrey.gresource", ); // TODO: consider using meson to pass include paths - println!("cargo:rustc-link-lib=mpv"); + println!("cargo::rustc-link-lib=mpv"); let bindings = bindgen::Builder::default() .header("src/mpv/wrapper.h") .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) .generate() .expect("could not generate bindings for mpv"); - let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()); bindings .write_to_file(out_path.join("mpv_ffi.rs")) .expect("could not write mpv bindings"); diff --git a/meson.build b/meson.build index 70d92fd..432b7bc 100644 --- a/meson.build +++ b/meson.build @@ -38,7 +38,6 @@ add_project_arguments( subdir('data') subdir('po') -subdir('resources') subdir('src') if get_option('buildtype') == 'debug' @@ -60,7 +59,6 @@ custom_target( 'cargo-build', build_by_default: true, build_always_stale: true, - depends: blueprints, input: config_rs, console: true, # means nothing (always stale and uncopied), we can't cp since env: drops the /bin/sh wrapper diff --git a/resources/meson.build b/resources/meson.build deleted file mode 100644 index 57c1863..0000000 --- a/resources/meson.build +++ /dev/null @@ -1,24 +0,0 @@ -blueprints = custom_target( - 'blueprints', - input: files( - 'play_queue.blp', - 'play_queue_song.blp', - 'playbar.blp', - 'setup.blp', - 'window.blp', - ), - output: [ - 'play_queue.ui', - 'play_queue_song.ui', - 'playbar.ui', - 'setup.ui', - 'window.ui', - ], - command: [ - find_program('blueprint-compiler'), - 'batch-compile', - '@OUTDIR@', - '@CURRENT_SOURCE_DIR@', - '@INPUT@', - ], -) diff --git a/src/mpv/wait_event.rs b/src/mpv/wait_event.rs new file mode 100644 index 0000000..1f00309 --- /dev/null +++ b/src/mpv/wait_event.rs @@ -0,0 +1,34 @@ +use std::future::Future; +use std::task::Waker; + +pub struct WaitEvent<'a>(&'a Handle); + +impl Future for WaitEvent { + type Output = Event; + + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + // set wakeup before polling, don't miss any wakeup events + { + let waker = self.0.wakeup.lock(); + match waker.as_mut() { + None => *waker = cx.waker().clone(), + Some(waker) if !cx.waker().will_wake(waker) => *waker = cx.waker().clone, + _ => {} + } + } + + match self.0.wait_event_timeout(0.0) { + Some(event) => Poll::Ready(event), + None => Poll::Pending, + } + } +} + +pub(super) extern "C" fn callback(d: *mut c_void) { + let d = d as *const Mutex>; + let waker = unsafe { &*d }; + let waker = waker.lock().unwrap(); + if let Some(waker) = waker.take() { + waker.wake(); + } +}