Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silly Question? #86

Open
ccoupe opened this issue Dec 31, 2013 · 4 comments
Open

Silly Question? #86

ccoupe opened this issue Dec 31, 2013 · 4 comments

Comments

@ccoupe
Copy link

ccoupe commented Dec 31, 2013

I apologize if this is off topic, but since rake compiler can do this it's my best place to ask my question (I think). I'm trying to cross compile an app that embeds Ruby - Shoes. The base Shoes app does cross compile and run on i386-linux, x86_64_linux, and raspbian. Shoes also has a couple of extensions with extconf.rb files. I can't figure out the magic in extconf.rb needed for mkmf.rb so that it generates a Makefile that uses the proper compiler.

I know it can be done. If I cross compile Ruby, it builds it's extensions with the proper compiler and the mkmf log clearly shows that. Anyway, here's the extconf.rb I'm trying. - it should fail, but it doesn't.

require 'mkmf'
puts "compile ext with #{ENV['CC']}"
$CC = '/bin/fail' #=ENV['CC']
CC = $CC
RbConfig::CONFIG['$(CC)']= $CC
$CFLAGS += ' -Wno-declaration-after-statement -std=gnu99 -ffast-math'
create_makefile('chipmunk')

The output when running the build is

compile ext with arm-linux-gnueabihf-gcc
creating Makefile
compiling cpArbiter.c

The resulting .o file and the lib are x86_64 (my build system). why does mkmf ignore me?. The append to $CFLAGS does work.

@luislavena
Copy link
Contributor

Hello @ccoupe

Sorry for the delayed response.

mkmf will use information from rbconfig, but will also use platform information before you require it.

rake-compiler uses the same trick of Ruby itself by generating a fake.rb file placed on the same directory of extconf.rb and that is required before anything

You will find the contents of that file here (well, partially, since version information is generated at runtime)

https://github.com/luislavena/rake-compiler/blob/master/lib/rake/extensiontask.rb#L483-L510

And that results in a command line similar to this:

$ ruby -I. -rfake extconf.rb

I believe you will need to achieve something similar for your cross-compilation process to work.

Let me know if this helps you.

Regards.

@ccoupe
Copy link
Author

ccoupe commented Jan 14, 2014

Luis,

Thank you for the help. I managed get some hacks that work well
enough for the two extensions I needed to build but it's ugly: I just
studied the mkmf.rb code and overwrite some of the CONFIG[] entries or
some $global variable that mkmf had set with the building systems
rbconfig. Not pretty but it works, so far.

I do need to do a more robust effort, so I thank you for the
pointers. FWIW, I have cross compiled binary distributions of Shoes
(with Gkt3 and embedded ruby 1.9.3) for x86_64 linux, i386 linux,
raspberry pi, and Windows and they work (modulo my Gkt3 errors). There
is thread deadlock when running my windows version under Wine, but not
(yet) in Win 7.

Has anyone attempted to use pthread for Windows-Ruby? I looked at
win32/win32.c and that more
work that I want to attempt.

Regards,
Cecil

On 01/13/2014 06:49 PM, Luis Lavena wrote:

Hello @ccoupe https://github.com/ccoupe

Sorry for the delayed response.

mkmf will use information from |rbconfig|, but will also use platform
information /before/ you require it.

rake-compiler uses the same trick of Ruby itself by generating a
|fake.rb| file placed on the same directory of |extconf.rb| and that
is required /before anything/

You will find the contents of that file here (well, partially, since
version information is generated at runtime)

https://github.com/luislavena/rake-compiler/blob/master/lib/rake/extensiontask.rb#L483-L510

And that results in a command line similar to this:

$ ruby -I. -rfake extconf.rb

I believe you will need to achieve something similar for your
cross-compilation process to work.

Let me know if this helps you.

Regards.


Reply to this email directly or view it on GitHub
#86 (comment).

@chrisrgue
Copy link

@ccoupe: I am facing the very same challenge as you did. Could you please share the (working) hacks that you referred to above ?

@ccoupe
Copy link
Author

ccoupe commented May 27, 2015

@chrisrgue , each gem with an ext requires it's own unique set of compile time flags and constants. I ended up writing a extconf.rb for each archicture/builder combination and run that instead. It's not something I would scale beyond the two gem of concern to me. You can look at what I've done here shoes/shoes3#72 but its very specific to that project.

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

No branches or pull requests

3 participants