ruby-modules: improve cross-compilation support

This commit is contained in:
Ivan Trubach 2023-11-26 22:18:23 +03:00
parent 77347136f6
commit 30971173ab
5 changed files with 37 additions and 8 deletions

View File

@ -1,4 +1,8 @@
{ stdenv, runCommand, ruby, lib, rsync
{ stdenv
, lib
, buildPackages
, runCommand
, ruby
, defaultGemConfig, buildRubyGem, buildEnv
, makeBinaryWrapper
, bundler
@ -190,7 +194,7 @@ let
runCommand name' basicEnvArgs ''
mkdir -p $out
for i in $paths; do
${rsync}/bin/rsync -a $i/lib $out/
${buildPackages.rsync}/bin/rsync -a $i/lib $out/
done
eval "$postBuild"
''

View File

@ -59,8 +59,21 @@ in rec {
then attrs // gemConfig.${attrs.gemName} attrs
else attrs);
genStubsScript = { lib, ruby, confFiles, bundler, groups, binPaths, ... }: ''
${ruby}/bin/ruby ${./gen-bin-stubs.rb} \
genStubsScript = { lib, runCommand, ruby, confFiles, bundler, groups, binPaths, ... }:
let
genStubsScript = runCommand "gen-bin-stubs"
{
strictDeps = true;
nativeBuildInputs = [ ruby ];
}
''
cp ${./gen-bin-stubs.rb} $out
chmod +x $out
patchShebangs --build $out
'';
in
''
${genStubsScript} \
"${ruby}/bin/ruby" \
"${confFiles}/Gemfile" \
"$out/${ruby.gemPath}" \

View File

@ -1,3 +1,4 @@
#!/usr/bin/env ruby
require 'rbconfig'
require 'rubygems'
require 'rubygems/specification'

View File

@ -1,5 +1,6 @@
{ ruby, lib, callPackage, defaultGemConfig, buildEnv, runCommand
, bundler, rsync
, buildPackages
, bundler
}@defs:
{ name ? null
@ -21,7 +22,7 @@
}@args:
let
inherit (import ../bundled-common/functions.nix {inherit lib ruby gemConfig groups; }) genStubsScript;
inherit (import ../bundled-common/functions.nix { inherit lib ruby gemConfig groups; }) genStubsScript;
basicEnv = (callPackage ../bundled-common { inherit bundler; }) (args // { inherit pname name; mainGemName = pname; });
@ -51,7 +52,7 @@ in
pathsToLink = [ "/lib" ];
postBuild = genStubsScript {
inherit lib ruby bundler groups;
inherit lib runCommand ruby bundler groups;
confFiles = basicEnv.confFiles;
binPaths = [ basicEnv.gems.${pname} ];
} + lib.optionalString (postBuild != null) postBuild;
@ -67,7 +68,7 @@ in
runCommand basicEnv.name bundlerEnvArgs ''
mkdir -p $out
for i in $paths; do
${rsync}/bin/rsync -a $i/lib $out/
${buildPackages.rsync}/bin/rsync -a $i/lib $out/
done
eval "$postBuild"
''

View File

@ -252,6 +252,16 @@ stdenv.mkDerivation ((builtins.removeAttrs attrs ["source"]) // {
runHook postInstall
'';
# For Ruby-generated binstubs, shebang paths are already in Nix store but for
# ruby used to build the package. Update them to match the host system. Note
# that patchShebangsAuto ignores scripts where shebang line is already in Nix
# store.
fixupPhase = attrs.fixupPhase or ''
runHook preFixup
patchShebangs --update --host $out/${ruby.gemPath}/bin
runHook postFixup
'';
propagatedBuildInputs = gemPath ++ propagatedBuildInputs;
propagatedUserEnvPkgs = gemPath ++ propagatedUserEnvPkgs;