[RFC 2/4] erofs-utils: introduce build support for libcurl, openssl and libxml2 library

Yifan Zhao zhaoyifan28 at huawei.com
Tue Jul 29 21:06:08 AEST 2025


From: zhaoyifan <zhaoyifan28 at huawei.com>

This patch adds additional dependencies on libcurl, openssl and libxml2 library
for the upcoming S3 data source support, with libcurl to interact with S3 API,
openssl to generate S3 auth signature and libxml2 to parse response body.

The newly introduced dependencies are optional, controlled by the `--enable-s3`
configure option.

Signed-off-by: Yifan Zhao <zhaoyifan28 at huawei.com>
---
 configure.ac       | 41 +++++++++++++++++++++++++++++++++++++++++
 include/erofs/s3.h | 10 ++++++++++
 lib/Makefile.am    |  5 +++++
 lib/s3.c           |  7 +++++++
 mkfs/Makefile.am   |  3 ++-
 5 files changed, 65 insertions(+), 1 deletion(-)
 create mode 100644 include/erofs/s3.h
 create mode 100644 lib/s3.c

diff --git a/configure.ac b/configure.ac
index 2d42b1f..925fad8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -165,6 +165,10 @@ AC_ARG_WITH(xxhash,
    [AS_HELP_STRING([--with-xxhash],
       [Enable and build with libxxhash support @<:@default=auto@:>@])])
 
+AC_ARG_ENABLE(s3,
+   [AS_HELP_STRING([--enable-s3], [enable s3 image generation support @<:@default=no@:>@])],
+   [enable_s3="$enableval"], [enable_s3="no"])
+
 AC_ARG_ENABLE(fuse,
    [AS_HELP_STRING([--enable-fuse], [enable erofsfuse @<:@default=no@:>@])],
    [enable_fuse="$enableval"], [enable_fuse="no"])
@@ -578,6 +582,32 @@ AS_IF([test "x$with_xxhash" != "xno"], [
   ])
 ])
 
