Skip to content

Commit

Permalink
Allow building without zstd temporarily
Browse files Browse the repository at this point in the history
Eventually zstd will become the default compression method for cached
data, but for new we allow building without it as well.

Resolves: #561, #562
  • Loading branch information
ximion committed Dec 8, 2023
1 parent e747fb8 commit 25a7317
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
13 changes: 11 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ conf.set('HAVE_APT_SUPPORT', get_option('apt-support'))
conf.set('HAVE_STEMMING', get_option('stemming'))
conf.set('HAVE_SYSTEMD', get_option('systemd'))
conf.set('HAVE_SVG_SUPPORT', get_option('svg-support'))
conf.set('HAVE_ZSTD', get_option('zstd-support'))

configure_file(output: 'config.h', configuration: conf)
root_inc_dir = include_directories ('.')
Expand Down Expand Up @@ -159,8 +160,16 @@ yaml_dep = dependency('yaml-0.1')
xmlb_dep = dependency('xmlb', version: '>= 0.3.14',
fallback: ['libxmlb', 'libxmlb_dep'],
default_options: ['gtkdoc=false', 'introspection=false'])
zstd_dep = dependency('libzstd')
libsystemd_dep = dependency('libsystemd', required: get_option('systemd'))
if get_option('zstd-support')
zstd_dep = dependency('libzstd', required: get_option('zstd-support'))
else
zstd_dep = dependency('', required: false)
endif
if get_option('systemd')
libsystemd_dep = dependency('libsystemd', required: get_option('systemd'))
else
libsystemd_dep = dependency('', required: false)
endif

if get_option ('gir')
# ensure we have a version of GIR that isn't broken with Meson
Expand Down
5 changes: 5 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ option('svg-support',
value : true,
description : 'SVG graphics support for compose (only disable this for bootstrapping purposes)'
)
option('zstd-support',
type : 'boolean',
value : true,
description : 'Support Zstd for (de)compressing local / remote metadata'
)

option('docs',
type : 'boolean',
Expand Down
22 changes: 21 additions & 1 deletion src/as-zstd-decompressor.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@
#include "config.h"

#include <gio/gio.h>
#ifdef HAVE_ZSTD
#include <zstd.h>
#endif

static void as_zstd_decompressor_iface_init (GConverterIface *iface);

struct _AsZstdDecompressor {
GObject parent_instance;
#ifdef HAVE_ZSTD
ZSTD_DStream *zstdstream;
#endif
};

G_DEFINE_TYPE_WITH_CODE (AsZstdDecompressor,
Expand All @@ -40,8 +44,12 @@ G_DEFINE_TYPE_WITH_CODE (AsZstdDecompressor,
static void
as_zstd_decompressor_finalize (GObject *object)
{
#ifdef HAVE_ZSTD
AsZstdDecompressor *self = AS_ZSTD_DECOMPRESSOR (object);

ZSTD_freeDStream (self->zstdstream);
#endif

G_OBJECT_CLASS (as_zstd_decompressor_parent_class)->finalize (object);
}

Expand All @@ -53,8 +61,10 @@ as_zstd_decompressor_init (AsZstdDecompressor *self)
static void
as_zstd_decompressor_constructed (GObject *object)
{
#ifdef HAVE_ZSTD
AsZstdDecompressor *self = AS_ZSTD_DECOMPRESSOR (object);
self->zstdstream = ZSTD_createDStream ();
#endif
}

static void
Expand All @@ -74,8 +84,10 @@ as_zstd_decompressor_new (void)
static void
as_zstd_decompressor_reset (GConverter *converter)
{
#ifdef HAVE_ZSTD
AsZstdDecompressor *self = AS_ZSTD_DECOMPRESSOR (converter);
ZSTD_initDStream (self->zstdstream);
#endif
}

static GConverterResult
Expand All @@ -89,6 +101,7 @@ as_zstd_decompressor_convert (GConverter *converter,
gsize *bytes_written,
GError **error)
{
#ifdef HAVE_ZSTD
AsZstdDecompressor *self = AS_ZSTD_DECOMPRESSOR (converter);
ZSTD_outBuffer output = {
.dst = outbuf,
Expand All @@ -109,13 +122,20 @@ as_zstd_decompressor_convert (GConverter *converter,
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_INVALID_DATA,
"cannot decompress data: %s",
"can not decompress data: %s",
ZSTD_getErrorName (res));
return G_CONVERTER_ERROR;
}
*bytes_read = input.pos;
*bytes_written = output.pos;
return G_CONVERTER_CONVERTED;
#else
g_set_error_literal (error,
G_IO_ERROR,
G_IO_ERROR_INVALID_DATA,
"AppStream was not built with Zstd support. Can not decompress data.");
return G_CONVERTER_ERROR;
#endif
}

static void
Expand Down

0 comments on commit 25a7317

Please sign in to comment.