Skip to content

Commit

Permalink
Use gtk-rs's new blueprint support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RealKC committed Jul 19, 2023
1 parent 260a971 commit a40a332
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 68 deletions.
25 changes: 12 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
44 changes: 6 additions & 38 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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",
);
}
23 changes: 9 additions & 14 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
)

Expand Down
1 change: 0 additions & 1 deletion resources/resources.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
<file>editor/tool-colourpicker.png</file>

<!-- UI files generated from blueprints in build.rs -->
<file preprocess="xml-stripblanks" alias="ui/textdialog.ui">editor/textdialog.ui</file>
</gresource>
</gresources>
2 changes: 1 addition & 1 deletion src/editor/textdialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EditorWindow>,
Expand Down

0 comments on commit a40a332

Please sign in to comment.