Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Error building therubyracer/libv8 on FreeBSD 9 (and a solution) #158

Closed
jlc opened this issue Apr 28, 2012 · 14 comments
Closed

Error building therubyracer/libv8 on FreeBSD 9 (and a solution) #158

jlc opened this issue Apr 28, 2012 · 14 comments

Comments

@jlc
Copy link

jlc commented Apr 28, 2012

Hey Charles,

I came across a building issue of the libv8 gem while installing gitlab in a FreeBSD jail, and would like to share the problem and the solution I have found with you and anyone who might be interested.

The big picture:
a) this is the first time ever I'm getting close to ruby, RoR, gem...etc. Excuse me if I'm missing something somewhere.
b) uname -a : FreeBSD 9.0-RELEASE #0 amd64
c) gcc --version: gcc (GCC) 4.2.1 20070831 patched [FreeBSD]
d) requirement: make gitlab work :)

After I have understood that therubyracer is using a special version of libv8, and that we should not use the one provided by ports (/usr/ports/lang/v8), I tried to run

   # gem install libv6

Which gently install the libv6, however:

   # gem install therubyracer

Says:

   Building native extensions.  This could take a while...
   ERROR:  Error installing therubyracer:
   ERROR: Failed to build gem native extension.

    /usr/local/bin/ruby extconf.rb
    creating Makefile

    make
    compiling v8_array.cpp
    cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++
    ...
   v8_v8.h:6:7: warning: no newline at end of file
   linking shared-object v8.so
   g++: /usr/local/lib/ruby/gems/1.9.1/gems/libv8-3.3.10.4/lib/libv8/build/v8/libv8.a: No such file or directory
   *** Error code 1

   Stop in /usr/local/lib/ruby/gems/1.9.1/gems/therubyracer-0.10.1/ext/v8.

After few mistake (certainly due the lack of sleep...) between the 2 set of code in:

  /usr/local/lib/ruby/gems/1.9.1/gems/libv8-3.3.10.4/lib/libv8/v8

and

  /usr/local/lib/ruby/gems/1.9.1/gems/libv8-3.3.10.4/lib/libv8/buid/v8

I continued with:

 # cd /usr/local/lib/ruby/gems/1.9.1/gems/libv8-3.3.10.4/lib/libv8/build/v8
 # scons

Which produces:

   ...
   src/profile-generator.h:242:   instantiated from here
   src/splay-tree.h:187: error: no suitable 'operator delete' for 'v8::internal::SplayTree<v8::internal::CodeMap::CodeTreeConfig,                      v8::internal::FreeStoreAllocationPolicy>::Node'
   scons: *** [obj/release/accessors.o] Error 1
   scons: building terminated because of errors.

Googling this issue point to:
http://code.google.com/p/v8/issues/detail?id=744

Which say:

   i found the solution.

   scons arch=x64 solved the problem since my achitecture is 64bit...

Great! This nicely build libv8.a!

However,

   # gem install therubyracer

