about summary refs log tree commit diff
path: root/pkgs/development/interpreters/ruby
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2017-10-29 15:51:16 -0400
committerWill Dietz <w@wdtz.org>2018-02-13 09:44:29 -0600
commit41026550e2afb0182fca1ca59c57437b554359c6 (patch)
treee6a09b56176481d838f984ace9074285f79156e1 /pkgs/development/interpreters/ruby
parent2d772d52ae92d97ef1bd62e0f084d162bda0a62c (diff)
ruby: Enable cross-compilation
Diffstat (limited to 'pkgs/development/interpreters/ruby')
-rw-r--r--pkgs/development/interpreters/ruby/default.nix24
1 files changed, 19 insertions, 5 deletions
diff --git a/pkgs/development/interpreters/ruby/default.nix b/pkgs/development/interpreters/ruby/default.nix
index 9d82810900f0f..a0c563e3fb2db 100644
--- a/pkgs/development/interpreters/ruby/default.nix
+++ b/pkgs/development/interpreters/ruby/default.nix
@@ -1,4 +1,5 @@
-{ stdenv, lib, fetchurl, fetchpatch, fetchFromSavannah, fetchFromGitHub
+{ stdenv, buildPackages, lib
+, fetchurl, fetchpatch, fetchFromSavannah, fetchFromGitHub
 , zlib, openssl, gdbm, ncurses, readline, groff, libyaml, libffi, autoreconfHook, bison
 , autoconf, darwin ? null
 , buildEnv, bundler, bundix, Foundation
@@ -22,6 +23,12 @@ let
   # Contains the ruby version heuristics
   rubyVersion = import ./ruby-version.nix { inherit lib; };
 
+  # Needed during postInstall
+  buildRuby =
+    if stdenv.hostPlatform == stdenv.buildPlatform
+    then "$out/bin/ruby"
+    else "${buildPackages.ruby}/bin/ruby";
+
   generic = { version, sha256 }: let
     ver = version;
     tag = ver.gitTag;
@@ -30,7 +37,8 @@ let
     isRuby25 = ver.majMin == "2.5";
     baseruby = self.override { useRailsExpress = false; };
     self = lib.makeOverridable (
-      { stdenv, lib, fetchurl, fetchpatch, fetchFromSavannah, fetchFromGitHub
+  { stdenv, buildPackages, lib
+      , fetchurl, fetchpatch, fetchFromSavannah, fetchFromGitHub
       , useRailsExpress ? true
       , zlib, zlibSupport ? true
       , openssl, opensslSupport ? true
@@ -67,7 +75,11 @@ let
         # Have `configure' avoid `/usr/bin/nroff' in non-chroot builds.
         NROFF = "${groff}/bin/nroff";
 
-        nativeBuildInputs = ops useRailsExpress [ autoreconfHook bison ];
+        nativeBuildInputs =
+             ops useRailsExpress [ autoreconfHook bison ]
+          ++ ops (stdenv.buildPlatform != stdenv.hostPlatform) [
+               buildPackages.ruby
+             ];
         buildInputs =
              (op fiddleSupport libffi)
           ++ (ops cursesSupport [ ncurses readline ])
@@ -129,14 +141,16 @@ let
             "--with-out-ext=tk"
             # on yosemite, "generating encdb.h" will hang for a very long time without this flag
             "--with-setjmp-type=setjmp"
-          ];
+          ]
+          ++ op (stdenv.hostPlatform != stdenv.buildPlatform)
+             "--with-baseruby=${buildRuby}";
 
         installFlags = stdenv.lib.optionalString docSupport "install-doc";
         # Bundler tries to create this directory
         postInstall = ''
           # Update rubygems
           pushd rubygems
-          $out/bin/ruby setup.rb
+          ${buildRuby} setup.rb
           popd
 
           # Remove unnecessary groff reference from runtime closure, since it's big