Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions auto/help
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ cat << END
go OPTIONS configure Go module
run "./configure go --help" to see available options

ruby OPTIONS configure Ruby module
run "./configure ruby --help" to see available options

END
3 changes: 3 additions & 0 deletions auto/make
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ ${NXT_DAEMON}-uninstall:

END

if [ $NXT_RUBY_MODULE != NO ]; then
. auto/modules/ruby/make
fi

# Makefile.
# *.dSYM is MacOSX Clang debug information.
Expand Down
5 changes: 4 additions & 1 deletion auto/modules/conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright (C) Igor Sysoev
# Copyright (C) NGINX, Inc.


case "$nxt_module" in

python)
Expand All @@ -17,6 +16,10 @@ case "$nxt_module" in
. auto/modules/go
;;

ruby)
. auto/modules/ruby
;;

*)
echo
echo $0: error: invalid module \"$nxt_module\".
Expand Down
175 changes: 175 additions & 0 deletions auto/modules/ruby
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@

# Copyright (C) Fedor Sakharov


shift

for nxt_option; do

case "$nxt_option" in
-*=*) value=`echo "$nxt_option" | sed -e 's/[-_a-zA-Z0-9]*=//'` ;;
*) value="" ;;
esac

case "$nxt_option" in
--config=*) NXT_RUBY_CONFIG="$value" ;;
--module=*) NXT_RUBY_MODULE="$value" ;;
--lib-path=*) NXT_RUBY_LIB_PATH="$value" ;;

--help)
cat << END

--config=FILE set ruby-config filename
--module=NAME set unit ruby module name
--lib-path=DIRECTORY set directory path to libruby.so library

END
exit 0
;;

*)
echo
echo $0: error: invalid RUBY option \"$nxt_option\"
echo
exit 1
;;

esac

done


if [ ! -f $NXT_AUTOCONF_DATA ]; then
echo
echo Please run common $0 before configuring module \"$nxt_module\".
echo
exit 1
fi

. $NXT_AUTOCONF_DATA


NXT_RUBY_CONFIG=${NXT_RUBY_CONFIG=ruby-config}
NXT_RUBY=${NXT_RUBY_CONFIG%-config*}
NXT_RUBY_MODULE=${NXT_RUBY_MODULE=${NXT_RUBY##*/}}
NXT_RUBY_LIB_PATH=${NXT_RUBY_LIB_PATH=}


$echo "configuring RUBY module"
$echo "configuring RUBY module ..." >> $NXT_AUTOCONF_ERR

$echo -n "checking for RUBY ..."
$echo "checking for RUBY ..." >> $NXT_AUTOCONF_ERR


NXT_RUBY_LDFLAGS=

if /bin/sh -c "ruby --version" >> $NXT_AUTOCONF_ERR 2>&1; then

$echo " found"

NXT_RUBY_VERSION="`ruby --version`"
$echo " + RUBY version: ${NXT_RUBY_VERSION}"

NXT_RUBY_INCLUDE="-I/usr/include/ruby-2.3.0/ -I/usr/include/x86_64-linux-gnu/ruby-2.3.0/"
NXT_RUBY_LIB="-lruby-2.3"

if [ "$NXT_RUBY_LIB_PATH" != "" ]; then
NXT_RUBY_LDFLAGS="-L${NXT_RUBY_LIB_PATH} -Wl,-rpath ${NXT_RUBY_LIB_PATH}"
fi

nxt_feature="RUBY embed RACK"
nxt_feature_name=NXT_HAVE_RUBY
nxt_feature_run=no
nxt_feature_incs="${NXT_RUBY_INCLUDE}"
nxt_feature_libs="${NXT_RUBY_LIB} ${NXT_RUBY_LDFLAGS}"
nxt_feature_test="
#include <ruby.h>

int main() {
ruby_setup();
return 0;
}"

. auto/feature

if [ $nxt_found = no ]; then
$echo
$echo $NXT_RUBY_LDFLAGS
$echo $NXT_RUBY_INCLUDE
$echo $0: error: no RUBY embed RACK found.
$echo
exit 1;
fi

else
$echo
$echo $0: error: no RUBY found.
$echo
exit 1;
fi

if grep ^$NXT_RUBY_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then
$echo
$echo $0: error: duplicate \"$NXT_RUBY_MODULE\" module configured
$echo
exit 1;
fi

$echo " + RUBY module: ${NXT_RUBY_MODULE}.unit.so"

$echo >> $NXT_MAKEFILE

NXT_RUBY_MODULES_SRCS=" \
src/nxt_ruby_rack.c
"

# The ruby module object files

nxt_objs=

for nxt_src in $NXT_RUBY_MODULES_SRCS; do

nxt_obj=`$echo $nxt_src | sed -e "s/\.c$/-$NXT_RUBY_MODULE.o/"`
nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj"

cat << END >> $NXT_MAKEFILE

$NXT_BUILD_DIR/$nxt_obj: $nxt_src
\$(CC) -c \$(CFLAGS) \$(NXT_INCS) $NXT_RUBY_INCLUDE \\
-o $NXT_BUILD_DIR/$nxt_obj $nxt_src
END

done


cat << END >> $NXT_MAKEFILE

.PHONY: ${NXT_RUBY_MODULE}
.PHONY: ${NXT_RUBY_MODULE}-install
.PHONY: ${NXT_RUBY_MODULE}-uninstall

all: ${NXT_RUBY_MODULE}

${NXT_RUBY_MODULE}: $NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so

$NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so: $nxt_objs
$NXT_MODULE_LINK -o $NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so \\
$nxt_objs ${NXT_RUBY_LIB} ${NXT_RUBY_LDFLAGS}


install: ${NXT_RUBY_MODULE}-install

${NXT_RUBY_MODULE}-install: ${NXT_RUBY_MODULE}
install -d \$(DESTDIR)$NXT_MODULES
install -p $NXT_BUILD_DIR/${NXT_RUBY_MODULE}.unit.so \\
\$(DESTDIR)$NXT_MODULES/


uninstall: ${NXT_RUBY_MODULE}-uninstall

${NXT_RUBY_MODULE}-uninstall:
rm -f \$(DESTDIR)$NXT_MODULES/${NXT_RUBY_MODULE}.unit.so
@rmdir -p \$(DESTDIR)$NXT_MODULES 2>/dev/null || true

END
6 changes: 6 additions & 0 deletions auto/options
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ NXT_TEST_BUILD_HPUX_SENDFILE=NO

NXT_TESTS=NO

NXT_RUBY=ruby
NXT_RUBY_MODULE=NO

for nxt_option
do
case "$nxt_option" in
Expand Down Expand Up @@ -97,6 +100,9 @@ do
exit 0
;;

--with-ruby=*) NXT_RUBY="$value" ;;
--with-ruby_module) NXT_RUBY_MODULE=YES ;;