Says:

 ...
 v8_handle.h:43: warning: dereferencing type-punned pointer will break strict-aliasing rules
 linking shared-object v8.so
 /usr/bin/ld: /usr/local/lib/ruby/gems/1.9.1/gems/libv8-3.3.10.4/lib/libv8/build/v8/libv8.a(api.o): relocation R_X86_64_32S against `_ZTVN2v89ExtensionE' can not be used when making a shared object; recompile with -     fPIC/usr/local/lib/ruby/gems/1.9.1/gems/libv8-3.3.10.4/lib/libv8/build/v8/libv8.a: could not read symbols: Bad value
 *** Error code 1
 Stop in /usr/local/lib/ruby/gems/1.9.1/gems/therubyracer-0.10.1/ext/v8.

We then need to add -fPIC into the freebsd section of

 /usr/local/lib/ruby/gems/1.9.1/gems/libv8-3.3.10.4/lib/libv8/build/v8/SConstruct

'os:freebsd': {
  'CPPPATH' : ['/usr/local/include'],
  'LIBPATH' : ['/usr/local/lib'],
  'CCFLAGS':      ['-ansi', '-fPIC'],
  'LIBS': ['execinfo']
},

Rebuild libv8:

  # scons arch=x64

Install therubyracer

 # gem install therubyracer

Which, finally, says:

 Building native extensions.  This could take a while...
 Successfully installed therubyracer-0.10.1
 1 gem installed
 Installing ri documentation for therubyracer-0.10.1...
 Installing RDoc documentation for therubyracer-0.10.1...

I hope it has been clear enough for you to fix it.
If you need any tests / help : jl@lo.cx

Wish you a nice day,

Jeanluc

@turgu1
Copy link

turgu1 commented May 1, 2012

Thanks for the fix, it worked for me too. Hope the change required to libv8 will be applies soon.

Cheers

Guy

@eddanger
Copy link

eddanger commented May 2, 2012

It seems that there is a conflict when you have v8 installed in your system already.

Here is what I did to get closer to installing therubyracer:

Deinstall v8

$ cd /usr/ports/lang/v8
$ sudo make deinstall

add -fPIC into the freebsd section of SConstruct as you indicated above

Run scons with x64 arch

$ scons arch=x64

This compiles, but when I run sudo gem install therubyracer I lose my successful build and it resets the SConstruct...

Any way to get therubyracer to use the system shared v8?

@jlc
Copy link
Author

jlc commented May 3, 2012

@eddanger :
During my previous googling looking for a solution to the problem, it seams that therubyracer is using a separate version of libv8 due to the frequent changes on the lib api which make it difficult to maintain the module (if I got it well).

@turgu1 :
As a side note to my previous report, does therubyracer tried to build the libv8 (as shown at the begin of the previous report)?

     ...v8/libv8.a: No such file or directory

Moreover, if I remermber well my last tests (I cannot recheck right now, but it can be done later if necessary), the "gem install libv8" is building it nicely.

@turgu1
Copy link

turgu1 commented May 3, 2012

@jlc:
I'm still trying to understand the installation process used when building therubyracer. I wanted to fork libv8 to adjust the parameters and propose an easy correction back through github, but I can't see how I could access the version 3.3.10.4 of libv8 used by therubyracer. Following the recipe you gave, I was able to get the installed libv8.a compiled and therubyracer linked, but I still get some errors at run-time that I would like to debug before posting again about it.

My context of use is the following: I'm developing a Ruby on Rails document management application that uses Twitter Bootstrap to build the HTML/Javascript front-end. As bootstrap uses Less as a pre-processing language to produce CSS, it requires therubyracer to support the Less compiler. To integrate bootstrap, I use the twitter-bootstrap-rails gem. Everything goes well under OSX (my development environment) but when I deploy through Capistrano on the targeted FreeBSD production server, I get compiling errors from the bundle process during deployment. On both the development and deployment environment, I use the last stable Ruby version 1.9.3, Ruby on Rails version 3.2.3, RVM to manage the ruby interpreter and PostgreSQL as the database backend (of course, Capistrano to automate the deployment).

Under OSX, therubyracer seems to install a binary version of the libv8 gem(no source found on my development system). Under FreeBSD, the version seems to be related to http://github.com/fractaloop/libv8, but I can't get access to it through github.

The Capistrano process make bundler run and put all gems required by the application at the following place:

/home/edoc2/apps/eDoc2/shared/bundle/ruby/1.9.1/gems

where I found the libv8-3.3.10.4 directory. Using your recipe, I managed to compile libv8.a and make it available to the complete the deployment process. The bundle process didn't tried to compile it again as it was there. But still, I get runtime errors.

Hope all this help!

Cheers!

Guy

@GSI
Copy link

GSI commented May 6, 2012

Thanks, jlc. While extracting your workaround, I turned it into a script for my own documentation purposes and others who might find it useable.

https://gist.github.com/2621916

Note that this is for a RVM based installation. Amend the paths according to your setup.

@eddanger
Copy link

eddanger commented May 6, 2012

@GSI slightly modified for my setup allows me to install:

https://gist.github.com/2623519

But I'm getting a Core dump when using therubyracer in my projects.

https://gist.github.com/2623637

@madmax
Copy link

madmax commented Jun 9, 2012

I created fork that should works I tested it on freebsd 8.x

https://github.com/madmax/therubyracer-freebsd

@pgib
Copy link

pgib commented Jun 9, 2012

@madmax thank you, thank you, thank you!

@ghost
Copy link

ghost commented Jun 10, 2012

@madmax thank you for building this but unfortunately libv8-freebsd does not seem to compile for me on FreeBSD 9 amd64, doing a gem install libv8-freebsd --verbose I have the following error:

scons: warning: Ignoring missing SConscript 'obj/test/release/SConscript'
File "/usr/home/oggy/.rvm/gems/ruby-1.9.3-p194/gems/libv8-freebsd-3.3.10.4/lib/libv8/build/v8/SConstruct", line 1411, in BuildSpecific
src/extensions/externalize-string-extension.cc:55: error: 'uc16' was not declared in this scope
src/extensions/externalize-string-extension.cc:55: error: template argument 1 is invalid
src/extensions/externalize-string-extension.cc:56: error: invalid type in declaration before ';' token
src/extensions/externalize-string-extension.cc: In member function 'virtual v8::Handlev8::FunctionTemplate v8::internal::ExternalizeStringExtension::GetNativeFunction(v8::Handlev8::String)':
src/extensions/externalize-string-extension.cc:66: error: 'strcmp' was not declared in this scope
src/extensions/externalize-string-extension.cc:69: error: 'ASSERT' was not declared in this scope
src/extensions/externalize-string-extension.cc: In static member function 'static v8::Handlev8::Value v8::internal::ExternalizeStringExtension::Externalize(const v8::Arguments&)':
src/extensions/externalize-string-extension.cc:91: error: incomplete type 'v8::Utils' used in nested name specifier
src/extensions/externalize-string-extension.cc:92: error: 'class v8::String' has no member named 'IsExternalString'
src/extensions/externalize-string-extension.cc:96: error: 'class v8::String' has no member named 'IsAsciiRepresentation'
src/extensions/externalize-string-extension.cc:97: error: 'class v8::String' has no member named 'length'
src/extensions/externalize-string-extension.cc:98: error: 'WriteToFlat' is not a member of 'v8::String'
src/extensions/externalize-string-extension.cc:98: error: 'class v8::String' has no member named 'length'
src/extensions/externalize-string-extension.cc:100: error: 'class v8::String' has no member named 'length'
src/extensions/externalize-string-extension.cc:102: error: 'class v8::String' has no member named 'IsSymbol'
src/extensions/externalize-string-extension.cc:103: error: 'HEAP' was not declared in this scope
src/extensions/externalize-string-extension.cc:107: error: 'uc16' was not declared in this scope
src/extensions/externalize-string-extension.cc:107: error: 'data' was not declared in this scope
src/extensions/externalize-string-extension.cc:107: error: expected type-specifier before 'uc16'
src/extensions/externalize-string-extension.cc:107: error: expected `;' before 'uc16'
src/extensions/externalize-string-extension.cc:108: error: 'WriteToFlat' is not a member of 'v8::String'
src/extensions/externalize-string-extension.cc:108: error: 'class v8::String' has no member named 'length'
src/extensions/externalize-string-extension.cc:110: error: 'class v8::String' has no member named 'length'
src/extensions/externalize-string-extension.cc:110: error: new initializer expression list treated as compound expression
src/extensions/externalize-string-extension.cc:111: error: no matching function for call to 'v8::String::MakeExternal(v8::internal::SimpleTwoByteStringResource_&)'
/usr/local/include/v8.h:1238: note: candidates are: bool v8::String::MakeExternal(v8::String::ExternalStringResource_)
/usr/local/include/v8.h:1259: note: bool v8::String::MakeExternal(v8::String::ExternalAsciiStringResource_)
src/extensions/externalize-string-extension.cc:112: error: 'class v8::String' has no member named 'IsSymbol'
src/extensions/externalize-string-extension.cc:113: error: 'HEAP' was not declared in this scope
src/extensions/externalize-string-extension.cc: In static member function 'static v8::Handlev8::Value v8::internal::ExternalizeStringExtension::IsAscii(const v8::Arguments&)':
src/extensions/externalize-string-extension.cc:130: error: incomplete type 'v8::Utils' used in nested name specifier
scons: *_* [obj/release/extensions/externalize-string-extension.o] Error 1
gmake: *** [build/v8/libv8.a] Error 2
creating Makefile

