Skip to contentSkip to conversation

ruby-shadow: Work around cross compile gem problem

PATCH In review Jason Wessel 2 participants 3 messages Jan 15, 2016 – Jan 19, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ruby-shadow: Work around cross compile gem problem

Prior to this commit it is not possible to cross build a ruby gem. In fact even on the x86 system the object files for the native gem are generated with the wrong compiler (the host compiler instead of the cross compiler).

A better way to fix this in the future would be to use only gems that supported cross compile tool called rake. For now the bbclass can modify the extconf.rb just before creating the gem and insert some code into the Makefile so as to honor the cross compile environment.

---
 classes/ruby.bbclass                           |   31 ++++++++++++++++++++++++
 recipes-support/ruby-shadow/ruby-shadow_git.bb |    2 +-
 2 files changed, 32 insertions(+), 1 deletion(-)
classes/ruby.bbclass +31 -0
index 0c842d5..92226f6 100644
@@ -83,10 +83,41 @@ RUBY_INSTALL_GEMS ?= "${BPN}-${BPV}.gem"
 
 RUBY_COMPILE_FLAGS ?= 'LANG="en_US.UTF-8" LC_ALL="en_US.UTF-8"'
 
+ruby_gen_extconf_fix() {
+	cat<<EOF>append
+  RbConfig::MAKEFILE_CONFIG['CPPFLAGS'] = ENV['CPPFLAGS'] if ENV['CPPFLAGS']
+  \$CPPFLAGS = ENV['CPPFLAGS'] if ENV['CPPFLAGS']
+  RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
+  RbConfig::MAKEFILE_CONFIG['LD'] = ENV['LD'] if ENV['LD']
+  RbConfig::MAKEFILE_CONFIG['CFLAGS'] = ENV['CFLAGS'] if ENV['CFLAGS']
+  RbConfig::MAKEFILE_CONFIG['CXXFLAGS'] = ENV['CXXFLAGS'] if ENV['CXXFLAGS']
+EOF
+	cat append2>>append
+	sysroot_ruby=${STAGING_INCDIR}/ruby-${RUBY_GEM_VERSION}
+	ruby_arch=`ls -1 ${sysroot_ruby} |grep -v ruby |tail -1 2> /dev/null`
+	cat<<EOF>>append
+  system("perl -p -i -e 's#^topdir.*#topdir = ${sysroot_ruby}#' Makefile")
+  system("perl -p -i -e 's#^hdrdir.*#hdrdir = ${sysroot_ruby}#' Makefile")
+  system("perl -p -i -e 's#^arch_hdrdir.*#arch_hdrdir = ${sysroot_ruby}/\\\\\$(arch)#' Makefile")
+  system("perl -p -i -e 's#^arch =.*#arch = ${ruby_arch}#' Makefile")
+  system("perl -p -i -e 's#^LIBPATH =.*#LIBPATH = -L.#' Makefile")
+EOF
+}
+
 ruby_do_compile() {
+	if [ -f extconf.rb -a ! -f extconf.rb.orig ] ; then
+		grep create_makefile extconf.rb > append2 || (exit 0)
+		ruby_gen_extconf_fix
+		cp extconf.rb extconf.rb.orig
+		# Patch extconf.rb for cross compile
+		cat append >> extconf.rb
+	fi
 	for gem in ${RUBY_BUILD_GEMS}; do
 		${RUBY_COMPILE_FLAGS} gem build $gem
 	done
+	if [ -f extconf.rb.orig ] ; then
+		mv extconf.rb.orig extconf.rb
+	fi
 }
 
 
recipes-support/ruby-shadow/ruby-shadow_git.bb +1 -1
index 72be016..75588f3 100644
@@ -20,4 +20,4 @@ RDEPENDS_${PN} += " \
 "
 
 RUBY_INSTALL_GEMS = "ruby-shadow-${PV}.gem"
-FILES_${PN}-dbg += "/usr/lib64/ruby/gems/*/gems/ruby-shadow-${PV}/.debug/shadow.so"
+FILES_${PN}-dbg += "/usr/lib*/ruby/gems/*/gems/ruby-shadow-${PV}/.debug/shadow.so"
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/1 ruby-shadow: Work around cross compile gem problem

