1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python2_7 python3_6 )
7 PYTHON_REQ_USE="threads(+)"
10 USE_RUBY="ruby23 ruby24"
14 PHP_EXT_OPTIONAL_USE="php"
15 USE_PHP="php7-2 php7-3 php7-4" # deps must be registered separately below
19 inherit apache-module eutils flag-o-matic multilib pax-utils php-ext-source-r2 python-r1 ruby-ng versionator
21 DESCRIPTION="uWSGI server for Python web applications"
22 HOMEPAGE="http://projects.unbit.it/uwsgi/"
23 SRC_URI="https://github.com/unbit/uwsgi/archive/${PV}.tar.gz -> ${P}.tar.gz"
27 KEYWORDS="amd64 x86 ~amd64-linux"
29 UWSGI_PLUGINS_STD=( ping cache carbon nagios rpc rrdtool
30 http ugreen signal syslog rsyslog
31 router_{uwsgi,redirect,basicauth,rewrite,http,cache,static,memcached,redis,hash,expires,metrics}
32 {core,fast,raw,ssl}router
33 redislog mongodblog log{file,socket}
34 spooler cheaper_busyness symcall
35 transformation_{chunked,gzip,offload,tofile}
37 UWSGI_PLUGINS_OPT=( alarm_{curl,xmpp} clock_{monotonic,realtime} curl_cron
38 dumbloop echo emperor_{amqp,pg,zeromq} forkptyrouter
39 geoip graylog2 legion_cache_fetch ldap log{crypto,pipe} notfound pam
40 rados router_{access,radius,spnego,xmldir}
41 sqlite ssi stats_pusher_statsd
42 systemd_logger transformation_toupper tuntap webdav xattr xslt zabbix )
44 LANG_SUPPORT_SIMPLE=( cgi perl ) # plugins which can be built in the main build process
45 LANG_SUPPORT_EXTENDED=( go lua php python python-asyncio python-gevent ruby )
47 # plugins to be ignored (for now):
48 # cheaper_backlog2: example plugin
50 # cplusplus: partially example code, needs explicit class
52 # example: example plugin
53 # exception_log: example plugin
57 IUSE="apache2 +caps debug +embedded expat jemalloc json libressl +pcre +routing selinux +ssl +xml yajl yaml zeromq"
59 for plugin in ${UWSGI_PLUGINS_STD[@]}; do IUSE="${IUSE} +uwsgi_plugins_${plugin}"; done
60 for plugin in ${UWSGI_PLUGINS_OPT[@]}; do IUSE="${IUSE} uwsgi_plugins_${plugin}"; done
61 IUSE="${IUSE} ${LANG_SUPPORT_SIMPLE[@]} ${LANG_SUPPORT_EXTENDED[@]}"
63 REQUIRED_USE="|| ( ${LANG_SUPPORT_SIMPLE[@]} ${LANG_SUPPORT_EXTENDED[@]} )
64 uwsgi_plugins_logcrypto? ( ssl )
65 uwsgi_plugins_sslrouter? ( ssl )
67 uwsgi_plugins_emperor_zeromq? ( zeromq )
68 uwsgi_plugins_forkptyrouter? ( uwsgi_plugins_corerouter )
69 uwsgi_plugins_router_xmldir? ( xml !expat )
70 python? ( ${PYTHON_REQUIRED_USE} )
71 python-asyncio? ( || ( $(python_gen_useflags -3) ) python-gevent )
72 python-gevent? ( python )
75 # util-linux is required for libuuid when requesting zeromq support
80 # 4. Language/app support
81 CDEPEND="sys-libs/zlib
82 caps? ( sys-libs/libcap )
83 json? ( !yajl? ( dev-libs/jansson )
84 yajl? ( dev-libs/yajl ) )
85 pcre? ( dev-libs/libpcre:3 )
87 !libressl? ( dev-libs/openssl:0 )
88 libressl? ( dev-libs/libressl )
90 xml? ( !expat? ( dev-libs/libxml2 )
91 expat? ( dev-libs/expat ) )
92 yaml? ( dev-libs/libyaml )
93 zeromq? ( net-libs/zeromq sys-apps/util-linux )
94 uwsgi_plugins_alarm_curl? ( net-misc/curl )
95 uwsgi_plugins_alarm_xmpp? ( net-libs/gloox )
96 uwsgi_plugins_curl_cron? ( net-misc/curl )
97 uwsgi_plugins_emperor_pg? ( dev-db/postgresql:= )
98 uwsgi_plugins_geoip? ( dev-libs/geoip )
99 uwsgi_plugins_ldap? ( net-nds/openldap )
100 uwsgi_plugins_pam? ( sys-libs/pam )
101 uwsgi_plugins_sqlite? ( dev-db/sqlite:3 )
102 uwsgi_plugins_rados? ( sys-cluster/ceph )
103 uwsgi_plugins_router_access? ( sys-apps/tcp-wrappers )
104 uwsgi_plugins_router_spnego? ( virtual/krb5 )
105 uwsgi_plugins_systemd_logger? ( sys-apps/systemd )
106 uwsgi_plugins_webdav? ( dev-libs/libxml2 )
107 uwsgi_plugins_xslt? ( dev-libs/libxslt )
108 go? ( sys-devel/gcc:=[go] )
109 lua? ( dev-lang/lua:= )
110 perl? ( dev-lang/perl:= )
112 php_targets_php7-2? ( dev-lang/php:7.2[embed] )
113 php_targets_php7-3? ( dev-lang/php:7.3[embed] )
114 php_targets_php7-4? ( dev-lang/php:7.4[embed] )
116 python? ( ${PYTHON_DEPS} )
117 python-gevent? ( >=dev-python/gevent-1.2.1[${PYTHON_USEDEP}] )
118 ruby? ( $(ruby_implementations_depend) )"
122 selinux? ( sec-policy/selinux-uwsgi )
123 uwsgi_plugins_rrdtool? ( net-analyzer/rrdtool )"
127 S="${WORKDIR}/${MY_P}"
128 APXS2_S="${S}/apache2"
129 APACHE2_MOD_CONF="42_mod_uwsgi-r2 42_mod_uwsgi"
131 # FIXME: is this patch still useful?
133 "${FILESDIR}/2.0.14-php-plugin.patch"
142 use ruby && ruby-ng_pkg_setup
143 depend.apache_pkg_setup
151 -e "s|'-Werror', ||" \
152 -e "s|uc.get('plugin_dir')|uc.get('plugin_build_dir')|" \
153 uwsgiconfig.py || die "sed failed"
156 -e "s|/lib|/$(get_libdir)|" \
157 plugins/php/uwsgiplugin.py || die "sed failed"
161 local embedded_plugins=()
163 local malloc_impl="libc"
167 for p in ${UWSGI_PLUGINS_STD[@]} ${UWSGI_PLUGINS_OPT[@]} ; do
168 use uwsgi_plugins_${p} && embedded_plugins+=("${p}")
170 for p in ${LANG_SUPPORT_SIMPLE[@]} ; do
171 use ${p} && plugins+=("${p}")
174 # do not embed any plugins
175 if ! use embedded; then
176 plugins=( ${plugins[@]} ${embedded_plugins[@]} )
181 plugins=${plugins[@]}
182 embedded_plugins=${embedded_plugins[@]}
184 # rename some of the use flags, language plugins are always real plugins
185 plugins="${plugins/perl/psgi}"
186 plugins="${plugins/sqlite/sqlite3}"
187 embedded_plugins="${embedded_plugins/sqlite/sqlite3}"
189 # override defaults as requested by the user
191 use expat && xml="expat" || xml="libxml2"
194 use yajl && json="yajl" || json="jansson"
196 use jemalloc && malloc_impl="jemalloc"
198 # prepare the buildconf for gentoo
199 cp "${FILESDIR}"/gentoo.buildconf buildconf/gentoo.ini || die
201 -e "s|VAR_XML|${xml}|" \
202 -e "s|VAR_YAML|$(usex yaml libyaml true)|" \
203 -e "s|VAR_JSON|${json}|" \
204 -e "s|VAR_SSL|$(usex ssl true false)|" \
205 -e "s|VAR_PCRE|$(usex pcre true false)|" \
206 -e "s|VAR_ZMQ|$(usex zeromq true false)|" \
207 -e "s|VAR_ROUTING|$(usex routing true false)|" \
208 -e "s|VAR_DEBUG|$(usex debug true false)|" \
209 -e "s|VAR_MALLOC|${malloc_impl}|" \
210 -e "s|VAR_PLUGINS|${plugins// /, }|" \
211 -e "s|VAR_PLUGIN_DIR|${EPREFIX}/usr/$(get_libdir)/uwsgi|" \
212 -e "s|VAR_BUILD_DIR|${T}/plugins|" \
213 -e "s|VAR_EMBEDDED|${embedded_plugins// /, }|" \
214 buildconf/gentoo.ini || die "sed failed"
217 sed -i -e 's|sys/capability.h|DISABLED|' uwsgiconfig.py || die "sed failed"
220 if ! use zeromq; then
221 sed -i -e 's|uuid/uuid.h|DISABLED|' uwsgiconfig.py || die "sed failed"
224 if use uwsgi_plugins_emperor_pg ; then
225 PGPV="$(best_version dev-db/postgresql)"
226 PGSLOT="$(get_version_component_range 1-2 ${PGPV##dev-db/postgresql-})"
228 -e "s|pg_config|pg_config${PGSLOT/.}|" \
229 plugins/emperor_pg/uwsgiplugin.py || die "sed failed"
233 each_ruby_compile() {
234 cd "${WORKDIR}/${MY_P}" || die "sed failed"
236 UWSGICONFIG_RUBYPATH="${RUBY}" python uwsgiconfig.py --plugin plugins/rack gentoo rack_${RUBY##*/} || die "building plugin for ${RUBY} failed"
237 UWSGICONFIG_RUBYPATH="${RUBY}" python uwsgiconfig.py --plugin plugins/fiber gentoo fiber_${RUBY##*/}|| die "building fiber plugin for ${RUBY} failed"
238 UWSGICONFIG_RUBYPATH="${RUBY}" python uwsgiconfig.py --plugin plugins/rbthreads gentoo rbthreads_${RUBY##*/}|| die "building rbthreads plugin for ${RUBY} failed"
241 python_compile_plugins() {
247 ${PYTHON} uwsgiconfig.py --plugin plugins/python gentoo ${EPYV} || die "building plugin for ${EPYTHON} failed"
249 if use python-asyncio ; then
250 if [[ "${PYV}" == "34" || "${PYV}" == "35" ]] ; then
251 ${PYTHON} uwsgiconfig.py --plugin plugins/asyncio gentoo asyncio${PYV} || die "building plugin for asyncio-support in ${EPYTHON} failed"
255 if use python-gevent ; then
256 ${PYTHON} uwsgiconfig.py --plugin plugins/gevent gentoo gevent${PYV} || die "building plugin for gevent-support in ${EPYTHON} failed"
260 python_install_symlinks() {
261 dosym uwsgi /usr/bin/uwsgi_${EPYTHON/.}
265 mkdir -p "${T}/plugins" || die
267 python uwsgiconfig.py --build gentoo || die "building uwsgi failed"
270 python uwsgiconfig.py --plugin plugins/gccgo gentoo || die "building plugin for go failed"
274 # setting the name for the pkg-config file to lua, since we don't have
276 UWSGICONFIG_LUAPC="lua" python uwsgiconfig.py --plugin plugins/lua gentoo || die "building plugin for lua failed"
280 for s in $(php_get_slots); do
281 UWSGICONFIG_PHPDIR="/usr/$(get_libdir)/${s}" python uwsgiconfig.py --plugin plugins/php gentoo ${s/.} || die "building plugin for ${s} failed"
286 python_foreach_impl python_compile_plugins
293 if use apache2 ; then
294 for m in proxy_uwsgi Ruwsgi uwsgi ; do
295 APXS2_ARGS="-c mod_${m}.c"
296 apache-module_src_compile
303 pax-mark m "${D}"/usr/bin/uwsgi
305 insinto /usr/$(get_libdir)/uwsgi
306 doins "${T}/plugins"/*.so
308 use cgi && dosym uwsgi /usr/bin/uwsgi_cgi
309 use go && dosym uwsgi /usr/bin/uwsgi_go
310 use lua && dosym uwsgi /usr/bin/uwsgi_lua
311 use perl && dosym uwsgi /usr/bin/uwsgi_psgi
314 for s in $(php_get_slots); do
315 dosym uwsgi /usr/bin/uwsgi_${s/.}
320 python_foreach_impl python_install_symlinks
321 python_foreach_impl python_domodule uwsgidecorators.py
325 for m in proxy_uwsgi Ruwsgi uwsgi ; do
326 APACHE2_MOD_FILE="${APXS2_S}/.libs/mod_${m}.so"
327 apache-module_src_install
331 newinitd "${FILESDIR}"/uwsgi.initd-r7 uwsgi
332 newconfd "${FILESDIR}"/uwsgi.confd-r4 uwsgi
333 keepdir /etc/"${PN}".d
334 use uwsgi_plugins_spooler && keepdir /var/spool/"${PN}"
338 if use apache2 ; then
339 elog "Three Apache modules have been installed: mod_proxy_uwsgi, mod_uwsgi and mod_Ruwsgi."
340 elog "You can enable them with -D PROXY_UWSGI, -DUWSGI or -DRUWSGI in /etc/conf.d/apache2."
341 elog "mod_uwsgi and mod_Ruwsgi have the same configuration interface and define the same symbols."
342 elog "Therefore you can enable only one of them at a time."
343 elog "mod_uwsgi is commercially supported by Unbit and stable but a bit hacky."
344 elog "mod_Ruwsgi is newer and more Apache-API friendly but not commercially supported."
345 elog "mod_proxy_uwsgi is a proxy module, considered stable and is now the recommended module."
348 elog "Append the following options to the uwsgi call to load the respective language plugin:"
349 use cgi && elog " '--plugins cgi' for cgi"
350 use lua && elog " '--plugins lua' for lua"
351 use perl && elog " '--plugins psgi' for perl"
354 for s in $(php_get_slots); do
355 elog " '--plugins ${s/.}' for ${s}"
359 python_pkg_postinst() {
366 elog " '--plugins ${EPYV}' for ${EPYTHON}"
367 if use python-asyncio ; then
368 if [[ ${EPYV} == python34 ]] ; then
369 elog " '--plugins ${EPYV},asyncio${PYV}' for asyncio support in ${EPYTHON}"
371 elog " (asyncio is only supported in python3.4)"
374 if use python-gevent ; then
375 elog " '--plugins ${EPYV},gevent${PYV}' for gevent support in ${EPYTHON}"
379 use python && python_foreach_impl python_pkg_postinst
382 for ruby in $(ruby_get_use_implementations) ; do
383 elog " '--plugins rack_${ruby/.}' for ${ruby}"
384 elog " '--plugins fiber_${ruby/.}' for ${ruby} fibers"
385 elog " '--plugins rbthreads_${ruby/.}' for ${ruby} rbthreads"