@madmax
Copy link

madmax commented Jun 10, 2012

Hmm, I tested it on Freebsd 8.2 and 8.1. Did you have ports/lang/v8 installed? If yes try uninstall it.

Try

gem unpack libv8-freebsd
cd libv8-freebsd-3.3.10.4/lib/libv8
gmake

What version gcc it use? For me it is
cd build/v8 && SHELL=/bin/sh && GCC_VERSION=42 ../scons/install/bin/scons arch=x64

@ghost
Copy link

ghost commented Jun 10, 2012

@madmax removed the v8 port and have libv8-freebsd and therubyracer-freebsd installed, thanks.

@pgib
Copy link

pgib commented Jun 14, 2012

@madmax So, I was able to get these installed under FreeBSD 9.0, but the issue now is that my Rails project uses the Assets pipeline and I see this in my Gemfile.lock:

less (2.0.12)
  commonjs (~> 0.2.0)
  therubyracer (~> 0.9.9)                                                                                                                                  

I was able to get around this by manually renaming my installed gems to pose as therubyracer and libv8 (ie. remove the -freebsd), but this doesn't seem like a great solution.

And when running it, I get a similar coredump to @eddanger:

/usr/local/lib/ruby/gems/1.9/gems/therubyracer-freebsd-0.10.1/lib/v8/portal.rb:16: [BUG] Stack consistency error (sp: 309, bp: 310)
ruby 1.9.3p125 (2012-02-16 revision 34643) [i386-freebsd9]

:(

@madmax
Copy link

madmax commented Jun 14, 2012

@pgib please update less and it should works just fine.

You can also use

gem 'therubyracer', git: "git://github.com/madmax/therubyracer-freebsd.git"

But this old less version require old therubyracer and still it will not work, i suggest update less.

About [BUG] i have no idea, i'm not C guy :)

@cowboyd
Copy link
Collaborator

cowboyd commented Jun 16, 2012

therubyracer and libv8 builds have been updated on master to fix this and other issues.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants