Permalink
Browse files

Imports Ruby's port to NativeClient (a.k.a NaCl).

Patch by Google Inc. [ruby-core:45073].

* configure.in (RUBY_NACL): New M4 func to configure variables for
  NaCl.
  (RUBY_NACL_CHECK_PEPPER_TYPES): New M4 func to check the old names
  of Pepper interface types.
  (BTESTRUBY): New variable to specify which ruby should be run on
  "make btest". NaCl can run the built binary by sel_ldr, but it need
  rbconfig.rb. So this variable is distinguished from $MINIRUBY.
  
* thread_pthread.c: Disabled some features on NaCl.

* io.c: ditto.

* process.c: ditto.

* signal.c: ditto.

* file.c: ditto.

* missing/flock.c: ditto.

* nacl/pepper_main.c: An example implementation of Pepper application
  that embeds Ruby.

* nacl/example.html: An example of web page that uses the Pepper
  application.

* nacl/nacl-config.rb: Detects variants of NaCl SDK.

* nacl/GNUmakefile.in: Makefile template for NaCl specific build
  process.

* nacl/package.rb: script for packaging a NaCl-Ruby embedding
  application. 

* nacl/reate_nmf.rb: Wrapper script of create_nmf.py

* dln.c (dln_load): Added a hack to call on NaCl.

* util.c (ruby_getcwd): Path to the current directort is not available
  on NaCl.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent 0a7aada commit 76bc2d1ed7f13fb329c33f48756ea3c24c59a6ea @yugui yugui committed May 17, 2012
Showing with 1,855 additions and 36 deletions.
  1. +48 −1 ChangeLog
  2. +2 −0 Makefile.in
  3. +1 −1 common.mk
  4. +123 −7 configure.in
  5. +4 −0 dir.c
  6. +15 −0 dln.c
  7. +50 −0 ext/Setup.nacl
  8. +1 −1 ext/extmk.rb
  9. +1 −1 ext/pty/extconf.rb
  10. +22 −0 file.c
  11. +6 −0 gc.c
  12. +2 −2 gc.h
  13. +20 −10 io.c
  14. +0 −1 iseq.c
  15. +2 −1 missing/flock.c
  16. +60 −0 nacl/GNUmakefile.in
  17. +34 −0 nacl/README.nacl
  18. +70 −0 nacl/create_nmf.rb
  19. +15 −0 nacl/dirent.h
  20. +150 −0 nacl/example.html
  21. +7 −0 nacl/ioctl.h
  22. +61 −0 nacl/nacl-config.rb
  23. +109 −0 nacl/package.rb
  24. +924 −0 nacl/pepper_main.c
  25. +8 −0 nacl/resource.h
  26. +7 −0 nacl/select.h
  27. +6 −0 nacl/signal.h
  28. +10 −0 nacl/stat.h
  29. +9 −0 nacl/unistd.h
  30. +11 −0 nacl/utime.h
  31. +29 −8 process.c
  32. +5 −2 signal.c
  33. +9 −1 thread.c
  34. +19 −0 thread_pthread.c
  35. +10 −0 util.c
  36. +4 −0 vm_core.h
  37. +1 −0 win32/Makefile.sub