Prior to this commit it is not possible to cross build a ruby gem. In fact even on the x86 system the object files for the native gem are generated with the wrong compiler (the host compiler instead of the cross compiler).

A better way to fix this in the future would be to use only gems that supported cross compile tool called rake. For now the bbclass can modify the extconf.rb just before creating the gem and insert some code into the Makefile so as to honor the cross compile environment.

---
 classes/ruby.bbclass                           |   31 ++++++++++++++++++++++++
 recipes-support/ruby-shadow/ruby-shadow_git.bb |    2 +-
 2 files changed, 32 insertions(+), 1 deletion(-)
classes/ruby.bbclass +31 -0
index 0c842d5..92226f6 100644
@@ -83,10 +83,41 @@ RUBY_INSTALL_GEMS ?= "${BPN}-${BPV}.gem"
 
 RUBY_COMPILE_FLAGS ?= 'LANG="en_US.UTF-8" LC_ALL="en_US.UTF-8"'
 
+ruby_gen_extconf_fix() {
+	cat<<EOF>append
+  RbConfig::MAKEFILE_CONFIG['CPPFLAGS'] = ENV['CPPFLAGS'] if ENV['CPPFLAGS']
+  \$CPPFLAGS = ENV['CPPFLAGS'] if ENV['CPPFLAGS']
+  RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
+  RbConfig::MAKEFILE_CONFIG['LD'] = ENV['LD'] if ENV['LD']
+  RbConfig::MAKEFILE_CONFIG['CFLAGS'] = ENV['CFLAGS'] if ENV['CFLAGS']
+  RbConfig::MAKEFILE_CONFIG['CXXFLAGS'] = ENV['CXXFLAGS'] if ENV['CXXFLAGS']
+EOF
+	cat append2>>append
+	sysroot_ruby=${STAGING_INCDIR}/ruby-${RUBY_GEM_VERSION}
+	ruby_arch=`ls -1 ${sysroot_ruby} |grep -v ruby |tail -1 2> /dev/null`
+	cat<<EOF>>append
+  system("perl -p -i -e 's#^topdir.*#topdir = ${sysroot_ruby}#' Makefile")
+  system("perl -p -i -e 's#^hdrdir.*#hdrdir = ${sysroot_ruby}#' Makefile")
+  system("perl -p -i -e 's#^arch_hdrdir.*#arch_hdrdir = ${sysroot_ruby}/\\\\\$(arch)#' Makefile")
+  system("perl -p -i -e 's#^arch =.*#arch = ${ruby_arch}#' Makefile")
+  system("perl -p -i -e 's#^LIBPATH =.*#LIBPATH = -L.#' Makefile")
+EOF
+}
+
 ruby_do_compile() {
+	if [ -f extconf.rb -a ! -f extconf.rb.orig ] ; then
+		grep create_makefile extconf.rb > append2 || (exit 0)
+		ruby_gen_extconf_fix
+		cp extconf.rb extconf.rb.orig
+		# Patch extconf.rb for cross compile
+		cat append >> extconf.rb
+	fi
 	for gem in ${RUBY_BUILD_GEMS}; do
 		${RUBY_COMPILE_FLAGS} gem build $gem
 	done
+	if [ -f extconf.rb.orig ] ; then
+		mv extconf.rb.orig extconf.rb
+	fi
 }
 
 
recipes-support/ruby-shadow/ruby-shadow_git.bb +1 -1
index 72be016..75588f3 100644
@@ -20,4 +20,4 @@ RDEPENDS_${PN} += " \
 "
 
 RUBY_INSTALL_GEMS = "ruby-shadow-${PV}.gem"
-FILES_${PN}-dbg += "/usr/lib64/ruby/gems/*/gems/ruby-shadow-${PV}/.debug/shadow.so"
+FILES_${PN}-dbg += "/usr/lib*/ruby/gems/*/gems/ruby-shadow-${PV}/.debug/shadow.so"
Signature · 1 line
1.7.9.5
#2 lore raw
In reply to Jason Wessel

nasty stuff.

Definitely an improvement from what we had before. I've merged this to master.

Bruce

Quoted 89 lines · Jason Wessel

