From 5b2edc73ec7982235f32dd1dfdf1e683d65302d1 Mon Sep 17 00:00:00 2001 From: Christopher Davis Date: Mon, 4 Mar 2019 01:24:08 -0500 Subject: [PATCH] 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!. Closes https://gitlab.gnome.org/World/podcasts/issues/55 --- .gitignore | 1 + .gitlab-ci.yml | 3 --- meson.build | 1 + podcasts-gtk/Cargo.toml | 1 - podcasts-gtk/build.rs | 14 -------------- podcasts-gtk/resources/meson.build | 7 +++++++ podcasts-gtk/src/meson.build | 17 +++++++++++++++++ ...static_resource.rs => static_resource.rs.in} | 2 +- scripts/test.sh | 3 --- 9 files changed, 27 insertions(+), 22 deletions(-) delete mode 100644 podcasts-gtk/build.rs rename podcasts-gtk/src/{static_resource.rs => static_resource.rs.in} (94%) diff --git a/.gitignore b/.gitignore index f5cb1ce..468395b 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ repo/ # Files configured by meson podcasts-gtk/src/config.rs +podcasts-gtk/src/static_resource.rs diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 93fd27d..0bd47d3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,9 +17,6 @@ flatpak: script: - flatpak-builder --stop-at=${FLATPAK_MODULE} app ${MANIFEST_PATH} - # https://gitlab.gnome.org/World/podcasts/issues/55 - # Force regeneration of gresources regardless of artifacts chage - - flatpak-builder --run app ${MANIFEST_PATH} glib-compile-resources --sourcedir=podcasts-gtk/resources/ podcasts-gtk/resources/resources.xml # Build the flatpak repo - flatpak-builder --run app ${MANIFEST_PATH} meson --prefix=/app ${CONFIGURE_ARGS} _build diff --git a/meson.build b/meson.build index 89a111c..0e2c2f8 100644 --- a/meson.build +++ b/meson.build @@ -46,6 +46,7 @@ endif application_id = 'org.gnome.Podcasts@0@'.format(profile) i18n = import('i18n') +gnome = import('gnome') subdir('podcasts-gtk/po') podir = join_paths (meson.source_root (), 'podcasts-gtk', 'po') diff --git a/podcasts-gtk/Cargo.toml b/podcasts-gtk/Cargo.toml index 787930b..1ec78f0 100644 --- a/podcasts-gtk/Cargo.toml +++ b/podcasts-gtk/Cargo.toml @@ -1,6 +1,5 @@ [package] authors = ["Jordan Petridis "] -build = "build.rs" name = "podcasts-gtk" version = "0.1.0" diff --git a/podcasts-gtk/build.rs b/podcasts-gtk/build.rs deleted file mode 100644 index c8279e6..0000000 --- a/podcasts-gtk/build.rs +++ /dev/null @@ -1,14 +0,0 @@ -use std::process::Command; - -fn main() { - // Rerun the build script when files in the resources folder are changed. - println!("cargo:rerun-if-changed=resources"); - println!("cargo:rerun-if-changed=resources/*"); - - let out = Command::new("glib-compile-resources") - .args(&["--generate", "resources.xml"]) - .current_dir("resources") - .status() - .expect("failed to generate resources"); - assert!(out.success()); -} diff --git a/podcasts-gtk/resources/meson.build b/podcasts-gtk/resources/meson.build index ee91f08..c46bd00 100644 --- a/podcasts-gtk/resources/meson.build +++ b/podcasts-gtk/resources/meson.build @@ -58,4 +58,11 @@ configure_file( install_dir: join_paths(datadir,'dbus-1', 'services') ) +podcasts_resources = gnome.compile_resources( + 'resources', + 'resources.xml', + gresource_bundle: true, + source_dir: meson.current_build_dir() +) + meson.add_install_script('../../scripts/compile-gschema.py') diff --git a/podcasts-gtk/src/meson.build b/podcasts-gtk/src/meson.build index 55a9607..75f0084 100644 --- a/podcasts-gtk/src/meson.build +++ b/podcasts-gtk/src/meson.build @@ -15,12 +15,29 @@ run_command( check: true ) +# include_bytes! only takes a string literal +resource_conf = configuration_data() +resource_conf.set_quoted('RESOURCEFILE', podcasts_resources.full_path()) +resource_rs = configure_file( + input: 'static_resource.rs.in', + output: 'static_resource.rs', + configuration: resource_conf +) + +run_command( + 'cp', + resource_rs, + meson.current_source_dir(), + check: true +) + cargo_release = custom_target('cargo-build', build_always_stale: true, output: ['gnome-podcasts'], install: true, install_dir: podcasts_bindir, console: true, + depends: podcasts_resources, command: [cargo_script, '@SOURCE_ROOT@', '@OUTPUT@', diff --git a/podcasts-gtk/src/static_resource.rs b/podcasts-gtk/src/static_resource.rs.in similarity index 94% rename from podcasts-gtk/src/static_resource.rs rename to podcasts-gtk/src/static_resource.rs.in index c7fad23..a6c303e 100644 --- a/podcasts-gtk/src/static_resource.rs +++ b/podcasts-gtk/src/static_resource.rs.in @@ -23,7 +23,7 @@ use glib::Bytes; pub(crate) fn init() -> Result<(), Error> { // load the gresource binary at build time and include/link it into the final // binary. - let res_bytes = include_bytes!("../resources/resources.gresource"); + let res_bytes = include_bytes!(@RESOURCEFILE@); // Create Resource it will live as long the value lives. let gbytes = Bytes::from_static(res_bytes.as_ref()); diff --git a/scripts/test.sh b/scripts/test.sh index 5d4a9bd..9a7208e 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -12,9 +12,6 @@ export CONFIGURE_ARGS="-Dprofile=development" # export RUNTIME_REPO="https://sdk.gnome.org/gnome-nightly.flatpakrepo" flatpak-builder --stop-at=${FLATPAK_MODULE} --force-clean app ${MANIFEST_PATH} -# https://gitlab.gnome.org/World/podcasts/issues/55 -# Force regeneration of gresources regardless of artifacts chage -flatpak-builder --run app ${MANIFEST_PATH} glib-compile-resources --sourcedir=podcasts-gtk/resources/ podcasts-gtk/resources/resources.xml # Build the flatpak repo flatpak-builder --run app ${MANIFEST_PATH} meson --prefix=/app ${CONFIGURE_ARGS} build