Skip to content

Commit

Permalink
compose: Allow building without SVG support
Browse files Browse the repository at this point in the history
Apparently, bootstrapping a system with Rust in the toolchain is still a
major pain, and since rsvg is being rewritten in Rust, AppStream is
dragging it in if compose is enabled.
Of course, building AppStream without SVG support is not a great idea,
unless the only thing you are using appstream-compose for is non-GUI
applications.
As this is apparently the case for some Flatpak runtimes, we allow
disabling rsvg, but also complain very loudly as soon as we encounter an
SVG icon. This change should simplify early bootstrap and allow building
the complete appstream-compose at a later time in the build process.

Resolves: ximion#434
  • Loading branch information
ximion committed Sep 24, 2022
1 parent 27adc35 commit 95fb63f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
12 changes: 12 additions & 0 deletions compose/asc-canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@

#include <cairo.h>
#include <cairo-ft.h>
#ifdef HAVE_SVG_SUPPORT
#include <librsvg/rsvg.h>
#endif

#include "asc-font-private.h"
#include "asc-image.h"
Expand Down Expand Up @@ -152,6 +154,7 @@ asc_canvas_get_height (AscCanvas *canvas)
gboolean
asc_canvas_render_svg (AscCanvas *canvas, GInputStream *stream, GError **error)
{
#ifdef HAVE_SVG_SUPPORT
AscCanvasPrivate *priv = GET_PRIVATE (canvas);
RsvgHandle *handle = NULL;
gboolean ret = FALSE;
Expand Down Expand Up @@ -220,6 +223,15 @@ asc_canvas_render_svg (AscCanvas *canvas, GInputStream *stream, GError **error)
if (handle != NULL)
g_object_unref (handle);
return ret;
#else
g_warning ("Unable to render SVG graphic: AppStream built without SVG support.");
g_set_error_literal (error,
ASC_CANVAS_ERROR,
ASC_CANVAS_ERROR_UNSUPPORTED,
"AppStream was built without SVG support. This is an issue with your AppStream distribution. "
"Please rebuild AppStream with SVG support enabled or contact your distributor to enable it for you.");
return FALSE;
#endif
}

/**
Expand Down
8 changes: 5 additions & 3 deletions compose/asc-canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ G_DECLARE_FINAL_TYPE (AscCanvas, asc_canvas, ASC, CANVAS, GObject)

/**
* AscCanvasError:
* @ASC_CANVAS_ERROR_FAILED: Generic failure.
* @ASC_CANVAS_ERROR_DRAWING: Drawing operation failed.
* @ASC_CANVAS_ERROR_FONT: Issue with font or font selection.
* @ASC_CANVAS_ERROR_FAILED: Generic failure.
* @ASC_CANVAS_ERROR_DRAWING: Drawing operation failed.
* @ASC_CANVAS_ERROR_FONT: Issue with font or font selection.
* @ASC_CANVAS_ERROR_UNSUPPORTED: The requested action was not supported.
*
* A drawing error.
**/
typedef enum {
ASC_CANVAS_ERROR_FAILED,
ASC_CANVAS_ERROR_DRAWING,
ASC_CANVAS_ERROR_FONT,
ASC_CANVAS_ERROR_UNSUPPORTED,
/*< private >*/
ASC_CANVAS_ERROR_LAST
} AscCanvasError;
Expand Down
13 changes: 10 additions & 3 deletions compose/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,18 @@ asclib_res = glib.compile_resources (
)

# extra dependencies we need just for AppStream Compose
cairo_dep = dependency('cairo', version : '>= 1.12')
cairo_dep = dependency('cairo', version: '>= 1.12')
gdkpixbuf_dep = dependency('gdk-pixbuf-2.0')
rsvg_dep = dependency('librsvg-2.0', version : '>= 2.48')
freetype_dep = dependency('freetype2')
pango_dep = dependency('pango')
fontconfig_dep = dependency('fontconfig')
m_dep = cc.find_library('m', required: false)
if get_option ('svg-support')
rsvg_dep = dependency('librsvg-2.0', version: '>= 2.48')
else
rsvg_dep = dependency('', required: false)
warning('Building without SVG support. Therefore appstream-compose will be unable to render SVG icons.')
endif

appstream_compose_lib = library ('appstream-compose',
[ascompose_src,
Expand All @@ -76,6 +82,7 @@ appstream_compose_lib = library ('appstream-compose',
soversion: '0',
version: as_version,
dependencies: [appstream_dep,
m_dep,
gio_dep,
cairo_dep,
gdkpixbuf_dep,
Expand All @@ -101,7 +108,7 @@ pkgc.generate(
'gio-2.0',
'gobject-2.0',
'gdk-pixbuf-2.0',
'appstream']
'appstream'],
)

appstream_compose_dep = declare_dependency(
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ conf.set_quoted('SYSCONFDIR',
get_option('sysconfdir')))
conf.set('HAVE_APT_SUPPORT', get_option('apt-support'))
conf.set('HAVE_STEMMING', get_option('stemming'))
conf.set('HAVE_SVG_SUPPORT', get_option('svg-support'))

configure_file(output: 'config.h', configuration: conf)
root_inc_dir = include_directories ('.')
Expand Down
5 changes: 5 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ option('gir',
value : true,
description : 'Build introspection data'
)
option('svg-support',
type : 'boolean',
value : true,
description : 'SVG graphics support for compose (only disable this for bootstrapping purposes)'
)

option('docs',
type : 'boolean',
Expand Down

0 comments on commit 95fb63f

Please sign in to comment.