rails-engine/script_core

Trying to add mruby-httprequest

tdegrunt opened this issue · 6 comments

Trying to add https://github.com/matsumotory/mruby-httprequest, to script_core's mruby.

Steps:

  1. bundle exec rake app:script_core:engine:new
  2. Edited the gembox file to include github: 'matsumotory/mruby-httprequest'
  3. bundle exec rake app:script_core:engine:build

Last bit of output of step 3:

CC    mrbgems/mruby-io/src/file.c -> build/sandbox/mrbgems/mruby-io/src/file.o
/Users/tdegrunt/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/script_core-0.2.1/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file.c:139:7: error: implicit
      declaration of function 'rename' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  if (rename(src, dst) < 0) {
      ^
/Users/tdegrunt/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/script_core-0.2.1/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file.c:139:7: note: did you mean
      'devname'?
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdlib.h:293:7: note: 'devname' declared here
char    *devname(dev_t, mode_t);
         ^
1 error generated.
rake aborted!

Command Failed: [gcc -std=gnu99 -g -O3 -Wall -Wundef -Wdeclaration-after-statement -Werror-implicit-function-declaration -Wwrite-strings -g3 -O0 -fPIC -g3 -O3 -DMRB_DEBUG -D_GNU_SOURCE -DMRB_ENABLE_DEBUG_HOOK -DMRB_INT64 -DMRB_UTF8_STRING -DMRB_WORD_BOXING -DYYDEBUG -DMRB_DISABLE_STDIO -DMRBGEM_MRUBY_IO_VERSION=0.0.0 -I/Users/tdegrunt/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/script_core-0.2.1/ext/enterprise_script_service/mruby/include -I/Users/tdegrunt/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/script_core-0.2.1/ext/enterprise_script_service/mruby/src -I/Users/tdegrunt/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/script_core-0.2.1/ext/enterprise_script_service/mruby/mrbgems/mruby-io/include -MMD -o /Users/tdegrunt/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/script_core-0.2.1/ext/enterprise_script_service/mruby/build/sandbox/mrbgems/mruby-io/src/file.o -c /Users/tdegrunt/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/script_core-0.2.1/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file.c]

This is on macOS. Any idea what causes this? Is this a too new gcc?

jasl commented

I'm not sure mruby-httprequest support mruby 2.1, because its last update is in 3 years ago...

Could you try to downgrade script_core to 0.0.6 to see what happend? maybe it works

jasl commented

Ok I did some research, don't know why mruby-io can't compile, I'm not experienced on C, called friend for help

jasl commented

image

OK, finally let it work, because LLVM-macOS should include stdio.h by default, but GCC not, so adding #include <stdio.h> to mruby/mrbgems/mruby-io/src/file.c will work.

I'll send a PR to mruby, don't know this is the right way.

You need put these in to your gembox:

conf.gem core: "mruby-sprintf"
conf.gem mgem: "mruby-httprequest"

and you have to give a long timeout throttle because 1 second is too short for network IO, and keep in mind that mruby is running syncronizingly which means it will blocking your program until return or timeout.

Thank you give this issue that let me know IO works in the sandbox.

jasl commented

Unforunatly ESS opened MRB_DISABLE_STDIO flag made mruby-io compiling failed.

Although we can give an option to remove that, but that would lead the sandbox vulnerble.

what do you think?

Was just about to try this out. It would be nice to have this option, but indeed vulnerable sandboxes make no sense. Let's not. I'll think of another way! Shall I close this ticket?

Really enjoy using this gem!

jasl commented

Was just about to try this out. It would be nice to have this option, but indeed vulnerable sandboxes make no sense. Let's not. I'll think of another way! Shall I close this ticket?

Really enjoy using this gem!

Thank you for reply! I close the issue