Merge pull request #138368 from arcnmx/ruby-cross-closure

ruby: remove build references from cross compiles
This commit is contained in:
Mario Rodas 2021-12-25 11:08:26 -05:00 committed by GitHub
commit 9c7bea23cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,21 +17,10 @@ let
# Contains the ruby version heuristics # Contains the ruby version heuristics
rubyVersion = import ./ruby-version.nix { inherit lib; }; 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 generic = { version, sha256 }: let
ver = version; ver = version;
tag = ver.gitTag; tag = ver.gitTag;
atLeast30 = lib.versionAtLeast ver.majMin "3.0"; atLeast30 = lib.versionAtLeast ver.majMin "3.0";
baseruby = self.override {
useRailsExpress = false;
docSupport = false;
rubygemsSupport = false;
};
self = lib.makeOverridable ( self = lib.makeOverridable (
{ stdenv, buildPackages, lib { stdenv, buildPackages, lib
, fetchurl, fetchpatch, fetchFromSavannah, fetchFromGitHub , fetchurl, fetchpatch, fetchFromSavannah, fetchFromGitHub
@ -59,6 +48,12 @@ let
, buildEnv, bundler, bundix , buildEnv, bundler, bundix
, libiconv, libobjc, libunwind, Foundation , libiconv, libobjc, libunwind, Foundation
, makeWrapper, buildRubyGem, defaultGemConfig , makeWrapper, buildRubyGem, defaultGemConfig
, baseRuby ? buildPackages.ruby.override {
useRailsExpress = false;
docSupport = false;
rubygemsSupport = false;
}
, useBaseRuby ? stdenv.hostPlatform != stdenv.buildPlatform || useRailsExpress
}: }:
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
pname = "ruby"; pname = "ruby";
@ -81,7 +76,7 @@ let
nativeBuildInputs = [ autoreconfHook bison ] nativeBuildInputs = [ autoreconfHook bison ]
++ (op docSupport groff) ++ (op docSupport groff)
++ op (stdenv.buildPlatform != stdenv.hostPlatform) buildPackages.ruby; ++ op useBaseRuby baseRuby;
buildInputs = [ autoconf ] buildInputs = [ autoconf ]
++ (op fiddleSupport libffi) ++ (op fiddleSupport libffi)
++ (ops cursesSupport [ ncurses readline ]) ++ (ops cursesSupport [ ncurses readline ])
@ -133,24 +128,24 @@ let
sed -i ext/io/console/io-console.gemspec -e '/s\.date/d' sed -i ext/io/console/io-console.gemspec -e '/s\.date/d'
''; '';
configureFlags = ["--enable-shared" "--enable-pthread" "--with-soname=ruby-${version}"] configureFlags = [
++ op useRailsExpress "--with-baseruby=${baseruby}/bin/ruby" (lib.enableFeature (!stdenv.hostPlatform.isStatic) "shared")
++ op (!jitSupport) "--disable-jit-support" (lib.enableFeature true "pthread")
++ op (!docSupport) "--disable-install-doc" (lib.withFeatureAs true "soname" "ruby-${version}")
++ op (jemallocSupport) "--with-jemalloc" (lib.withFeatureAs useBaseRuby "baseruby" "${baseRuby}/bin/ruby")
++ ops stdenv.isDarwin [ (lib.enableFeature jitSupport "jit-support")
# on darwin, we have /usr/include/tk.h -- so the configure script detects (lib.enableFeature docSupport "install-doc")
# that tk is installed (lib.withFeature jemallocSupport "jemalloc")
"--with-out-ext=tk" (lib.withFeatureAs docSupport "ridir" "${placeholder "devdoc"}/share/ri")
# on yosemite, "generating encdb.h" will hang for a very long time without this flag ] ++ ops stdenv.isDarwin [
"--with-setjmp-type=setjmp" # on darwin, we have /usr/include/tk.h -- so the configure script detects
] # that tk is installed
++ op (stdenv.hostPlatform != stdenv.buildPlatform) "--with-out-ext=tk"
"--with-baseruby=${buildRuby}"; # on yosemite, "generating encdb.h" will hang for a very long time without this flag
"--with-setjmp-type=setjmp"
];
preConfigure = opString docSupport '' preConfigure = opString docSupport ''
configureFlagsArray+=("--with-ridir=$devdoc/share/ri")
# rdoc creates XDG_DATA_DIR (defaulting to $HOME/.local/share) even if # rdoc creates XDG_DATA_DIR (defaulting to $HOME/.local/share) even if
# it's not going to be used. # it's not going to be used.
export HOME=$TMPDIR export HOME=$TMPDIR
@ -208,13 +203,16 @@ let
# Add rbconfig shim so ri can find docs # Add rbconfig shim so ri can find docs
mkdir -p $devdoc/lib/ruby/site_ruby mkdir -p $devdoc/lib/ruby/site_ruby
cp ${./rbconfig.rb} $devdoc/lib/ruby/site_ruby/rbconfig.rb cp ${./rbconfig.rb} $devdoc/lib/ruby/site_ruby/rbconfig.rb
'' + opString useRailsExpress '' sed -i '/^ CONFIG\["\(BASERUBY\|SHELL\|GREP\|EGREP\|MKDIR_P\|MAKEDIRS\|INSTALL\)"\]/d' $rbConfig
'' + opString useBaseRuby ''
# Prevent the baseruby from being included in the closure. # Prevent the baseruby from being included in the closure.
sed -i '/^ CONFIG\["BASERUBY"\]/d' $rbConfig ${removeReferencesTo}/bin/remove-references-to \
sed -i "s|'--with-baseruby=${baseruby}/bin/ruby'||" $rbConfig -t ${baseRuby} \
$rbConfig $out/lib/libruby*
''; '';
disallowedRequisites = op (!jitSupport) stdenv.cc.cc; disallowedRequisites = op (!jitSupport) stdenv.cc.cc
++ op useBaseRuby baseRuby;
meta = with lib; { meta = with lib; {
description = "The Ruby language"; description = "The Ruby language";
@ -227,7 +225,6 @@ let
passthru = rec { passthru = rec {
version = ver; version = ver;
rubyEngine = "ruby"; rubyEngine = "ruby";
baseRuby = baseruby;
libPath = "lib/${rubyEngine}/${ver.libDir}"; libPath = "lib/${rubyEngine}/${ver.libDir}";
gemPath = "lib/${rubyEngine}/gems/${ver.libDir}"; gemPath = "lib/${rubyEngine}/gems/${ver.libDir}";
devEnv = import ./dev.nix { devEnv = import ./dev.nix {
@ -246,6 +243,8 @@ let
minorVersion = ver.minor; minorVersion = ver.minor;
teenyVersion = ver.tiny; teenyVersion = ver.tiny;
patchLevel = ver.patchLevel; patchLevel = ver.patchLevel;
} // lib.optionalAttrs useBaseRuby {
inherit baseRuby;
}; };
} }
) args; in self; ) args; in self;