[gtk] widget-factory: Speed up build
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk] widget-factory: Speed up build
- Date: Fri, 1 Oct 2021 03:30:57 +0000 (UTC)
commit d7e117f52b14f4571a3e6aaa5405b61e3efc6161
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Sep 30 22:41:36 2021 -0400
widget-factory: Speed up build
Avoid serializing the gresource blob into a C string
and running gcc over it. Instead, use ld to put it
directly into an .o file and add it to the build.
The build system machinations here were copied from
gobject/tests/meson.build, and should ideally be part
of the meson gnome module.
demos/widget-factory/meson.build | 67 +++++++++++++++++++++++++++++++++++++---
1 file changed, 63 insertions(+), 4 deletions(-)
---
diff --git a/demos/widget-factory/meson.build b/demos/widget-factory/meson.build
index 6b09db3e2b..2763111570 100644
--- a/demos/widget-factory/meson.build
+++ b/demos/widget-factory/meson.build
@@ -1,9 +1,68 @@
# demos/widget-factory
-widgetfactory_resources = gnome.compile_resources('widgetfactory_resources',
- 'widget-factory.gresource.xml',
- source_dir: '.',
-)
+objcopy_supports_add_symbol = false
+objcopy = find_program('objcopy', required : false)
+if objcopy.found()
+ objcopy_supports_add_symbol = run_command(objcopy, '--help').stdout().contains('--add-symbol')
+endif
+
+ld = find_program('ld', required : false)
+
+if build_machine.system() == 'linux' and objcopy.found() and objcopy_supports_add_symbol and ld.found()
+ glib_compile_resources = find_program('glib-compile-resources')
+
+ # Create the resource blob
+ widgetfactory_gresource = custom_target('widgetfactory.gresource',
+ input : 'widget-factory.gresource.xml',
+ output : 'widgetfactory.gresource',
+ command : [glib_compile_resources,
+ '--target=@OUTPUT@',
+ '--sourcedir=' + meson.current_source_dir(),
+ '--sourcedir=' + meson.current_build_dir(),
+ '@INPUT@'])
+
+ # Create resource data file
+ widgetfactory_resources_c = custom_target('widgetfactory_resources.c',
+ input : 'widget-factory.gresource.xml',
+ output : 'widgetfactory_resources.c',
+ command : [glib_compile_resources,
+ '--target=@OUTPUT@',
+ '--sourcedir=' + meson.current_source_dir(),
+ '--sourcedir=' + meson.current_build_dir(),
+ '--generate-source',
+ '--external-data',
+ '--c-name', '_g_binary_widgetfactory',
+ '@INPUT@'])
+
+ # Create object file containing resource data
+ widgetfactory_resources_binary = custom_target('widgetfactory_resources.o',
+ input : widgetfactory_gresource,
+ output : 'widgetfactory_resources.o',
+ command : [ld,
+ '-r',
+ '-b','binary',
+ '@INPUT@',
+ '-o','@OUTPUT@'])
+
+ # Rename symbol to match the one in the C file
+ widgetfactory_resources_o = custom_target('widgetfactory_resources2.o',
+ input : widgetfactory_resources_binary,
+ output : 'widgetfactory_resources2.o',
+ command : [objcopy,
+ '--add-symbol','_g_binary_widgetfactory_resource_data=.data:0',
+ '@INPUT@',
+ '@OUTPUT@'])
+
+ widgetfactory_resources = [
+ widgetfactory_resources_c,
+ widgetfactory_resources_o,
+ ]
+else
+ widgetfactory_resources = gnome.compile_resources('widgetfactory_resources',
+ 'widget-factory.gresource.xml',
+ source_dir: '.',
+ )
+endif
executable('gtk4-widget-factory',
sources: ['widget-factory.c', 'gtkloader.c', widgetfactory_resources],
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]