+AS_IF([test "x$enable_s3" != "xno"], [
+  # Paranoia: don't trust the result reported by pkgconfig before trying out
+  saved_LIBS="$LIBS"
+  saved_CPPFLAGS=${CPPFLAGS}
+  PKG_CHECK_MODULES([libcurl], [libcurl])
+  PKG_CHECK_MODULES([openssl], [openssl])
+  PKG_CHECK_MODULES([libxml2],  [libxml-2.0])
+  CPPFLAGS="${libcurl_CFLAGS} ${openssl_CFLAGS} ${libxml2_CFLAGS} ${CPPFLAGS}"
+  LIBS="${libcurl_LIBS} ${openssl_LIBS} ${libxml2_LIBS} $LIBS"
+  s3_deps_ok="yes"
+  AC_CHECK_LIB(curl, curl_multi_perform, [], [
+    AC_MSG_ERROR([libcurl doesn't work properly])
+    s3_deps_ok="no"
+  ])
+  AC_CHECK_LIB(ssl, EVP_sha1, [], [
+    AC_MSG_ERROR([openssl doesn't work properly])
+    s3_deps_ok="no"
+  ])
+  AC_CHECK_LIB(xml2, xmlReadMemory, [], [
+    AC_MSG_ERROR([libxml-2.0 doesn't work properly])
+    s3_deps_ok="no"
+  ])
+  AS_IF([test "x$s3_deps_ok" = "xyes"], [have_s3="yes"], [have_s3="no"])
+  LIBS="${saved_LIBS}"
+  CPPFLAGS="${saved_CPPFLAGS}"], [have_s3="no"])
+
 # Enable 64-bit off_t
 CFLAGS+=" -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
 
@@ -601,6 +631,7 @@ AM_CONDITIONAL([ENABLE_LIBDEFLATE], [test "x${have_libdeflate}" = "xyes"])
 AM_CONDITIONAL([ENABLE_LIBZSTD], [test "x${have_libzstd}" = "xyes"])
 AM_CONDITIONAL([ENABLE_QPL], [test "x${have_qpl}" = "xyes"])
 AM_CONDITIONAL([ENABLE_XXHASH], [test "x${have_xxhash}" = "xyes"])
+AM_CONDITIONAL([ENABLE_S3], [test "x${have_s3}" = "xyes"])
 AM_CONDITIONAL([ENABLE_STATIC_FUSE], [test "x${enable_static_fuse}" = "xyes"])
 
 if test "x$have_uuid" = "xyes"; then
@@ -652,6 +683,16 @@ if test "x$have_xxhash" = "xyes"; then
   AC_DEFINE([HAVE_XXHASH], 1, [Define to 1 if xxhash is found])
 fi
 
+if test "x$have_s3" = "xyes"; then
+  AC_DEFINE([HAVE_S3], 1, [Define to 1 if s3 is enabled])
+  AC_SUBST([libcurl_LIBS])
+  AC_SUBST([libcurl_CFLAGS])
+  AC_SUBST([openssl_LIBS])
+  AC_SUBST([openssl_CFLAGS])
+  AC_SUBST([libxml2_LIBS])
+  AC_SUBST([libxml2_CFLAGS])
+fi
+
 # Dump maximum block size
 AS_IF([test "x$erofs_cv_max_block_size" = "x"],
       [$erofs_cv_max_block_size = 4096], [])
diff --git a/include/erofs/s3.h b/include/erofs/s3.h
new file mode 100644
index 0000000..e29bde2
--- /dev/null
+++ b/include/erofs/s3.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */
+/*
+ * Copyright (C) 2025 HUAWEI, Inc.
+ *             http://www.huawei.com/
+ * Created by Yifan Zhao <zhaoyifan28 at huawei.com>
+ */
+#ifndef __EROFS_S3_H
+#define __EROFS_S3_H
+
+#endif
\ No newline at end of file
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 0db81df..b53ec76 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -22,6 +22,7 @@ noinst_HEADERS = $(top_srcdir)/include/erofs_fs.h \
       $(top_srcdir)/include/erofs/print.h \
       $(top_srcdir)/include/erofs/bitops.h \
       $(top_srcdir)/include/erofs/tar.h \
+      $(top_srcdir)/include/erofs/s3.h \
       $(top_srcdir)/include/erofs/trace.h \
       $(top_srcdir)/include/erofs/xattr.h \
       $(top_srcdir)/include/erofs/compress_hints.h \
@@ -66,6 +67,10 @@ liberofs_la_CFLAGS += ${libxxhash_CFLAGS}
 else
 liberofs_la_SOURCES += xxhash.c
 endif
+if ENABLE_S3
+liberofs_la_CFLAGS += ${libcurl_CFLAGS} ${openssl_CFLAGS} ${libxml2_CFLAGS}
+liberofs_la_SOURCES += s3.c
+endif
 if ENABLE_EROFS_MT
 liberofs_la_LDFLAGS = -lpthread
 liberofs_la_SOURCES += workqueue.c
diff --git a/lib/s3.c b/lib/s3.c
new file mode 100644
index 0000000..bbd35a4
--- /dev/null
+++ b/lib/s3.c
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */
+/*
+ * Copyright (C) 2025 HUAWEI, Inc.
+ *             http://www.huawei.com/
+ * Created by Yifan Zhao <zhaoyifan28 at huawei.com>
+ */
+#include "erofs/s3.h"
diff --git a/mkfs/Makefile.am b/mkfs/Makefile.am
index 2499242..b84b4c1 100644
--- a/mkfs/Makefile.am
+++ b/mkfs/Makefile.am
@@ -7,4 +7,5 @@ mkfs_erofs_SOURCES = main.c
 mkfs_erofs_CFLAGS = -Wall -I$(top_srcdir)/include
 mkfs_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \
 	${libuuid_LIBS} ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} \
-	${libdeflate_LIBS} ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS}
+	${libdeflate_LIBS} ${libzstd_LIBS} ${libqpl_LIBS} ${libxxhash_LIBS} \
+	${libcurl_LIBS} ${openssl_LIBS} ${libxml2_LIBS}
-- 
2.46.0



More information about the Linux-erofs mailing list