From a40a33208590061ee332cbbbfb62e7796c47f203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C8=9Bca=20Dumitru?= Date: Wed, 19 Jul 2023 00:20:24 +0300 Subject: [PATCH] Use gtk-rs's new blueprint support This removes some build code but we still need the meson stuff in order to get the blueprint compiler in CI. There is now some new meson code that adds the path to the blueprint compiler to $PATH in order for gtk4_macros to detect it and be able to use it. --- Cargo.lock | 25 +++++++++--------- Cargo.toml | 2 +- build.rs | 44 +++++-------------------------- meson.build | 23 +++++++--------- resources/resources.gresource.xml | 1 - src/editor/textdialog.rs | 2 +- 6 files changed, 29 insertions(+), 68 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 161c095..b194bb2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -826,9 +826,9 @@ dependencies = [ [[package]] name = "gtk4" -version = "0.6.0" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f61aa16bbd4554552645227d4249b58fd730b27985a7e0283fd0a2d479e954a8" +checksum = "b28a32a04cd75cef14a0983f8b0c669e0fe152a0a7725accdeb594e2c764c88b" dependencies = [ "bitflags", "cairo-rs", @@ -849,9 +849,9 @@ dependencies = [ [[package]] name = "gtk4-macros" -version = "0.6.0" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db4676c4f90d8b010e88cb4558f61f47d76d6f6b8e6f6b89e62640f443907f61" +checksum = "6a4d6b61570f76d3ee542d984da443b1cd69b6105264c61afec3abed08c2500f" dependencies = [ "anyhow", "proc-macro-crate", @@ -1369,21 +1369,21 @@ dependencies = [ [[package]] name = "quick-xml" -version = "0.22.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8533f14c8382aaad0d592c812ac3b826162128b65662331e1127b45c3d18536b" +checksum = "58e21a144a0ffb5fad7b464babcdab934a325ad69b7c0373bcfef5cbd9799ca9" dependencies = [ "memchr", + "serde", ] [[package]] name = "quick-xml" -version = "0.25.0" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58e21a144a0ffb5fad7b464babcdab934a325ad69b7c0373bcfef5cbd9799ca9" +checksum = "0ce5e73202a820a31f8a0ee32ada5e21029c81fd9e3ebf668a40832e4219d9d1" dependencies = [ "memchr", - "serde", ] [[package]] @@ -2009,13 +2009,12 @@ checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" [[package]] name = "xcb" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0faeb4d7e2d54fff4a0584f61297e86b106914af2029778de7b427f72564d6c5" +version = "1.2.1" +source = "git+https://github.com/rust-x-bindings/rust-xcb/#5657d694e72c9c69049b5452d9a248ddd949f246" dependencies = [ "bitflags", "libc", - "quick-xml 0.22.0", + "quick-xml 0.28.2", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 27eff77..927c2f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ members = ["kcshot-data", "kcshot-screenshot"] [workspace.dependencies] cairo = { package = "cairo-rs", version = "0.17.0", features = ["png"] } -gtk4 = "0.6.0" +gtk4 = { version = "0.6.6", features = ["blueprint"] } once_cell = "1.13.1" tokio = { version = "1.25.0", features = ["rt-multi-thread"] } tracing = "0.1.23" diff --git a/build.rs b/build.rs index 7a2cbeb..3282438 100644 --- a/build.rs +++ b/build.rs @@ -1,46 +1,14 @@ -use std::{env, process::Command}; - fn main() { // See: https://docs.rs/diesel_migrations/2.0.0-rc.1/diesel_migrations/macro.embed_migrations.html#automatic-rebuilds println!("cargo:rerun-if-changed=migrations/"); - if std::option_env!("KCSHOT_LINTING").is_none() { - let blueprint_dir = env::var("OUT_DIR").unwrap() + "/resources"; - compile_blueprints(&["src/editor/textdialog.blp"], &blueprint_dir); - glib_build_tools::compile_resources( - &[blueprint_dir.as_str(), "resources"], - "resources/resources.gresource.xml", - "compiled.gresource", - ); - } else { + if std::option_env!("KCSHOT_LINTING").is_some() { println!("cargo:rustc-cfg=kcshot_linting"); } -} - -fn compile_blueprints(blueprints: &[&str], target: &str) { - let blueprint_compiler = std::env::var("BLUEPRINT_COMPILER_PATH") - .unwrap_or_else(|_| "blueprint-compiler".to_owned()); - - let mut blueprint_compiler = Command::new(blueprint_compiler); - blueprint_compiler - .arg("batch-compile") - .arg(target) - .arg("src/"); - - for blueprint in blueprints { - println!("cargo:rerun-if-changed={blueprint}"); - blueprint_compiler.arg(blueprint); - } - let output = blueprint_compiler - .output() - .expect("Failed to execute blueprint-compiler"); - - if !output.status.success() { - panic!( - "blueprint-compiler returned {}, with stderr:\n{}", - output.status, - std::str::from_utf8(&output.stderr).unwrap() - ); - } + glib_build_tools::compile_resources( + &["resources"], + "resources/resources.gresource.xml", + "compiled.gresource", + ); } diff --git a/meson.build b/meson.build index 782d5a4..84f957b 100644 --- a/meson.build +++ b/meson.build @@ -28,12 +28,16 @@ else message('Building in debug mode') endif -cargo_env = ['CARGO_HOME=' + meson.project_build_root() / 'cargo-home'] - message( - 'blueprint-compiler is: ' / find_program('blueprint-compiler').full_path(), + 'blueprint-compiler is: ' + find_program('blueprint-compiler').full_path(), ) +fs = import('fs') +env = environment() +env.append('PATH', fs.parent(find_program('blueprint-compiler').full_path())) +env.set('CARGO_HOME', meson.project_build_root() / 'cargo-home') +meson.add_devenv(env) + cargo_build = custom_target( 'cargo-build', build_by_default: true, @@ -42,12 +46,7 @@ cargo_build = custom_target( console: true, install: true, install_dir: bindir, - env: { - 'BLUEPRINT_COMPILER_PATH': find_program( - 'blueprint-compiler', - ).full_path(), - 'CARGO_HOME': meson.project_build_root() / 'cargo-home', - }, + env: env, command: [ 'sh', '-c', cargo, @@ -67,11 +66,7 @@ test( 'test', '--manifest-path=@0@/Cargo.toml'.format(meson.global_source_root()), ], - env: { - 'BLUEPRINT_COMPILER_PATH': find_program( - 'blueprint-compiler', - ).full_path(), - }, + env: env, timeout: 3000, ) diff --git a/resources/resources.gresource.xml b/resources/resources.gresource.xml index 551dee1..d5861eb 100644 --- a/resources/resources.gresource.xml +++ b/resources/resources.gresource.xml @@ -16,6 +16,5 @@ editor/tool-colourpicker.png - editor/textdialog.ui diff --git a/src/editor/textdialog.rs b/src/editor/textdialog.rs index bda3065..573f35b 100644 --- a/src/editor/textdialog.rs +++ b/src/editor/textdialog.rs @@ -106,7 +106,7 @@ mod underlying { #[derive(Debug, Default, Properties, CompositeTemplate)] #[properties(wrapper_type = super::TextInput)] - #[template(resource = "/kc/kcshot/ui/textdialog.ui")] + #[template(file = "src/editor/textdialog.blp")] pub struct TextInput { #[property(get, set, construct_only)] editor: WeakRef,