View
@@ -1,6 +1,53 @@
+Thu May 17 11:33:07 2012 Yuki Yugui Sonoda <yugui@google.com>
+
+ Imports Ruby's port to NativeClient (a.k.a NaCl).
+ Patch by Google Inc. [ruby-core:45073].
+
+ * configure.in (RUBY_NACL): New M4 func to configure variables for
+ NaCl.
+ (RUBY_NACL_CHECK_PEPPER_TYPES): New M4 func to check the old names
+ of Pepper interface types.
+ (BTESTRUBY): New variable to specify which ruby should be run on
+ "make btest". NaCl can run the built binary by sel_ldr, but it need
+ rbconfig.rb. So this variable is distinguished from $MINIRUBY.
+
+ * thread_pthread.c: Disabled some features on NaCl.
+
+ * io.c: ditto.
+
+ * process.c: ditto.
+
+ * signal.c: ditto.
+
+ * file.c: ditto.
+
+ * missing/flock.c: ditto.
+
+ * nacl/pepper_main.c: An example implementation of Pepper application
+ that embeds Ruby.
+
+ * nacl/example.html: An example of web page that uses the Pepper
+ application.
+
+ * nacl/nacl-config.rb: Detects variants of NaCl SDK.
+
+ * nacl/GNUmakefile.in: Makefile template for NaCl specific build
+ process.
+
+ * nacl/package.rb: script for packaging a NaCl-Ruby embedding
+ application.
+
+ * nacl/reate_nmf.rb: Wrapper script of create_nmf.py
+
+ * dln.c (dln_load): Added a hack to call on NaCl.
+
+ * util.c (ruby_getcwd): Path to the current directort is not available
+ on NaCl.
+
Thu May 17 10:54:58 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
- * ext/tk/extconf.rb: add -l options to $libs not $LDFLAGS, to be
+ * ext/tk/extconf.rb: add -l options to $libs not $LDFLAGS,
+ to be
passed to EXTLIBS in exts.mk.
* enc/encinit.c.erb: use %-lines to adjust indent in the generated file.
View
@@ -90,6 +90,8 @@ MINIRUBY = @MINIRUBY@\
$(MINIRUBYOPT)
RUNRUBY = @RUNRUBY@ $(RUNRUBYOPT) -- $(RUN_OPTS)
XRUBY = @XRUBY@
+BTESTRUBY = @BTESTRUBY@\
+ $(MINIRUBYOPT)
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
View
@@ -472,7 +472,7 @@ check-ruby: test test-ruby
btest: $(TEST_RUNNABLE)-btest
no-btest: PHONY
yes-btest: miniruby$(EXEEXT) PHONY
- $(BOOTSTRAPRUBY) "$(srcdir)/bootstraptest/runner.rb" --ruby="$(MINIRUBY)" $(OPTS)
+ $(BOOTSTRAPRUBY) "$(srcdir)/bootstraptest/runner.rb" --ruby="$(BTESTRUBY)" $(OPTS)
btest-ruby: $(TEST_RUNNABLE)-btest-ruby
no-btest-ruby: PHONY
View
@@ -51,6 +51,79 @@ target_cpu=x64
])
])
+AC_DEFUN([RUBY_NACL],
+[
+ AS_CASE(["${host_os}"],
+[nacl], [
+ ac_cv_exeext=.nexe
+ host_vendor=chromium
+ ac_cv_host=chromium
+ AC_MSG_CHECKING([wheather \$NACL_SDK_ROOT is set])
+ if test x"${NACL_SDK_ROOT}" = x; then
+ AC_MSG_RESULT([no])
+ AC_MSG_ERROR([You need to set \$NACL_SDK_ROOT environment variable to build for NativeClient])
+ fi
+ AC_MSG_RESULT([yes])
+
+ nacl_cv_build_variant=glibc
+ AC_ARG_WITH(newlib,
+ AS_HELP_STRING([--with-newlib], [uses newlib version of NativeClient SDK]),
+ [AS_CASE([$withval],
+ [no], [nacl_cv_build_variant=glibc],
+ [yes], [nacl_cv_build_variant=newlib])])
+
+ AS_CASE(["$build_cpu"],
+ [x86_64|i?86], [nacl_cv_cpu_nick=x86], [nacl_cv_cpu_nick=$build_cpu])
+ AS_CASE(["$build_os"],
+ [linux*], [nacl_cv_os_nick=linux],
+ [darwin*], [nacl_cv_os_nick=mac],
+ [cygwin*|mingw*], [nacl_cv_os_nick=win],
+ [nacl_cv_os_nick=$build_os])
+
+ host="$host_cpu-chromium-$host_os-"
+ ac_tool_prefix="$host_cpu-nacl-"
+
+ AC_MSG_CHECKING([NativeClient toolchain])
+ if test -d \
+ "${NACL_SDK_ROOT}/toolchain/${nacl_cv_os_nick}_${nacl_cv_cpu_nick}_${nacl_cv_build_variant}"; then
+ NACL_TOOLCHAIN="${nacl_cv_os_nick}_${nacl_cv_cpu_nick}_${nacl_cv_build_variant}"
+ else
+ AS_CASE(
+ ["${nacl_cv_build_variant}"],
+ [glibc], [if test \
+ -d "${NACL_SDK_ROOT}/toolchain/${nacl_cv_os_nick}_${nacl_cv_cpu_nick}_newlib" \
+ -a -d "${NACL_SDK_ROOT}/toolchain/${nacl_cv_os_nick}_${nacl_cv_cpu_nick}"; then
+ NACL_TOOLCHAIN="${nacl_cv_os_nick}_${nacl_cv_cpu_nick}"
+ fi],
+ [newlib], [ NACL_TOOLCHAIN="${nacl_cv_os_nick}_${nacl_cv_cpu_nick}" ])
+ fi
+ if test ! -e "${NACL_SDK_ROOT}/toolchain/${NACL_TOOLCHAIN}/${ac_tool_prefix}gcc"; then
+ if test "${build_cpu}" = i686 -a -e "${NACL_SDK_ROOT}/toolchain/${NACL_TOOLCHAIN}/nacl-gcc"; then
+ ac_tool_prefix=nacl-
+ fi
+ if test "${build_cpu}" = x86_64 -a -e "${NACL_SDK_ROOT}/toolchain/${NACL_TOOLCHAIN}/nacl-gcc"; then
+ ac_tool_prefix=nacl64-
+ fi
+ fi
+ if test -z "${NACL_TOOLCHAIN}"; then
+ AC_MSG_ERROR([Unrecognized --host and --build combination or NaCl SDK is not installed])
+ fi
+ PATH="${PATH}:${NACL_SDK_ROOT}/toolchain/${NACL_TOOLCHAIN}/bin"
+ AC_MSG_RESULT(${NACL_TOOLCHAIN})
+
+ AC_SUBST(NACL_TOOLCHAIN)
+ AC_SUBST(NACL_SDK_ROOT)
+ AC_SUBST(NACL_SDK_VARIANT, nacl_cv_build_variant)
+])])
+
+AC_DEFUN([RUBY_NACL_CHECK_PEPPER_TYPES],
+[
+ AC_CHECK_TYPES([struct PPB_Core, struct PPB_Messaging, struct PPB_Var,
+ struct PPB_URLLoader, struct PPB_URLRequestInfo,
+ struct PPB_URLResponseInfo, struct PPB_FileRef,
+ struct PPP_Instance])
+])
+
AC_DEFUN([RUBY_CPPOUTFILE],
[AC_CACHE_CHECK(whether ${CPP} accepts -o, rb_cv_cppoutfile,
[cppflags=$CPPFLAGS
@@ -283,6 +356,7 @@ if test -z "${CXXFLAGS+set}"; then
cxxflags="$cxxflags "'${optflags} ${debugflags} ${warnflags}'
fi
+RUBY_NACL
if test x"${build}" != x"${host}"; then
AC_CHECK_TOOL(CC, gcc)
fi
@@ -377,6 +451,7 @@ AC_SUBST(MAKEDIRS)
AC_CHECK_PROGS(DOT, dot)
AC_CHECK_PROGS(DOXYGEN, doxygen)
+AS_CASE(["${host_os}"], [nacl], [AC_PATH_PROG(PYTHON, python)])
AC_CHECK_PROG(PKG_CONFIG, pkg-config, [pkg-config], [], [],
[`"$as_dir/$ac_word$ac_exec_ext" --print-errors --version > /dev/null 2>&1 || echo "$as_dir/$ac_word$ac_exec_ext"`])
@@ -509,7 +584,7 @@ if test "$GCC" = yes; then
# -fstack-protector
AS_CASE(["$target_os"],
- [mingw*], [
+ [mingw*|nacl], [
stack_protector=no
],
[
@@ -1135,6 +1210,14 @@ main()
],
[superux*], [ ac_cv_func_setitimer=no
],
+[nacl], [
+ LIBS="-lm -lnosys $LIBS"
+ if test "${nacl_cv_build_variant}" = "newlib"; then
+ RUBY_APPEND_OPTION(CPPFLAGS, -DNACL_NEWLIB)
+ else
+ RUBY_APPEND_OPTION(XCFLAGS, -fPIC)
+ fi
+ ],
[ LIBS="-lm $LIBS"])
AC_CHECK_LIB(crypt, crypt)
AC_CHECK_LIB(dl, dlopen) # Dynamic linking for SunOS/Solaris and SYSV
@@ -1201,6 +1284,9 @@ AC_CHECK_MEMBERS([struct stat.st_ctimensec])
AC_CHECK_TYPES([struct timespec], [], [], [@%:@ifdef HAVE_TIME_H
@%:@include <time.h>
+@%:@endif
+@%:@ifdef HAVE_SYS_TIME_H
+@%:@include <sys/time.h>
@%:@endif])
AC_CHECK_TYPES([struct timezone], [], [], [@%:@ifdef HAVE_TIME_H
@@ -1263,6 +1349,8 @@ RUBY_DEFINT(intptr_t, void*)
RUBY_DEFINT(uintptr_t, void*, unsigned)
RUBY_DEFINT(ssize_t, size_t, [], [@%:@include <sys/types.h>]) dnl may differ from int, so not use AC_TYPE_SSIZE_T.
+RUBY_NACL_CHECK_PEPPER_TYPES
+
AC_CACHE_CHECK(for stack end address, rb_cv_stack_end_address,
[rb_cv_stack_end_address=no
for addr in __libc_stack_end _SEND; do
@@ -1451,11 +1539,11 @@ AC_CHECK_FUNCS(fmod killpg wait4 waitpid fork spawnv syscall __syscall chroot ge
getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
getpriority getrlimit setrlimit sysconf close getpwnam_r getgrnam_r\
dlopen sigprocmask sigaction sigsetjmp _setjmp _longjmp\
- setsid telldir seekdir fchmod cosh sinh tanh log2 round\
+ setsid telldir seekdir fchmod cosh sinh tanh log2 round llabs\
setuid setgid daemon select_large_fdset setenv unsetenv\
mktime timegm gmtime_r clock_gettime gettimeofday poll ppoll\
pread sendfile shutdown sigaltstack dl_iterate_phdr\
- dup3 pipe2 posix_memalign memalign)
+ dup3 pipe2 posix_memalign memalign ioctl)
AC_CACHE_CHECK(for unsetenv returns a value, rb_cv_unsetenv_return_value,
[AC_TRY_COMPILE([
@@ -1917,7 +2005,8 @@ if test x"$enable_pthread" = xyes; then
pthread_getattr_np pthread_attr_get_np pthread_attr_getstack\
pthread_get_stackaddr_np pthread_get_stacksize_np \
thr_stksegment pthread_stackseg_np pthread_getthrds_np \
- pthread_condattr_setclock pthread_sigmask)
+ pthread_cond_initialize pthread_condattr_setclock pthread_condattr_init \
+ pthread_sigmask)
fi
if test x"$ac_cv_header_ucontext_h" = xyes; then
if test x"$rb_with_pthread" = xyes; then
@@ -2034,11 +2123,14 @@ if test "$rb_cv_binary_elf" = yes; then
if test "$with_dln_a_out" = yes; then
AC_MSG_ERROR(dln_a_out does not work with ELF)
fi
- AC_LIBOBJ([addr2line])
+ AC_CHECK_HEADERS([elf.h elf_abi.h])
+ if test $ac_cv_header_elf_h = yes -o $ac_cv_header_elf_abi_h = yes; then
+ AC_LIBOBJ([addr2line])
+ fi
fi
AS_CASE(["$target_os"],
-[linux* | gnu* | k*bsd*-gnu | bsdi* | kopensolaris*-gnu], [
+[linux* | gnu* | k*bsd*-gnu | bsdi* | kopensolaris*-gnu | nacl], [
if test "$rb_cv_binary_elf" = no; then
with_dln_a_out=yes
else
@@ -2218,6 +2310,7 @@ if test "$with_dln_a_out" != yes; then
rb_cv_dlopen=yes],
[os2-emx*], [ LDFLAGS="$LDFLAGS -Zomf"
],
+ [nacl], [ LDSHARED='$(CC) -shared' ],
[ : ${LDSHARED='$(LD)'}])
AC_MSG_RESULT($rb_cv_dlopen)
fi
@@ -2342,6 +2435,9 @@ AS_CASE(["$target_os"],
[*djgpp*], [
setup=Setup.dj
],
+ [nacl], [
+ setup=Setup.nacl
+ ],
[
setup=Setup
])
@@ -2352,6 +2448,7 @@ if test "$prefix" = NONE; then
prefix=$ac_default_prefix
fi
+BTESTRUBY='$(MINIRUBY)'
if test x"$cross_compiling" = xyes; then
test x"$MINIRUBY" = x && MINIRUBY="${RUBY-$BASERUBY} -I`pwd` "-r'$(arch)-fake'
XRUBY_LIBDIR=`${RUBY-$BASERUBY} -rrbconfig -e ['puts RbConfig::CONFIG["libdir"]']`
@@ -2364,6 +2461,20 @@ if test x"$cross_compiling" = xyes; then
RUNRUBY='$(MINIRUBY) -I`cd $(srcdir)/lib; pwd`'
XRUBY='$(MINIRUBY)'
TEST_RUNNABLE=no
+
+ if test "$host_os" = "nacl"; then
+ if test "$build_cpu" = "$host_cpu" || test "${nacl_cv_cpu_nick}" = "x86" -a "$host_cpu" = "i686"; then
+ nacl_cv_sel_ldr='`$(MINIRUBY) $(srcdir)/nacl/nacl-config.rb sel_ldr`'
+ nacl_cv_irt_core='`$(MINIRUBY) $(srcdir)/nacl/nacl-config.rb irt_core`'
+ nacl_cv_runnable_ld='`$(MINIRUBY) $(srcdir)/nacl/nacl-config.rb runnable_ld`'
+ nacl_cv_host_lib='`$(MINIRUBY) $(srcdir)/nacl/nacl-config.rb host_lib`'
+ TEST_RUNNABLE=yes
+ BTESTRUBY="${nacl_cv_sel_ldr} -a -B ${nacl_cv_irt_core} -w 1:3 -w 2:4"
+ BTESTRUBY="$BTESTRUBY -- ${nacl_cv_runnable_ld} --library-path ${nacl_cv_host_lib}"
+ BTESTRUBY="$BTESTRUBY `pwd`/"'miniruby$(EXEEXT) -I`cd $(srcdir)/lib; pwd` -I.'
+ BTESTRUBY="$BTESTRUBY"' -I$(EXTOUT)/common 3>&1 4>&2 1>/dev/null 2>/dev/null '
+ fi
+ fi
else
MINIRUBY='./miniruby$(EXEEXT) -I$(srcdir)/lib -I.'
MINIRUBY="$MINIRUBY"' -I$(EXTOUT)/common'
@@ -2374,6 +2485,7 @@ else
fi
AC_SUBST(TEST_RUNNABLE)
AC_SUBST(MINIRUBY)
+AC_SUBST(BTESTRUBY)
AC_SUBST(PREP)
AC_SUBST(RUNRUBY)
AC_SUBST(XRUBY)
@@ -2600,6 +2712,7 @@ AC_CACHE_CHECK([for prefix of external symbols], rb_cv_symbol_prefix, [
SYMBOL_PREFIX="$rb_cv_symbol_prefix"
test "x$SYMBOL_PREFIX" = xNONE && SYMBOL_PREFIX=''
MINIDLNOBJ=dmydln.o
+
AS_CASE(["$target_os"],
[linux*], [
],
@@ -2679,7 +2792,10 @@ AS_CASE(["$target_os"],
AS_CASE(["$YACC"],[*yacc*], [
XCFLAGS="$XCFLAGS -DYYMAXDEPTH=300"
YACC="$YACC -Nl40000 -Nm40000"
- ])])
+ ])],
+ [nacl], [
+ FIRSTMAKEFILE=GNUmakefile:nacl/GNUmakefile.in
+ ])
MINIOBJS="$MINIDLNOBJ"
AS_CASE(["$THREAD_MODEL"],
View
@@ -44,6 +44,10 @@
# include "win32/dir.h"
# endif
#endif
+#if defined(__native_client__) && defined(NACL_NEWLIB)
+# include "nacl/dirent.h"
+# include "nacl/stat.h"
+#endif
#include <errno.h>
View
@@ -1318,13 +1318,28 @@ dln_load(const char *file)
# define RTLD_GLOBAL 0
#endif
+#ifdef __native_client__
+ char* p, *orig;
+ if (file[0] == '.' && file[1] == '/') file+=2;
+ orig = strdup(file);
+ for (p = file; *p; ++p) {
+ if (*p == '/') *p = '_';
+ }
+#endif
/* Load file */
if ((handle = (void*)dlopen(file, RTLD_LAZY|RTLD_GLOBAL)) == NULL) {
+#ifdef __native_client__
+ free(orig);
+#endif
error = dln_strerror();
goto failed;
}
init_fct = (void(*)())(VALUE)dlsym(handle, buf);
+#ifdef __native_client__
+ strcpy(file, orig);
+ free(orig);
+#endif
#if defined __SYMBIAN32__
if (init_fct == NULL) {
init_fct = (void(*)())dlsym(handle, "1"); /* Some Symbian versions do not support symbol table in DLL, ordinal numbers only */
Oops, something went wrong.

0 comments on commit 76bc2d1

Please sign in to comment.