[fractal] build: Build resources with meson instead of build.rs



commit 7b1734af9548adff2698792721af184601eb43de
Author: Christopher Davis <brainblasted disroot org>
Date:   Mon Apr 22 01:19:17 2019 -0400

    build: Build resources with meson instead of build.rs
    
    Allows us to get rid of build.rs, which was only used to
    compile resources. static_resource.rs is now created by
    meson, and the meson path is used for include_bytes!.

 .gitignore                                              |  1 +
 .gitlab-ci.yml                                          |  4 ----
 fractal-gtk/Cargo.toml                                  |  1 -
 fractal-gtk/build.rs                                    | 11 -----------
 fractal-gtk/res/meson.build                             |  7 +++++++
 fractal-gtk/src/meson.build                             | 17 +++++++++++++++++
 .../src/{static_resources.rs => static_resources.rs.in} |  3 ++-
 meson.build                                             |  1 +
 8 files changed, 28 insertions(+), 17 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index efa4603b..7f5db05a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@ vendor
 
 # Files configured by meson
 fractal-gtk/src/config.rs
+fractal-gtk/src/static_resources.rs
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 07c9cd91..72e5cfea 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -33,8 +33,6 @@ flatpak:
     stage: "test"
     script:
         - flatpak-builder --stop-at=${FLATPAK_MODULE} --force-clean app ${MANIFEST_PATH}
-        # Force regeneration of gresources regardless of artifacts chage
-        - flatpak-builder --run app ${MANIFEST_PATH} glib-compile-resources --sourcedir=fractal-gtk/res/ 
fractal-gtk/res/resources.xml
 
         # Build the flatpak repo
         - flatpak-builder --run app ${MANIFEST_PATH} meson --prefix=/app -Dprofile=development _build
@@ -97,8 +95,6 @@ pages:
     stage: deploy
     script:
         - flatpak-builder --stop-at=${FLATPAK_MODULE} --force-clean app ${MANIFEST_PATH}
-        # Force regeneration of gresources regardless of artifacts chage
-        - flatpak-builder --run app ${MANIFEST_PATH} glib-compile-resources --sourcedir=fractal-gtk/res/ 
fractal-gtk/res/resources.xml
         - flatpak-builder --run app ${MANIFEST_PATH} meson _build
 
         - |
diff --git a/fractal-gtk/Cargo.toml b/fractal-gtk/Cargo.toml
index 426dec12..2fec22a8 100644
--- a/fractal-gtk/Cargo.toml
+++ b/fractal-gtk/Cargo.toml
@@ -1,6 +1,5 @@
 [package]
 authors = ["Daniel Garcia <danigm wadobo com>"]
-build = "build.rs"
 name = "fractal-gtk"
 version = "4.0.0"
 workspace = "../"
diff --git a/fractal-gtk/res/meson.build b/fractal-gtk/res/meson.build
index bab3bab8..df07d3d8 100644
--- a/fractal-gtk/res/meson.build
+++ b/fractal-gtk/res/meson.build
@@ -49,3 +49,10 @@ if appstream_util.found()
   )
 endif
 install_data('org.gnome.Fractal.gschema.xml', install_dir: join_paths(get_option('datadir'), 'glib-2.0', 
'schemas'))
+
+fractal_resources = gnome.compile_resources(
+  'resources',
+  'resources.xml',
+  gresource_bundle: true,
+  source_dir: meson.current_build_dir()
+)
diff --git a/fractal-gtk/src/meson.build b/fractal-gtk/src/meson.build
index f407fe01..2e3a82bf 100644
--- a/fractal-gtk/src/meson.build
+++ b/fractal-gtk/src/meson.build
@@ -16,12 +16,29 @@ run_command(
   check: true
 )
 
+# include_bytes! only takes a string literal
+resource_conf = configuration_data()
+resource_conf.set_quoted('RESOURCEFILE', fractal_resources.full_path())
+resource_rs = configure_file(
+  input: 'static_resources.rs.in',
+  output: 'static_resources.rs',
+  configuration: resource_conf
+)
+
+run_command(
+  'cp',
+  resource_rs,
+  meson.current_source_dir(),
+  check: true
+)
+
 c = run_command(grabber)
 sources = c.stdout().strip().split('\n')
 
 cargo_release = custom_target('cargo-build',
                         build_by_default: true,
                         input: sources,
+                        depends: fractal_resources,
                         output: ['fractal'],
                         install: true,
                         install_dir: fractal_bindir,
diff --git a/fractal-gtk/src/static_resources.rs b/fractal-gtk/src/static_resources.rs.in
similarity index 88%
rename from fractal-gtk/src/static_resources.rs
rename to fractal-gtk/src/static_resources.rs.in
index 700e2667..17bbb4a6 100644
--- a/fractal-gtk/src/static_resources.rs
+++ b/fractal-gtk/src/static_resources.rs.in
@@ -3,7 +3,8 @@ use glib::Bytes;
 
 pub fn init() -> Result<(), Error> {
     // load the gresource binary at build time and include/link it into the final binary.
-    let res_bytes = include_bytes!("../res/resources.gresource");
+    let res_bytes =
+        include_bytes!(@RESOURCEFILE@);
 
     // Create Resource, it will live as long the value lives.
     let gbytes = Bytes::from(res_bytes.as_ref());
diff --git a/meson.build b/meson.build
index 7eba5d80..ebd27089 100644
--- a/meson.build
+++ b/meson.build
@@ -60,6 +60,7 @@ fractal_localedir = join_paths(fractal_prefix, get_option('localedir'))
 datadir = get_option('datadir')
 
 i18n = import('i18n')
+gnome = import('gnome')
 
 podir = join_paths (meson.source_root (), 'fractal-gtk', 'po')
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]