]> xenbits.xensource.com Git - unikraft/libs/ruby.git/commitdiff
Provide main() function if configured to do so
authorCostin Lupu <costin.lupu@cs.pub.ro>
Mon, 16 Dec 2019 13:47:52 +0000 (15:47 +0200)
committerCostin Lupu <costin.lupu@cs.pub.ro>
Mon, 16 Dec 2019 13:54:35 +0000 (15:54 +0200)
We provide a configurable main() function for running Ruby out-of-the-box and
also for showing an example of such a function to be used by custom
applications. It also sets the necessary Ruby environment variables.

Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
Reviewed-by: Stefan Teodorescu <stefanl.teodorescu@gmail.com>
Config.uk
Makefile.uk
ruby_main_example.c [new file with mode: 0644]

index e47eee3184482ace298bbe9129773b241136f3d6..e163687106e7d4bd3976b41e94dc118be11f0971 100644 (file)
--- a/Config.uk
+++ b/Config.uk
@@ -22,6 +22,16 @@ config LIBRUBY_MINI
        bool "Mini configuration"
        default n
 
+config LIBRUBY_MAIN_FUNCTION
+       bool "Provide main function"
+       imply LIBUKLIBPARAM
+       imply LIBVFSCORE_AUTOMOUNT_ROOTFS
+       imply LIBVFSCORE_ROOTFS_9PFS
+       imply LIBDEVFS_AUTOMOUNT
+       imply LIBDEVFS_DEV_NULL
+       imply LIBUK9P
+       default n
+
 config LIBRUBY_EXT
        bool "Enable extensions"
        depends on !LIBRUBY_MINI
index 9abef23a31e2607abf7961bce8eb6f032bdfe4ef..946afef1ac8ee0e066895194774f32a67d4e0fa8 100644 (file)
@@ -96,6 +96,8 @@ LIBRUBY_CFLAGS-y += -std=gnu99 -D_FORTIFY_SOURCE=2 \
        -DRUBY_EXPORT -DCANONICALIZATION_FOR_MATHN
 
 LIBRUBY_SRCS-y += $(LIBRUBY_BASE)/thread.c|unikraft
+LIBRUBY_SRCS-$(CONFIG_LIBRUBY_MAIN_FUNCTION) += $(LIBRUBY_BASE)/ruby_main_example.c|unikraft
+LIBRUBY_RUBY_MAIN_EXAMPLE_FLAGS-y = -DLIBRUBY_VERSION_LONG=\"$(LIBRUBY_VERSION_LONG)\"
 
 ifeq ($(CONFIG_LIBRUBY_MINI),y)
 LIBRUBY_SRCS-y += $(LIBRUBY_SRC)/dmydln.c
diff --git a/ruby_main_example.c b/ruby_main_example.c
new file mode 100644 (file)
index 0000000..33bf033
--- /dev/null
@@ -0,0 +1,15 @@
+#include <stdlib.h>
+
+extern int ruby_main(int argc, char *argv[]);
+
+int main(int argc, char *argv[])
+{
+       setenv("GEM_HOME", "/lib/ruby/gems/"LIBRUBY_VERSION_LONG, 0);
+       setenv("GEM_PATH", "/lib/ruby/gems/"LIBRUBY_VERSION_LONG, 0);
+       setenv("RUBYGEMS_GEMDEPS", "/lib/ruby/"LIBRUBY_VERSION_LONG"/Gemfile", 0);
+       setenv("RUBYLIB", "/lib/ruby/"LIBRUBY_VERSION_LONG":"
+               "/lib/ruby/"LIBRUBY_VERSION_LONG"/x86_64-linux:"
+               "/lib/ruby/"LIBRUBY_VERSION_LONG"/.ext", 0);
+
+       return ruby_main(argc, argv);
+}