Skip to content

Commit

Permalink
Merge #2135
Browse files Browse the repository at this point in the history
2135: Fix dylib references of bundled programs on macOS r=rvl a=rvl

### Issue Number

Resolves #2134

### Overview

- On macOS rewrite dylib references from `/nix/store` to `@executable_path` - for every executable in the bundle.
- Add linking tests to `check-bundle.rb` for macOS and Linux.


Co-authored-by: Rodney Lorrimar <[email protected]>
  • Loading branch information
iohk-bors[bot] and rvl authored Sep 17, 2020
2 parents 29a67fe + e43dace commit 6e39dc1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion nix/linux-release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let
in pkgs.stdenv.mkDerivation {
inherit name;
buildInputs = with pkgs.buildPackages; [ gnutar gzip binutils ];
checkInputs = [ pkgs.buildPackages.ruby ];
checkInputs = with pkgs.buildPackages; [ ruby gnugrep glibc.bin ];
doCheck = true;
phases = [ "buildPhase" "checkPhase" ];
tarname = "${name}-linux64.tar.gz";
Expand Down
16 changes: 14 additions & 2 deletions nix/macos-release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,27 @@ let

in pkgs.stdenv.mkDerivation {
inherit name;
buildInputs = with pkgs.buildPackages; [ gnutar gzip binutils ];
checkInputs = [ pkgs.buildPackages.ruby ];
buildInputs = with pkgs.buildPackages; [
gnutar
gzip
binutils
commonLib.haskell-nix-extra-packages.haskellBuildUtils.package
nix
];
checkInputs = with pkgs.buildPackages; [
ruby
gnugrep
gnused
darwin.cctools
];
doCheck = true;
phases = [ "buildPhase" "checkPhase" ];
tarname = "${name}-macos64.tar.gz";
buildPhase = ''
mkdir $name
cp -nR ${concatMapStringsSep " " (exe: "${exe}/bin/*") exes} $name
chmod -R 755 $name
( cd $name; rewrite-libs . `ls -1 | grep -Fv .dylib` )
mkdir -p $out/nix-support
tar -czf $out/$tarname $name
Expand Down
8 changes: 3 additions & 5 deletions release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,18 @@ let
# Release distribution jobs - these all have a Hydra download link.

# Which exes should be put in the release archive.
releaseContents = rec {
releaseContents = {
jormungandr = [
"cardano-wallet-jormungandr"
"jormungandr"
"jormungandr-cli"
];
cardanoNodeCommon = [
shelley = [
"cardano-wallet"
"bech32"
"cardano-address"
"cardano-cli"
"cardano-node"
"cardano-tx"
];
shelley = [ "cardano-wallet" ] ++ cardanoNodeCommon;
};

# function to take a list of jobs by name from a jobset.
Expand Down
23 changes: 19 additions & 4 deletions scripts/check-bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
############################################################################
# Checks that every executable required in the release package is
# present and works.
# On Linux it checks if executables are statically linked.
# On macOS it checks that there are no /nix/store dylibs.
############################################################################

require 'open3'

tests = {
"cardano-wallet-jormungandr" => [ "jormungandr", "jcli" ],
"cardano-wallet-jormungandr" => [ ],
"cardano-wallet" => [ "cardano-node", "cardano-cli", "bech32", "cardano-tx", "cardano-address" ]
}

Expand All @@ -33,15 +35,28 @@ def report(cmd, status)
end

cmd = "#{wallet} version"
ver, status = Open3.capture2("#{runner} #{cmd}")
report(cmd, status.to_i)
begin
ver, status = Open3.capture2("#{runner} #{cmd}")
report(cmd, status.to_i)
rescue Errno::ENOENT
report(cmd, 1)
end

tests[wallet].each do |cmd|
tests[wallet].unshift(wallet).each do |cmd|
begin
stdout_str, status = Open3.capture2("#{runner} #{cmd} --help")
report(cmd, status.to_i)
rescue Errno::ENOENT
report(cmd, 1)
next
end

if /darwin/ =~ RUBY_PLATFORM then
system("! otool -L `type -p #{cmd}` | sed 1d | grep nix");
report("#{cmd} is free of /nix/store", $?.exitstatus)
elsif /linux/ =~ RUBY_PLATFORM then
system("! ldd `type -p #{cmd}` > /dev/null");
report("#{cmd} is static linked", $?.exitstatus)
end
end

Expand Down

0 comments on commit 6e39dc1

Please sign in to comment.