Skip to content

Commit

Permalink
Add auto options for maxmind_acl, stek_share, and uri_signing plugins (
Browse files Browse the repository at this point in the history
…#10741)

This helps clean up the dependency management and gives fine grained control over whether these plugins are built. I am planning to add all the experimental plugins, but I want to get these changes in quickly because we are still in the middle of fixing the plugins, and other PRs can build on these changes.

BUILD_EXPERIMENTAL_PLUGINS determines whether these plugins are OFF or AUTO on the first configuration. Changing the value of BUILD_EXPERIMENTAL_PLUGINS subsequently will not change whether those plugins are built, because their enabled/disabled state is cached separately. I have not come up with a good way to fix this. Suggestions welcome.
  • Loading branch information
JosiahWI authored Nov 10, 2023
1 parent 7942543 commit e4ff6ca
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 23 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ auto_option(
)
auto_option(LUAJIT PACKAGE_DEPENDS LuaJIT)
auto_option(UNWIND FEATURE_VAR TS_USE_REMOTE_UNWINDING PACKAGE_DEPENDS unwind)
auto_option(CJOSE PACKAGE_DEPENDS cjose)
auto_option(JANSSON PACKAGE_DEPENDS jansson)

option(ENABLE_ASAN "Use address sanitizer (default OFF)")
option(ENABLE_FUZZING "Enable fuzzing (default OFF)")
Expand Down Expand Up @@ -328,8 +326,6 @@ if(ENABLE_QUICHE)
endif()
endif()

# for the plugin system
find_package(nuraft) # experimental stek_share
find_package(maxminddb) # Header_rewrite experimental/maxmind_acl

if(ENABLE_ASAN)
Expand Down Expand Up @@ -614,6 +610,10 @@ if(ENABLE_FUZZING)
add_subdirectory(tests/fuzzing)
endif()
add_subdirectory(plugins)

# set up auto options for experimental plugins
include(ExperimentalPlugins)

add_subdirectory(configs)
if(ENABLE_EXAMPLE)
add_subdirectory(example)
Expand Down
16 changes: 15 additions & 1 deletion cmake/AutoOptionHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ endmacro()
# [DESCRIPTION <description>]
# [DEFAULT <default>]
# [FEATURE_VAR <feature_var>]
# [WITH_SUBDIRECTORY <name>]
# [PACKAGE_DEPENDS <package_one> <package_two> ...]
# [HEADER_DEPENDS <header_one> <header_two> ...]
# )
#
# This macro registers a new auto option and sets its corresponding feature
Expand Down Expand Up @@ -97,9 +99,17 @@ endmacro()
# used, given the value of the option and whether the requirements for the
# feature are satisfied. By default, it is USE_<feature_name>.
#
# WITH_SUBDIRECTORY is an optional subdirectory that should be added if the
# feature is enabled.
#
# PACKAGE_DEPENDS is a list of packages that are required for the feature.
#
# HEADER_DEPENDS is a list of headers that are required for the feature.
#
macro(auto_option _FEATURE_NAME)
cmake_parse_arguments(ARG "" "DESCRIPTION;DEFAULT;FEATURE_VAR" "PACKAGE_DEPENDS;HEADER_DEPENDS" ${ARGN})
cmake_parse_arguments(
ARG "" "DESCRIPTION;DEFAULT;FEATURE_VAR;WITH_SUBDIRECTORY" "PACKAGE_DEPENDS;HEADER_DEPENDS" ${ARGN}
)

set(OPTION_VAR "ENABLE_${_FEATURE_NAME}")
if(ARG_FEATURE_VAR)
Expand Down Expand Up @@ -127,6 +137,10 @@ macro(auto_option _FEATURE_NAME)
else()
set(${FEATURE_VAR} FALSE)
endif()

if(ARG_WITH_SUBDIRECTORY AND ${${FEATURE_VAR}})
add_subdirectory(${ARG_WITH_SUBDIRECTORY})
endif()
endmacro()

# Prints a colorized summary of one auto option.
Expand Down
65 changes: 65 additions & 0 deletions cmake/ExperimentalPlugins.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#######################
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor license
# agreements. See the NOTICE file distributed with this work for additional information regarding
# copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
#
#######################

# These are all the auto options for experimental plugins. They are contained in a
# module instead of a subdirectory because auto_options added in a subdirectory are
# not visible to their parent directories.

# Note that this default only works on the first run before the options are cached.
# Once the options are cached they must be adjusted manually.
if(BUILD_EXPERIMENTAL_PLUGINS)
set(_DEFAULT AUTO)
else()
set(_DEFAULT OFF)
endif()

auto_option(
MAXMIND_ACL
FEATURE_VAR
BUILD_MAXMIND_ACL
WITH_SUBDIRECTORY
plugins/experimental/maxmind_acl
PACKAGE_DEPENDS
maxminddb
DEFAULT
${_DEFAULT}
)
auto_option(
STEK_SHARE
FEATURE_VAR
BUILD_STEK_SHARE
WITH_SUBDIRECTORY
plugins/experimental/stek_share
PACKAGE_DEPENDS
nuraft
DEFAULT
${_DEFAULT}
)
auto_option(
URI_SIGNING
FEATURE_VAR
BUILD_URI_SIGNING
WITH_SUBDIRECTORY
plugins/experimental/uri_signing
PACKAGE_DEPENDS
cjose
jansson
DEFAULT
${_DEFAULT}
)

unset(_DEFAULT)
19 changes: 9 additions & 10 deletions cmake/Findnuraft.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,19 @@
#

find_library(nuraft_LIBRARY nuraft)
find_path(
nuraft_INCLUDE_DIR
NAMES libnuraft/nuraft.hxx
)
find_path(nuraft_INCLUDE_DIR NAMES libnuraft/nuraft.hxx)

mark_as_advanced(nuraft_FOUND nuraft_LIBRARY nuraft_INCLUDE_DIR)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(nuraft REQUIRED_VARS nuraft_LIBRARY nuraft_INCLUDE_DIR)

# Add the library but only add libraries if nuraft is found
add_library(nuraft::nuraft INTERFACE IMPORTED)
if(nuraft_FOUND)
set(nuraft_INCLUDE_DIRS ${nuraft_INCLUDE_DIR})
target_include_directories(nuraft::nuraft INTERFACE ${nuraft_INCLUDE_DIRS})
target_link_libraries(nuraft::nuraft INTERFACE ${nuraft_LIBRARY})
if(nuraft_FOUND AND NOT TARGET nuraft::nuraft)
# Add the library but only add libraries if nuraft is found
add_library(nuraft::nuraft INTERFACE IMPORTED)
if(nuraft_FOUND)
set(nuraft_INCLUDE_DIRS ${nuraft_INCLUDE_DIR})
target_include_directories(nuraft::nuraft INTERFACE ${nuraft_INCLUDE_DIRS})
target_link_libraries(nuraft::nuraft INTERFACE ${nuraft_LIBRARY})
endif()
endif()
7 changes: 0 additions & 7 deletions plugins/experimental/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,14 @@ add_subdirectory(hook-trace)
add_subdirectory(http_stats)
add_subdirectory(icap)
add_subdirectory(inliner)
add_subdirectory(maxmind_acl)
add_subdirectory(memcache)
add_subdirectory(memory_profile)
add_subdirectory(money_trace)
add_subdirectory(mp4)
add_subdirectory(rate_limit)
add_subdirectory(redo_cache_lookup)
add_subdirectory(sslheaders)
add_subdirectory(stek_share)
add_subdirectory(stream_editor)
add_subdirectory(system_stats)
add_subdirectory(tls_bridge)
if(USE_CJOSE AND USE_JANSSON)
add_subdirectory(uri_signing)
else()
message(STATUS "skipping uri_signing plugin (missing cjose and jansson)")
endif()
add_subdirectory(url_sig)
2 changes: 1 addition & 1 deletion plugins/experimental/maxmind_acl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if(maxminddb_FOUND)

target_include_directories(maxmind_acl PRIVATE ${PCRE_INCLUDE_DIR})

target_link_libraries(maxmind_acl PRIVATE libswoc yaml-cpp::yaml-cpp maxminddb::maxminddb)
target_link_libraries(maxmind_acl PRIVATE libswoc ts::tsapicore yaml-cpp::yaml-cpp maxminddb::maxminddb)

else()
message(STATUS "skipping maxmind_acl plugin (missing maxminddb)")
Expand Down

0 comments on commit e4ff6ca

Please sign in to comment.