*)
$echo
$echo $0: error: invalid option \"$nxt_option\".
Expand Down
3 changes: 3 additions & 0 deletions src/nxt_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,9 @@ nxt_app_parse_type(u_char *p, size_t length)
} else if (nxt_str_eq(&str, "go", 2)) {
return NXT_APP_GO;

} else if (nxt_str_eq(&str, "ruby", 4)) {
return NXT_APP_RUBY;

}

return NXT_APP_UNKNOWN;
Expand Down
6 changes: 6 additions & 0 deletions src/nxt_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ typedef enum {
NXT_APP_PYTHON,
NXT_APP_PHP,
NXT_APP_GO,
NXT_APP_RUBY,

NXT_APP_UNKNOWN,
} nxt_app_type_t;
Expand Down Expand Up @@ -50,6 +51,10 @@ typedef struct {
char *executable;
} nxt_go_app_conf_t;

typedef struct {
nxt_str_t index;
nxt_str_t root;
} nxt_ruby_app_conf_t;

struct nxt_common_app_conf_s {
nxt_str_t name;
Expand All @@ -65,6 +70,7 @@ struct nxt_common_app_conf_s {
nxt_python_app_conf_t python;
nxt_php_app_conf_t php;
nxt_go_app_conf_t go;
nxt_ruby_app_conf_t ruby;
} u;
};

Expand Down
26 changes: 26 additions & 0 deletions src/nxt_conf_validation.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,31 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_go_members[] = {
};


static nxt_conf_vldt_object_t nxt_conf_vldt_ruby_members[] = {
{ nxt_string("type"),
NXT_CONF_STRING,
NULL,
NULL, },

{ nxt_string("workers"),
NXT_CONF_INTEGER,
NULL,
NULL },

{ nxt_string("rack_root"),
NXT_CONF_STRING,
NULL,
NULL, },

{ nxt_string("rack_script"),
NXT_CONF_STRING,
NULL,
NULL, },

{ nxt_null_string, 0, NULL, NULL }
};


nxt_int_t
nxt_conf_validate(nxt_conf_validation_t *vldt)
{
Expand Down Expand Up @@ -364,6 +389,7 @@ nxt_conf_vldt_app(nxt_conf_validation_t *vldt, nxt_str_t *name,
nxt_conf_vldt_python_members,
nxt_conf_vldt_php_members,
nxt_conf_vldt_go_members,
nxt_conf_vldt_ruby_members,
};

ret = nxt_conf_vldt_type(vldt, name, value, NXT_CONF_OBJECT);
Expand Down
14 changes: 13 additions & 1 deletion src/nxt_main_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ static nxt_conf_map_t nxt_common_app_conf[] = {
NXT_CONF_MAP_CSTRZ,
offsetof(nxt_common_app_conf_t, u.go.executable),
},

{
nxt_string("rack_script"),
NXT_CONF_MAP_STR,
offsetof(nxt_common_app_conf_t, u.ruby.index),
},

{
nxt_string("rack_root"),
NXT_CONF_MAP_STR,
offsetof(nxt_common_app_conf_t, u.ruby.root),
}
};


Expand Down Expand Up @@ -1058,7 +1070,7 @@ nxt_main_port_modules_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
return;
}

nxt_debug(task, "application languages: \"%*s\"",
nxt_log(task, NXT_LOG_ALERT, "application languages: \"%*s\"",
b->mem.free - b->mem.pos, b->mem.pos);

conf = nxt_conf_json_parse(mp, b->mem.pos, b->mem.free, NULL);
Expand Down
Loading