From 61d558fc9d76d32e917c233571eb3aefe62299e1 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 22 Jun 2022 18:59:33 -0700 Subject: [PATCH] ircd: Define all IRCD_USE_ as integers for constexprs. --- configure.ac | 28 +++++++++++++ include/ircd/cl/init.h | 2 +- include/ircd/magick.h | 16 ++----- ircd/fs.cc | 86 ++++++++++++++++---------------------- ircd/fs_aio.cc | 7 ++-- ircd/gpt_pipe.cc | 5 +++ modules/console.cc | 12 ++++++ modules/llvm.cc | 13 +++--- modules/media/thumbnail.cc | 6 +-- 9 files changed, 98 insertions(+), 77 deletions(-) diff --git a/configure.ac b/configure.ac index b2d1ec567..51f098cc2 100644 --- a/configure.ac +++ b/configure.ac @@ -1403,6 +1403,8 @@ AM_COND_IF(LINUX, if test "$aio" = "yes"; then IRCD_DEFINE(USE_AIO, [1], [Linux AIO is supported and will be used]) +else + IRCD_DEFINE(USE_AIO, [0], [Linux AIO is not supported and won't be used]) fi AM_CONDITIONAL([AIO], [[[[ $aio = yes ]]]]) @@ -1426,6 +1428,8 @@ AM_CONDITIONAL([IOU], [[[[ $io_uring = yes ]]]]) AM_COND_IF([IOU], [ IRCD_DEFINE(USE_IOU, [1], [Linux io_uring is supported and may be used]) +], [ + IRCD_DEFINE(USE_IOU, [0], [Linux io_uring is not available]) ]) @@ -1659,6 +1663,13 @@ PKG_CHECK_MODULES(icuuc, [icuuc], AM_CONDITIONAL([ICUUC], [test "x$have_icuuc" = "xyes" ]) AM_CONDITIONAL([ICU], [test "x$have_icu" = "xyes" ]) +AM_COND_IF(ICU, +[ + IRCD_DEFINE(USE_ICU, [1], [International Components for Unicode is available]) +], [ + IRCD_DEFINE(USE_ICU, [0], [International Components for Unicode is not available]) +]) + dnl dnl dnl libsodium (NaCl) crypto support @@ -2237,6 +2248,8 @@ dnl IRCD_ENABLE_MAGICK is always defined for use in a constexpr if AM_COND_IF([IMAGEMAGICK], [ IRCD_DEFINE(USE_MAGICK, [1], [Magick support is available and enabled]) +], [ + IRCD_DEFINE(USE_MAGICK, [0], [Magick support is not available]) ]) dnl @@ -2343,6 +2356,13 @@ PKG_CHECK_MODULES(LLVM, [LLVM], AM_CONDITIONAL([LLVM], [test "x$have_libllvm" = "xyes" ]) +AM_COND_IF(LLVM, +[ + IRCD_DEFINE(USE_LLVM, [1], [libllvm is available and enabled]) +], [ + IRCD_DEFINE(USE_LLVM, [0], [libllvm is not available]) +]) + dnl dnl dnl LibDRM @@ -2389,6 +2409,8 @@ AM_COND_IF([DRM], AC_MSG_RESULT([yes]) IRCD_DEFINE(USE_DRM, [1], [DRM support is available and enabled]) DRM_LIBS+="-ldrm" +], [ + IRCD_DEFINE(USE_DRM, [0], [DRM support is not available]) ]) dnl @@ -2465,7 +2487,11 @@ AM_COND_IF([OPENCL], [ IRCD_DEFINE(USE_MESA_OPENCL, [1], [MesaOpenCL support is available and enabled]) OPENCL_LIBS+=" -lMesaOpenCL" + ], [ + IRCD_DEFINE(USE_MESA_OPENCL, [0], [MesaOpenCL support is not available and disabled]) ]) +], [ + IRCD_DEFINE(USE_OPENCL, [0], [OpenCL support is not available]) ]) dnl @@ -2521,6 +2547,8 @@ AM_COND_IF([ARMNN], [ IRCD_DEFINE(USE_ARMNN, [1], [Arm NN support is available and enabled]) ARMNN_LIBS+="-larmnn" +], [ + IRCD_DEFINE(USE_ARMNN, [0], [Arm NN support is not available]) ]) dnl diff --git a/include/ircd/cl/init.h b/include/ircd/cl/init.h index aaee87884..1ae26f802 100644 --- a/include/ircd/cl/init.h +++ b/include/ircd/cl/init.h @@ -38,7 +38,7 @@ ircd::cl::init init(), ~init() noexcept; }; -#ifndef IRCD_USE_OPENCL +#if IRCD_USE_OPENCL == 0 inline ircd::cl::init::init() {} inline ircd::cl::init::~init() noexcept {} #endif diff --git a/include/ircd/magick.h b/include/ircd/magick.h index d61be2017..35ffce30a 100644 --- a/include/ircd/magick.h +++ b/include/ircd/magick.h @@ -113,15 +113,7 @@ ircd::magick::init }; // inline stubs when magick disabled/unavailable. -#if !defined(IRCD_USE_MAGICK) - -inline -ircd::magick::init::init() -{} - -inline -ircd::magick::init::~init() -noexcept -{} - -#endif IRCD_USE_MAGICK +#if IRCD_USE_MAGICK == 0 +inline ircd::magick::init::init() {} +inline ircd::magick::init::~init() noexcept {} +#endif IRCD_USE_MAGICK == 0 diff --git a/ircd/fs.cc b/ircd/fs.cc index bd67f885b..524ce02ac 100644 --- a/ircd/fs.cc +++ b/ircd/fs.cc @@ -15,16 +15,17 @@ #include -#ifdef IRCD_USE_AIO +#if IRCD_USE_AIO > 0 #include "fs_aio.h" #endif -#ifdef IRCD_USE_IOU +#if IRCD_USE_IOU > 0 #include "fs_iou.h" #endif // TODO: prevents use until io_uring support implemented #undef IRCD_USE_IOU +#define IRCD_USE_IOU 0 namespace ircd::fs { @@ -230,17 +231,13 @@ ircd::fs::support::rwf_write_life decltype(ircd::fs::support::aio) ircd::fs::support::aio { - #ifdef IRCD_USE_AIO - true - #else - false - #endif + IRCD_USE_AIO }; void ircd::fs::support::dump_info() { - #if defined(IRCD_USE_AIO) || defined(IRCD_USE_IOU) + #if IRCD_USE_AIO || IRCD_USE_IOU const bool support_async {true}; #else const bool support_async {false}; @@ -779,21 +776,19 @@ ircd::fs::flush(const fd &fd, { assert(opts.op == op::SYNC); - #ifdef IRCD_USE_IOU - if(iou::system && opts.aio) - return void(iou::fsync(fd, opts)); - #endif + if constexpr(IRCD_USE_IOU) + if(iou::system && opts.aio) + return void(iou::fsync(fd, opts)); - #ifdef IRCD_USE_AIO - if(aio::system && opts.aio) - { - if(support::aio_fdsync && !opts.metadata) - return void(aio::fsync(fd, opts)); + if constexpr(IRCD_USE_AIO) + if(aio::system && opts.aio) + { + if(support::aio_fdsync && !opts.metadata) + return void(aio::fsync(fd, opts)); - else if(support::aio_fsync && opts.metadata) - return void(aio::fsync(fd, opts)); - } - #endif + else if(support::aio_fsync && opts.metadata) + return void(aio::fsync(fd, opts)); + } const prof::syscall_usage_warning message { @@ -1038,15 +1033,13 @@ ircd::fs::_read(const fd &fd, { assert(opts.op == op::READ); - #ifdef IRCD_USE_IOU - if(likely(iou::system && opts.aio)) - return iou::read(fd, iov, opts); - #endif + if constexpr(IRCD_USE_IOU) + if(likely(iou::system && opts.aio)) + return iou::read(fd, iov, opts); - #ifdef IRCD_USE_AIO - if(likely(aio::system && opts.aio)) - return aio::read(fd, iov, opts); - #endif + if constexpr(IRCD_USE_AIO) + if(likely(aio::system && opts.aio)) + return aio::read(fd, iov, opts); #ifdef HAVE_PREADV2 return support::preadv2? @@ -1425,15 +1418,13 @@ ircd::fs::_write(const fd &fd, { assert(opts.op == op::WRITE); - #ifdef IRCD_USE_IOU - if(likely(iou::system && opts.aio)) - return iou::write(fd, iov, opts); - #endif + if constexpr(IRCD_USE_IOU) + if(likely(iou::system && opts.aio)) + return iou::write(fd, iov, opts); - #ifdef IRCD_USE_AIO - if(likely(aio::system && opts.aio)) - return aio::write(fd, iov, opts); - #endif + if constexpr(IRCD_USE_AIO) + if(likely(aio::system && opts.aio)) + return aio::write(fd, iov, opts); #ifdef HAVE_PWRITEV2 return support::pwritev2? @@ -1671,14 +1662,14 @@ ircd::fs::aio::system; // init // -#ifndef IRCD_USE_AIO +#if IRCD_USE_AIO == 0 ircd::fs::aio::init::init() { assert(!system); } #endif -#ifndef IRCD_USE_AIO +#if IRCD_USE_AIO == 0 [[using gnu: weak, cold]] ircd::fs::aio::init::~init() noexcept @@ -1895,12 +1886,9 @@ ircd::fs::aio::stats::stats() decltype(ircd::fs::iou::support) ircd::fs::iou::support { - #ifdef IRCD_USE_IOU - info::kernel_version[0] > 5 || - (info::kernel_version[0] >= 5 && info::kernel_version[1] >= 1) - #else - false - #endif + IRCD_USE_IOU && + (info::kernel_version[0] > 5 || + (info::kernel_version[0] >= 5 && info::kernel_version[1] >= 1)) }; /// Conf item to control whether iou is enabled or bypassed. @@ -1927,7 +1915,7 @@ ircd::fs::iou::system; // init // -#ifndef IRCD_USE_IOU +#if IRCD_USE_IOU == 0 [[gnu::weak]] ircd::fs::iou::init::init() { @@ -1935,7 +1923,7 @@ ircd::fs::iou::init::init() } #endif -#ifndef IRCD_USE_IOU +#if IRCD_USE_IOU == 0 [[gnu::weak]] ircd::fs::iou::init::~init() noexcept @@ -2725,7 +2713,7 @@ ircd::fs::reflect(const op &op) return "????"; } -#ifndef IRCD_USE_AIO +#if IRCD_USE_AIO == 0 [[gnu::weak]] ircd::fs::op ircd::fs::aio::translate(const int &val) @@ -2734,7 +2722,7 @@ ircd::fs::aio::translate(const int &val) } #endif -#ifndef IRCD_USE_IOU +#if IRCD_USE_IOU == 0 [[gnu::weak]] ircd::fs::op ircd::fs::iou::translate(const int &val) diff --git a/ircd/fs_aio.cc b/ircd/fs_aio.cc index 0c9162abc..6ce11220a 100644 --- a/ircd/fs_aio.cc +++ b/ircd/fs_aio.cc @@ -85,10 +85,9 @@ ircd::fs::aio::init::init() // Don't init AIO if the io_uring is established. If it is, that means it // was supported by the build, this kernel, and didn't encounter an error // to construct. In all other cases AIO can serve as a fallback. - #if defined(IRCD_USE_IOU) - if(iou::system) - return; - #endif + if constexpr(IRCD_USE_IOU) + if(iou::system) + return; assert(!system); if(!aio::enable) diff --git a/ircd/gpt_pipe.cc b/ircd/gpt_pipe.cc index fc1447097..1ff5ef82a 100644 --- a/ircd/gpt_pipe.cc +++ b/ircd/gpt_pipe.cc @@ -32,6 +32,8 @@ ircd::gpt::pipe::handle_quit void ircd::gpt::pipe::init() { + if constexpr(!IRCD_USE_OPENCL) + return; } [[using gnu: cold, visibility("hidden")]] @@ -39,6 +41,9 @@ void ircd::gpt::pipe::fini() noexcept { + if constexpr(!IRCD_USE_OPENCL) + return; + const auto pending { cl::work::list.size() diff --git a/modules/console.cc b/modules/console.cc index 948d419f4..8a7771292 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -17284,6 +17284,12 @@ console_cmd__bridge__protocol(opt &out, const string_view &line) bool console_cmd__icu(opt &out, const string_view &line) { + if constexpr(!IRCD_USE_ICU) + throw error + { + "ICU is not available." + }; + const unique_mutable_buffer buf { size(line) * 4 @@ -17553,6 +17559,12 @@ console_cmd__app__signal(opt &out, const string_view &line) bool console_cmd__cl__info(opt &out, const string_view &line) { + if constexpr(!IRCD_USE_OPENCL) + throw error + { + "OpenCL is not available." + }; + const params param{line, " ", { "platform", "device", diff --git a/modules/llvm.cc b/modules/llvm.cc index 792a46963..80970a842 100644 --- a/modules/llvm.cc +++ b/modules/llvm.cc @@ -8,13 +8,14 @@ // copyright notice and this permission notice is present in all copies. The // full license for this software is available in the LICENSE file. -#if !defined(IRCD_USE_LLVM) \ -&& __has_include("") \ -&& __has_include("") - #define IRCD_USE_LLVM +#if IRCD_USE_LLVM == 1 && \ + (!__has_include("") || \ + ! __has_include("")) + #undef IRCD_USE_LLVM + #define IRCD_USE_LLVM 0 #endif -#if defined(IRCD_USE_LLVM) // ------------------------------------------------- +#if IRCD_USE_LLVM > 0 // ------------------------------------------------------ #include #include @@ -88,4 +89,4 @@ ircd::llvm::fini() } -#endif // IRCD_USE_LLVM ------------------------------------------------------ +#endif // IRCD_USE_LLVM > 0 -------------------------------------------------- diff --git a/modules/media/thumbnail.cc b/modules/media/thumbnail.cc index 34545ac6a..01633e6ab 100644 --- a/modules/media/thumbnail.cc +++ b/modules/media/thumbnail.cc @@ -282,11 +282,7 @@ get__thumbnail_local(client &client, const bool supported { // Available in build - #ifdef IRCD_USE_MAGICK - (true) - #else - (false) - #endif + IRCD_USE_MAGICK // Enabled by configuration && enable