Skip to content

Commit

Permalink
fix: Update resource compilation and loading in meson and Rust build
Browse files Browse the repository at this point in the history
  • Loading branch information
silviot committed Dec 8, 2024
1 parent fd2680f commit d7fb88b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ fn main() -> glib::ExitCode {
textdomain(GETTEXT_PACKAGE).expect("Unable to switch to the text domain");

// Load compiled resources
let resource_bytes = std::fs::read(concat!(env!("CARGO_MANIFEST_DIR"), "/src/aardvark.gresource"))
.expect("Could not load resources");
let resource_path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("_build")
.join("src")
.join("aardvark.gresource");

let resource_bytes = std::fs::read(&resource_path)
.unwrap_or_else(|_| panic!("Could not load resources from {:?}", resource_path));
let resources = gio::Resource::from_data(&gio::glib::Bytes::from(&resource_bytes))
.expect("Could not load resources");
.expect("Could not create resource from data");
gio::resources_register(&resources);

// Create a new GtkApplication. The application manages our main loop,
Expand Down
18 changes: 12 additions & 6 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ gresource = gnome.compile_resources('aardvark',
install: false,
)

# Copy the compiled resource bundle to the source directory for Cargo build
run_command(
'cp',
meson.current_build_dir() / 'aardvark.gresource',
meson.current_source_dir() / 'aardvark.gresource',
check: true
# Ensure resource file is available for Cargo build
resource_file = custom_target('resource-file',
input: 'aardvark.gresource.xml',
output: 'aardvark.gresource',
command: [
find_program('glib-compile-resources'),
'--sourcedir=@CURRENT_SOURCE_DIR@',
'--target=@OUTPUT@',
'@INPUT@'
],
install: false,
build_by_default: true
)

conf = configuration_data()
Expand Down

0 comments on commit d7fb88b

Please sign in to comment.