Prior to this commit it is not possible to cross build a ruby gem. In fact even on the x86 system the object files for the native gem are generated with the wrong compiler (the host compiler instead of the cross compiler).

A better way to fix this in the future would be to use only gems that supported cross compile tool called rake. For now the bbclass can modify the extconf.rb just before creating the gem and insert some code into the Makefile so as to honor the cross compile environment.

---
 classes/ruby.bbclass                           |   31
++++++++++++++++++++++++
 recipes-support/ruby-shadow/ruby-shadow_git.bb |    2 +-
 2 files changed, 32 insertions(+), 1 deletion(-)
classes/ruby.bbclass +3 -0
index 0c842d5..92226f6 100644
@@ -83,10 +83,41 @@ RUBY_INSTALL_GEMS ?= "${BPN}-${BPV}.gem"
 
 RUBY_COMPILE_FLAGS ?= 'LANG="en_US.UTF-8" LC_ALL="en_US.UTF-8"'
 
+ruby_gen_extconf_fix() {
+       cat<<EOF>append
+  RbConfig::MAKEFILE_CONFIG['CPPFLAGS'] = ENV['CPPFLAGS'] if

ENV['CPPFLAGS']

classes/ruby.bbclass +5 -0
+  \$CPPFLAGS = ENV['CPPFLAGS'] if ENV['CPPFLAGS']
+  RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
+  RbConfig::MAKEFILE_CONFIG['LD'] = ENV['LD'] if ENV['LD']
+  RbConfig::MAKEFILE_CONFIG['CFLAGS'] = ENV['CFLAGS'] if ENV['CFLAGS']
+  RbConfig::MAKEFILE_CONFIG['CXXFLAGS'] = ENV['CXXFLAGS'] if

ENV['CXXFLAGS']

classes/ruby.bbclass +4 -0
+EOF
+       cat append2>>append
+       sysroot_ruby=${STAGING_INCDIR}/ruby-${RUBY_GEM_VERSION}
+       ruby_arch=`ls -1 ${sysroot_ruby} |grep -v ruby |tail -1 2>

/dev/null`

classes/ruby.bbclass +4 -0
+       cat<<EOF>>append
+  system("perl -p -i -e 's#^topdir.*#topdir = ${sysroot_ruby}#' Makefile")
+  system("perl -p -i -e 's#^hdrdir.*#hdrdir = ${sysroot_ruby}#' Makefile")
+  system("perl -p -i -e 's#^arch_hdrdir.*#arch_hdrdir =

${sysroot_ruby}/\\\\\$(arch)#' Makefile")

classes/ruby.bbclass +15 -0
+  system("perl -p -i -e 's#^arch =.*#arch = ${ruby_arch}#' Makefile")
+  system("perl -p -i -e 's#^LIBPATH =.*#LIBPATH = -L.#' Makefile")
+EOF
+}
+
 ruby_do_compile() {
+       if [ -f extconf.rb -a ! -f extconf.rb.orig ] ; then
+               grep create_makefile extconf.rb > append2 || (exit 0)
+               ruby_gen_extconf_fix
+               cp extconf.rb extconf.rb.orig
+               # Patch extconf.rb for cross compile
+               cat append >> extconf.rb
+       fi
        for gem in ${RUBY_BUILD_GEMS}; do
                ${RUBY_COMPILE_FLAGS} gem build $gem
        done
+       if [ -f extconf.rb.orig ] ; then
+               mv extconf.rb.orig extconf.rb
+       fi
 }
recipes-support/ruby-shadow/ruby-shadow_git.bb +0 -1
index 72be016..75588f3 100644
@@ -20,4 +20,4 @@ RDEPENDS_${PN} += " \
 "
 
 RUBY_INSTALL_GEMS = "ruby-shadow-${PV}.gem"
-FILES_${PN}-dbg +=

"/usr/lib64/ruby/gems/*/gems/ruby-shadow-${PV}/.debug/shadow.so" +FILES_${PN}-dbg += "/usr/lib*/ruby/gems/*/gems/ruby-shadow-${PV}/.debug/shadow.so" --
1.7.9.5

--
_______________________________________________
meta-virtualization mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/meta-virtualization

Signature · 2 lines
"Thou shalt not follow the NULL pointer, for chaos and madness await thee
at its end"