Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

podofo: fix library linkage on Darwin #47214

Merged
merged 2 commits into from Sep 25, 2018
Merged

podofo: fix library linkage on Darwin #47214

merged 2 commits into from Sep 25, 2018

Conversation

mroi
Copy link
Contributor

@mroi mroi commented Sep 23, 2018

The podofo package is currently broken on Darwin: the podofo tools do not find libpodofo.0.9.6.dylib at runtime, because the library path the binary is linked against is incomplete.

The reason is that podofo builds both the library and the tools using this library in the same cmake run. And since the library is not yet installed when the tools are build, it does not contain the final store path as its install name. Linking the tools therefore picks up this incorrect install name.

I fixed this with a fixupPost script. I am not sure this is the correct way, since I am rather new to Nix, but the package works on Darwin now and this should have no effect for Linux.

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

Because the library is not yet installed when the tools are build, it does not contain its final store path as its install name. Linking the tools picks up this incorrect install name and needs to be fixed after installing.
@LnL7
Copy link
Member

LnL7 commented Sep 24, 2018

This is really strange, the dylib does have a correct install_name. The fact that the binaries built before the libraries are installed is not a problem and exactly what the install_name is for. It's used by the linker to allow linking against absolute paths while the library isn't installed in it's final location yet.

@mroi
Copy link
Contributor Author

mroi commented Sep 24, 2018

The dylib only receives its correct install_name when it is installed. The binaries are built before that, where the install_name of the library was still containing only the filename without any path information. At least that’s what happens when I observed the build. I am not a cmake expert, though.

I guess it works fine when you only build a library and then another project links against that library. But doing both in the same cmake build appears not to work properly.

@mroi
Copy link
Contributor Author

mroi commented Sep 25, 2018

Fact is that the current podofo package from the Hydra cache does not work on my macOS (18A389). Running the tools fail with this message:

dyld: Library not loaded: libpodofo.0.9.6.dylib
  Referenced from: /nix/store/gakcb85280a3d42v6j6qvz1p75bj42h5-podofo-0.9.6/bin/podofobox
  Reason: image not found
Abort trap: 6

@LnL7
Copy link
Member

LnL7 commented Sep 25, 2018

Hmm, that's unfortunate. Guess they must be using some nonstandard build scripts because I've not seen this before with cmake builds.

@@ -30,6 +31,12 @@ stdenv.mkDerivation rec {

cmakeFlags = "-DPODOFO_BUILD_SHARED=ON -DPODOFO_BUILD_STATIC=OFF";

postFixup = if stdenv.isDarwin then ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick, use stdenv.lib.optionalString instead of an if statement.

use stdenv.lib.optionalString instead of an if statement
@mroi
Copy link
Contributor Author

mroi commented Sep 25, 2018

Thanks a lot for this tip. I am rather new to Nix, so I did not know about stdenv.lib.optionalString. I fixed the pull request.

@LnL7
Copy link
Member

LnL7 commented Sep 25, 2018

No big deal 😄. It does about the same thing, but it's slightly nicer to use IMHO.

@LnL7 LnL7 merged commit 4b1ffa0 into NixOS:master Sep 25, 2018
@mroi mroi deleted the patch-2 branch September 25, 2018 20:13
@mroi
Copy link
Contributor Author

mroi commented Sep 25, 2018

I agree. Thanks for making contributing to Nix such a nice experience.

LnL7 pushed a commit that referenced this pull request Sep 25, 2018
* podofo: fix library linkage on Darwin

Because the library is not yet installed when the tools are build, it does not contain its final store path as its install name. Linking the tools picks up this incorrect install name and needs to be fixed after installing.

(cherry picked from commit 4b1ffa0)
@LnL7
Copy link
Member

LnL7 commented Sep 25, 2018

That's great to hear! Feel free to ping the NixOS/darwin-maintainers group or me if you make other darwin contributions that don't get the attention of the correct people. The repository is very active and sometimes changes can get a bit lost if people with relevant knowledge miss it.

backported to 18.09 in 0253b1e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants