rubyjs / therubyracer

Embed the V8 Javascript Interpreter into Ruby
1.66k stars 192 forks source link

Does not build on OSX mavericks with ruby 1.9.3-p194 #277

Closed banister closed 9 years ago

banister commented 10 years ago

I talked to @mpapis (from #rvm channel on freenode) and he stated it was due to therubyracer not using the CC variable from Ruby:

Installing therubyracer (0.10.2) 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /Users/johnmair/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb 
checking for main() in -lobjc... yes
creating Makefile

make
compiling rr.cpp
clang: warning: argument unused during compilation: '-rdynamic'
rr.cpp:48:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
rr.cpp:151:44: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
    return String::New(RSTRING_PTR(value), RSTRING_LEN(value));
           ~~~~~~                          ^~~~~~~~~~~~~~~~~~
/Users/johnmair/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:674:6: note: expanded from macro 'RSTRING_LEN'
     RSTRING_EMBED_LEN(str) : \
     ^~~~~~~~~~~~~~~~~~~~~~
/Users/johnmair/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:670:6: note: expanded from macro 'RSTRING_EMBED_LEN'
     (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rr.cpp:151:44: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
    return String::New(RSTRING_PTR(value), RSTRING_LEN(value));
           ~~~~~~                          ^~~~~~~~~~~~~~~~~~
/Users/johnmair/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:675:28: note: expanded from macro 'RSTRING_LEN'
     RSTRING(str)->as.heap.len)
     ~~~~~~~~~~~~~~~~~~~~~~^~~
3 warnings generated.
compiling v8.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_array.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_callbacks.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_context.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_date.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_debug.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_exception.cpp
clang: warning: argument unused during compilation: '-rdynamic'
v8_exception.cpp:10:16: warning: unused variable 'stack' [-Wunused-variable]
  static void* stack[20];
               ^
1 warning generated.
compiling v8_external.cpp
clang: warning: argument unused during compilation: '-rdynamic'
v8_external.cpp:10:9: warning: unused variable 'references' [-Wunused-variable]
  VALUE references;
        ^
1 warning generated.
compiling v8_function.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_handle.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_locker.cpp
clang: warning: argument unused during compilation: '-rdynamic'
v8_locker.cpp:45:5: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^
v8_locker.cpp:85:5: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^
2 warnings generated.
compiling v8_message.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_object.cpp
clang: warning: argument unused during compilation: '-rdynamic'
v8_object.cpp:77:19: warning: unused variable 'proto' [-Wunused-variable]
    Handle<Value> proto(rr_rb2v8(prototype));
                  ^
1 warning generated.
compiling v8_script.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_string.cpp
clang: warning: argument unused during compilation: '-rdynamic'
v8_string.cpp:18:73: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
    return rr_v8_handle_new(string_class, String::New(RSTRING_PTR(str), RSTRING_LEN(str)));
                                          ~~~~~~                        ^~~~~~~~~~~~~~~~
/Users/johnmair/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:674:6: note: expanded from macro 'RSTRING_LEN'
     RSTRING_EMBED_LEN(str) : \
     ^~~~~~~~~~~~~~~~~~~~~~
/Users/johnmair/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:670:6: note: expanded from macro 'RSTRING_EMBED_LEN'
     (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
v8_string.cpp:18:73: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
    return rr_v8_handle_new(string_class, String::New(RSTRING_PTR(str), RSTRING_LEN(str)));
                                          ~~~~~~                        ^~~~~~~~~~~~~~~~
/Users/johnmair/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:675:28: note: expanded from macro 'RSTRING_LEN'
     RSTRING(str)->as.heap.len)
     ~~~~~~~~~~~~~~~~~~~~~~^~~
v8_string.cpp:23:79: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
    return rr_v8_handle_new(string_class, String::NewSymbol(RSTRING_PTR(str), RSTRING_LEN(str)));
                                          ~~~~~~                              ^~~~~~~~~~~~~~~~
/Users/johnmair/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:674:6: note: expanded from macro 'RSTRING_LEN'
     RSTRING_EMBED_LEN(str) : \
     ^~~~~~~~~~~~~~~~~~~~~~
/Users/johnmair/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:670:6: note: expanded from macro 'RSTRING_EMBED_LEN'
     (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
v8_string.cpp:23:79: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
    return rr_v8_handle_new(string_class, String::NewSymbol(RSTRING_PTR(str), RSTRING_LEN(str)));
                                          ~~~~~~                              ^~~~~~~~~~~~~~~~
/Users/johnmair/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:675:28: note: expanded from macro 'RSTRING_LEN'
     RSTRING(str)->as.heap.len)
     ~~~~~~~~~~~~~~~~~~~~~~^~~
4 warnings generated.
compiling v8_template.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_try_catch.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_v8.cpp
clang: warning: argument unused during compilation: '-rdynamic'
v8_v8.cpp:22:49: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
    V8::SetFlagsFromString(RSTRING_PTR(string), RSTRING_LEN(string));
    ~~                                          ^~~~~~~~~~~~~~~~~~~
/Users/johnmair/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:674:6: note: expanded from macro 'RSTRING_LEN'
     RSTRING_EMBED_LEN(str) : \
     ^~~~~~~~~~~~~~~~~~~~~~
/Users/johnmair/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:670:6: note: expanded from macro 'RSTRING_EMBED_LEN'
     (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
v8_v8.cpp:22:49: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
    V8::SetFlagsFromString(RSTRING_PTR(string), RSTRING_LEN(string));
    ~~                                          ^~~~~~~~~~~~~~~~~~~
/Users/johnmair/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:675:28: note: expanded from macro 'RSTRING_LEN'
     RSTRING(str)->as.heap.len)
     ~~~~~~~~~~~~~~~~~~~~~~^~~
2 warnings generated.
compiling v8_value.cpp
clang: warning: argument unused during compilation: '-rdynamic'
v8_value.cpp:100:9: warning: unused function 'ToInt32' [-Wunused-function]
  VALUE ToInt32(VALUE self) {
        ^
1 warning generated.
compiling v8_weakref.cpp
clang: warning: argument unused during compilation: '-rdynamic'
linking shared-object v8.bundle
clang: error: no such file or directory: '/Users/johnmair/.rvm/gems/ruby-1.9.3-p194/gems/libv8-3.3.10.4/lib/libv8/build/v8/libv8.a'
make: *** [v8.bundle] Error 1

Gem files will remain installed in /Users/johnmair/.rvm/gems/ruby-1.9.3-p194/gems/therubyracer-0.10.2 for inspection.
Results logged to /Users/johnmair/.rvm/gems/ruby-1.9.3-p194/gems/therubyracer-0.10.2/ext/v8/gem_make.out

An error occurred while installing therubyracer (0.10.2), and Bundler cannot continue.
Make sure that `gem install therubyracer -v '0.10.2'` succeeds before bundling.
joepestro commented 10 years ago

+1

cowboyd commented 10 years ago

@mpapis can you elaborate? For the most part, we're just deferring to mkmf. I'm not aware of where we should be using the CC variable.

https://github.com/cowboyd/therubyracer/blob/master/ext/v8/extconf.rb

cowboyd commented 10 years ago

That said, on my fresh mavericks install:

~/C/therubyracer git:master ❯❯❯ ruby -v                                                            ⏎
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin13.0.2]
~/C/therubyracer git:master ❯❯❯ rake compile
mkdir -p tmp/x86_64-darwin13.0.2/init/1.9.3
cd tmp/x86_64-darwin13.0.2/init/1.9.3
/Users/cowboyd/.rbenv/versions/1.9.3-p448/bin/ruby -I. ../../../../ext/v8/extconf.rb
checking for main() in -lpthread... yes
checking for main() in -lobjc... yes
creating Makefile
cd -
cd tmp/x86_64-darwin13.0.2/init/1.9.3
make
compiling ../../../../ext/v8/accessor.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/array.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/backref.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/constants.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/constraints.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/context.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/date.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/exception.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/external.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/function.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/gc.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/handles.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/heap.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/init.cc
clang: warning: argument unused during compilation: '-rdynamic'
../../../../ext/v8/init.cc:11:20: warning: empty parentheses interpreted as a function declaration
      [-Wvexing-parse]
    v8::Locker lock();
                   ^~
../../../../ext/v8/init.cc:11:20: note: remove parentheses to declare a variable
    v8::Locker lock();
                   ^~
../../../../ext/v8/init.cc:11:16: warning: 'lock' has C-linkage specified, but returns user-defined
      type 'v8::Locker' which is incompatible with C [-Wreturn-type-c-linkage]
    v8::Locker lock();
               ^
2 warnings generated.
compiling ../../../../ext/v8/invocation.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/locker.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/message.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/object.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/primitive.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/rr.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/script.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/signature.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/stack.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/string.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/template.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/trycatch.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/v8.cc
clang: warning: argument unused during compilation: '-rdynamic'
compiling ../../../../ext/v8/value.cc
clang: warning: argument unused during compilation: '-rdynamic'
linking shared-object v8/init.bundle
cd -
install -c tmp/x86_64-darwin13.0.2/init/1.9.3/init.bundle lib/v8/init.bundle
cp tmp/x86_64-darwin13.0.2/init/1.9.3/init.bundle tmp/x86_64-darwin13.0.2/stage/lib/v8/init.bundle
~/C/therubyracer git:master ❯❯❯ rake spec
/Users/cowboyd/.rbenv/versions/1.9.3-p448/bin/ruby -S rspec ./spec/c/array_spec.rb ./spec/c/constants_spec.rb ./spec/c/exception_spec.rb ./spec/c/external_spec.rb ./spec/c/function_spec.rb ./spec/c/handles_spec.rb ./spec/c/locker_spec.rb ./spec/c/object_spec.rb ./spec/c/script_spec.rb ./spec/c/string_spec.rb ./spec/c/template_spec.rb ./spec/c/trycatch_spec.rb ./spec/mem/blunt_spec.rb ./spec/redjs_spec.rb ./spec/threading_spec.rb ./spec/v8/context_spec.rb ./spec/v8/conversion_spec.rb ./spec/v8/error_spec.rb ./spec/v8/function_spec.rb ./spec/v8/object_spec.rb --tag ~memory --tag ~threads
Run options: exclude {:memory=>true, :threads=>true}
..............................*......................

Pending:
  V8::Context not ready for prime-time
    # No reason given
    # ./spec/redjs_spec.rb:8

Finished in 0.03456 seconds
53 examples, 0 failures, 1 pending
mpapis commented 10 years ago

@cowboyd this happens on older patchlevels then p448, they were not possible to build with clang and gcc-4.x was used for them, unfortunately therubyracer did not use the CC ruby and instead tried to compile with clang

anyway ruby 1.9.3 any patchlevel even if you were able to compile it with clang can still have runtime issues and you would be safer recompiling it with gnu gcc

@banister can you run this one:

rvm config-get --all | grep -E 'CPP|CXX|CC|gcc|clang'
banister commented 10 years ago

@mpapis

$ rvm config-get --all | grep -E 'CPP|CXX|CC|gcc|clang'
CC: /usr/local/opt/apple-gcc42/bin/gcc-4.2
CCDLFLAGS: -fno-common
CPP: /usr/local/opt/apple-gcc42/bin/gcc-4.2 -E
CPPFLAGS: -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE  
CPPOUTFILE: -o conftest.i
CXX: g++
CXXFLAGS:  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement -Werror=shorten-64-to-32 -Werror=implicit-function-declaration
GCC: yes
LDSHARED: /usr/local/opt/apple-gcc42/bin/gcc-4.2 -dynamic -bundle
LIBRUBY_LDSHARED: /usr/local/opt/apple-gcc42/bin/gcc-4.2 -dynamiclib
configure_args:  '--prefix=/Users/johnmair/.rvm/rubies/ruby-1.9.3-p194' '--with-opt-dir=/usr/local/opt/libyaml' '--without-tcl' '--without-tk' '--enable-shared' 'CC=/usr/local/opt/apple-gcc42/bin/gcc-4.2' 'CFLAGS=-O3 -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include' 'LDFLAGS=-L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib'
mpapis commented 10 years ago

it looks like the problem could be https://github.com/cowboyd/therubyracer/blob/master/ext/v8/extconf.rb#L10

alecslupu commented 10 years ago

same on ruby-1.9.3-p448

rvm config-get --all | grep -E 'CPP|CXX|CC|gcc|clang'
CC: /usr/local/bin/gcc-4.2
CCDLFLAGS: -fno-common
CPP: /usr/local/bin/gcc-4.2 -E
CPPFLAGS: -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include
CPPOUTFILE: -o conftest.i
CXX: g++
CXXFLAGS:  -O3 -ggdb -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration
GCC: yes
LDSHARED: /usr/local/bin/gcc-4.2 -dynamic -bundle
LIBRUBY_LDSHARED: /usr/local/bin/gcc-4.2 -dynamiclib
configure_args:  '--prefix=/Users/alecslupu/.rvm/rubies/ruby-1.9.3-p448' '--with-opt-dir=/usr/local/opt/libyaml:/usr/local/opt/readline:/usr/local/opt/libksba:/usr/local/opt/openssl' '--without-tcl' '--without-tk' '--enable-shared' 'CC=/usr/local/bin/gcc-4.2'
alecslupu commented 10 years ago

I got it fixed by a dumb solution:

brew install v8
bundle install 
# after failing go to 
cd /Users/alecslupu/.rvm/gems/ruby-1.9.3-p448@my_gemset/gems/libv8-3.3.10.4/lib/libv8/build/v8
ln -s /usr/local/Cellar/v8/3.21.17/lib/libv8_base.x64.a ./libv8.a
bundle update

Aparently the problem is in libv8 (3.3.10.4) gem that is not building on a mavericks system, for that reason the "libv8.a" is never created.

cowboyd commented 10 years ago

@mpapis hmmm... That line should never get used on OSX systems since it does an explicit check for /darwin/ in the RUBY_PLATFORM

mpapis commented 10 years ago

I do not have right now access to an OSX system, would need to see resulting Makefile and check some code to tell you more, something makes it use clang instead of gcc-4.2 which was set in CC

ashblue commented 10 years ago

I tried a few of the above solutions, but still no fix. Any progress on a more permanent patch?

Edit: At work we've remove this gem from our current workflow temporarily since multiple people seem to be having the same issue.

alecslupu commented 10 years ago

@ashblue have you tried the "fix" i have proposed?

ashblue commented 10 years ago

Yes, "bundle install" would run correctly. But "rails s" would crash saying that therubyracer was not installed.

michaelharro commented 10 years ago

Newer versions of libv8 build on mavericks. Is it possible to update libv8?

ignisf commented 10 years ago

@michaelharro, could you me more specific? Which versions exactly?

michaelharro commented 10 years ago

@ignisf sure. We have a project that uses libv8. We were using gem 'libv8', '=3.11.8.17' and couldn't build on mavericks. I saw this http://stackoverflow.com/a/19586282 so I did some trial and error. I couldn't get any of the 3.11 versions to build on mavericks but all the 3.16 versions I tried worked just fine. So somewhere between 3.11.8.17 and 3.16 it was fixed.

valachi commented 10 years ago

I was the having the same issue with 0.10.1 and 0.10.2 on OSX Mavericks. @alecslupu's fix worked for me, but rails s, as well as rake db:create and several other commands would fail with uninitialized constant V8::JSError

alecslupu commented 10 years ago

@valachi I am running Rails 3.2.12 And i don't have any issues ... and therubyracer (0.10.2)

ignisf commented 10 years ago

@valachi, yes, there are a bunch of fixes in the 3.16 tree. I have released a binary version for Mavericks of libv8 3.11.8.17 so you should be able to use it without the need to compile. We will probably release a new version in the 3.11 branch once the new changes in the 3.16 branch prove to be stable.

matthewford commented 10 years ago

I'm also seeing a segfault when trying to require rubyracer/libv8 on mavericks. Managed to install them fine.

https://gist.github.com/matthewford/7915332

mjjohnson commented 10 years ago

I tried the symlink solution, as well as upgrading to newer versions of both libv8 and therubyracer, and wasn't having any success. However, I found another solution in http://stackoverflow.com/a/20145328/275058 and it seems to work great for me!

ignisf commented 10 years ago

@mjjohnson did you try the latest version in the libv8 master branch? The patches necessary for compilation with clang and GCC 4.2 are in and need to be tested before we release.

mjjohnson commented 10 years ago

@ignisf I hadn't tried that yet. :) I'm just getting an existing project running on my local box, and so for me it's better to be able to use the version they already had. But I can temporarily try from the master branch if you like.

tonatiuh commented 10 years ago

The solution shared by @mjjohnson worked perfect for me too. Thanks.

xacaxulu commented 10 years ago

+1

asadakbar commented 10 years ago

The solution suggested by @mjjohnson worked for me as well.

SimonKaluza commented 9 years ago

Nice work @mjjohnson :+1: