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

haskell: remove unused LDFLAGS in generic-builder #43825

Closed

Conversation

matthewbauer
Copy link
Member

@matthewbauer matthewbauer commented Jul 19, 2018

Once haskell has found a package.conf.d file, it no longer needs the
traditional -L flag. This commit removes the additional arguments from
NIX_LDFLAGS to prevent some systems from hitting the ARG_MAX limit.
This should accomplish the same thing as moving the $libdir somewhere
else without some of the breakages that would come with.

I don't have a macOS machine right now so cannot verify that this fixes the original issue. I can verify that it correctly removes the extra args from NIX_LDFLAGS though.

/cc @angerman @peti @Ericson2314 @domenkozar @nh2

@matthewbauer
Copy link
Member Author

@GrahamcOfBorg build haskell.packages.ghc821Binary.aeson

@GrahamcOfBorg
Copy link

No attempt on aarch64-linux (full log)

The following builds were skipped because they don't evaluate on aarch64-linux: haskell.packages.ghc821Binary.aeson

Partial log (click to expand)


a) For `nixos-rebuild` you can set
  { nixpkgs.config.allowUnsupportedSystem = true; }
in configuration.nix to override this.

b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
  { allowUnsupportedSystem = true; }
to ~/.config/nixpkgs/config.nix.


@GrahamcOfBorg
Copy link

Failure on x86_64-linux (full log)

Attempted: haskell.packages.ghc821Binary.aeson

Partial log (click to expand)

[14 of 24] Compiling Data.Aeson.Internal.Time ( Data/Aeson/Internal/Time.hs, dist/build/Data/Aeson/Internal/Time.o )
[15 of 24] Compiling Data.Aeson.Encoding.Builder ( Data/Aeson/Encoding/Builder.hs, dist/build/Data/Aeson/Encoding/Builder.o )
[16 of 24] Compiling Data.Aeson.Encoding.Internal ( Data/Aeson/Encoding/Internal.hs, dist/build/Data/Aeson/Encoding/Internal.o )
[17 of 24] Compiling Data.Aeson.Encoding ( Data/Aeson/Encoding.hs, dist/build/Data/Aeson/Encoding.o )
[18 of 24] Compiling Data.Aeson.Types.ToJSON ( Data/Aeson/Types/ToJSON.hs, dist/build/Data/Aeson/Types/ToJSON.o )

<no location info>: error:
    <command line>: can't load .so/.DLL for: libHSprimitive-0.6.3.0-9BHPmR1c3jBGsNX8V107zp.so (libHSprimitive-0.6.3.0-9BHPmR1c3jBGsNX8V107zp.so: cannot open shared object file: No such file or directory)
builder for '/nix/store/hzb8vsgif9znrbivk20layd442cffhqh-aeson-1.3.1.1.drv' failed with exit code 1
error: build of '/nix/store/hzb8vsgif9znrbivk20layd442cffhqh-aeson-1.3.1.1.drv' failed

@GrahamcOfBorg
Copy link

Failure on x86_64-darwin (full log)

Attempted: haskell.packages.ghc821Binary.aeson

Partial log (click to expand)

    |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
[13 of 24] Compiling Data.Aeson.Internal ( Data/Aeson/Internal.hs, dist/build/Data/Aeson/Internal.o )
[14 of 24] Compiling Data.Aeson.Internal.Time ( Data/Aeson/Internal/Time.hs, dist/build/Data/Aeson/Internal/Time.o )
[15 of 24] Compiling Data.Aeson.Encoding.Builder ( Data/Aeson/Encoding/Builder.hs, dist/build/Data/Aeson/Encoding/Builder.o )
[16 of 24] Compiling Data.Aeson.Encoding.Internal ( Data/Aeson/Encoding/Internal.hs, dist/build/Data/Aeson/Encoding/Internal.o )
[17 of 24] Compiling Data.Aeson.Encoding ( Data/Aeson/Encoding.hs, dist/build/Data/Aeson/Encoding.o )
[18 of 24] Compiling Data.Aeson.Types.ToJSON ( Data/Aeson/Types/ToJSON.hs, dist/build/Data/Aeson/Types/ToJSON.o )
<command line>: can't load .so/.DLL for: libHSprimitive-0.6.3.0-9BHPmR1c3jBGsNX8V107zp.dylib (dlopen(libHSprimitive-0.6.3.0-9BHPmR1c3jBGsNX8V107zp.dylib, 5): image not found)
builder for '/nix/store/01glywapkq5205rql032zmbarwac7wzv-aeson-1.3.1.1.drv' failed with exit code 1
�[31;1merror:�[0m build of '/nix/store/01glywapkq5205rql032zmbarwac7wzv-aeson-1.3.1.1.drv' failed

@matthewbauer
Copy link
Member Author

matthewbauer commented Jul 19, 2018

@GrahamcOfBorg build haskellPackages.aeson

@GrahamcOfBorg
Copy link

No attempt on aarch64-linux (full log)

The following builds were skipped because they don't evaluate on aarch64-linux: haskellPacakages.aeson

Partial log (click to expand)

Cannot nix-instantiate `haskellPacakages.aeson' because:
error: attribute 'haskellPacakages' in selection path 'haskellPacakages.aeson' not found

@GrahamcOfBorg
Copy link

No attempt on aarch64-linux (full log)

The following builds were skipped because they don't evaluate on aarch64-linux: haskellPackages.aeson

Partial log (click to expand)


a) For `nixos-rebuild` you can set
  { nixpkgs.config.allowUnsupportedSystem = true; }
in configuration.nix to override this.

b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
  { allowUnsupportedSystem = true; }
to ~/.config/nixpkgs/config.nix.


@GrahamcOfBorg
Copy link

No attempt on x86_64-darwin (full log)

The following builds were skipped because they don't evaluate on x86_64-darwin: haskellPacakages.aeson

Partial log (click to expand)

Cannot nix-instantiate `haskellPacakages.aeson' because:
�[31;1merror:�[0m attribute 'haskellPacakages' in selection path 'haskellPacakages.aeson' not found

@GrahamcOfBorg
Copy link

No attempt on x86_64-linux (full log)

The following builds were skipped because they don't evaluate on x86_64-linux: haskellPacakages.aeson

Partial log (click to expand)

Cannot nix-instantiate `haskellPacakages.aeson' because:
error: attribute 'haskellPacakages' in selection path 'haskellPacakages.aeson' not found

@matthewbauer
Copy link
Member Author

@GrahamcOfBorg build haskellPackages.aeson

@GrahamcOfBorg
Copy link

No attempt on aarch64-linux (full log)

The following builds were skipped because they don't evaluate on aarch64-linux: haskellPackages.aeson

Partial log (click to expand)


a) For `nixos-rebuild` you can set
  { nixpkgs.config.allowUnsupportedSystem = true; }
in configuration.nix to override this.

b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
  { allowUnsupportedSystem = true; }
to ~/.config/nixpkgs/config.nix.


@matthewbauer
Copy link
Member Author

haskell.packages.ghc821Binary.aeson is broken in master apparently.

@GrahamcOfBorg
Copy link

Failure on x86_64-linux (full log)

Attempted: haskellPackages.aeson

Partial log (click to expand)

cannot build derivation '/nix/store/11c7ld4ky104pbic8cml42gzvnrmlws9-tasty-quickcheck-0.10.drv': 9 dependencies couldn't be built
cannot build derivation '/nix/store/yhqzyz5w2zymvh37yx3f1ms7ydqy17d8-base-orphans-0.7.drv': 5 dependencies couldn't be built
cannot build derivation '/nix/store/r7dqa6kxv4gh9j9zgkazmd8z5ipj4awd-generic-deriving-1.12.2.drv': 5 dependencies couldn't be built
cannot build derivation '/nix/store/ahpp96yyjdfxdz2qslq2czn9nwm67jag-uuid-types-1.0.3.drv': 10 dependencies couldn't be built
cannot build derivation '/nix/store/arzpmycwc4kba5idq880mfsnkrhlrry5-tasty-ant-xml-1.1.4.drv': 6 dependencies couldn't be built
cannot build derivation '/nix/store/rv8xk8wl7vmx4c7y1mjypr7q3bawlhlc-scientific-0.3.6.2.drv': 12 dependencies couldn't be built
cannot build derivation '/nix/store/yj689hd526j91xaz1xgf9d0414ylgfv8-attoparsec-0.13.2.2.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/rmz0jrdi10aknmdxw70h9bh88rlli6hk-quickcheck-instances-0.3.18.drv': 13 dependencies couldn't be built
cannot build derivation '/nix/store/833as91vmwjv3gqya9invsvrni84ay2n-aeson-1.3.1.1.drv': 25 dependencies couldn't be built
error: build of '/nix/store/833as91vmwjv3gqya9invsvrni84ay2n-aeson-1.3.1.1.drv' failed

@GrahamcOfBorg
Copy link

Failure on x86_64-darwin (full log)

Attempted: haskellPackages.aeson

Partial log (click to expand)

cannot build derivation '/nix/store/y1wkhgkgnssk5864fv7vvjwry6c29alc-tasty-quickcheck-0.10.drv': 9 dependencies couldn't be built
cannot build derivation '/nix/store/9fs67lhn1735an8w74x6b5y55m4gx70b-base-orphans-0.7.drv': 5 dependencies couldn't be built
cannot build derivation '/nix/store/6zz43lqpng19qj1439izzd8sp30psabd-generic-deriving-1.12.2.drv': 5 dependencies couldn't be built
cannot build derivation '/nix/store/cxkyag0sgv0qbbg2nkwpy2nl9nn8fb6w-uuid-types-1.0.3.drv': 10 dependencies couldn't be built
cannot build derivation '/nix/store/613g1y5wrl6341f46x0imljhvs4lsf7l-tasty-ant-xml-1.1.4.drv': 6 dependencies couldn't be built
cannot build derivation '/nix/store/s7mmzgk24dpyb2ll7rbfpfqfvw8lhcza-scientific-0.3.6.2.drv': 12 dependencies couldn't be built
cannot build derivation '/nix/store/by703w7aqvx90n5g06cakcwj8qacj821-attoparsec-0.13.2.2.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/9hvjpzyi25i4zpizx0rfzrz528qliaia-quickcheck-instances-0.3.18.drv': 13 dependencies couldn't be built
cannot build derivation '/nix/store/q3m6rdqjjbbsxzsxb7vi9vqdk8k9a52z-aeson-1.3.1.1.drv': 25 dependencies couldn't be built
�[31;1merror:�[0m build of '/nix/store/q3m6rdqjjbbsxzsxb7vi9vqdk8k9a52z-aeson-1.3.1.1.drv' failed

@GrahamcOfBorg
Copy link

Failure on x86_64-linux (full log)

Attempted: haskellPackages.aeson

Partial log (click to expand)

cannot build derivation '/nix/store/11c7ld4ky104pbic8cml42gzvnrmlws9-tasty-quickcheck-0.10.drv': 9 dependencies couldn't be built
cannot build derivation '/nix/store/yhqzyz5w2zymvh37yx3f1ms7ydqy17d8-base-orphans-0.7.drv': 5 dependencies couldn't be built
cannot build derivation '/nix/store/r7dqa6kxv4gh9j9zgkazmd8z5ipj4awd-generic-deriving-1.12.2.drv': 5 dependencies couldn't be built
cannot build derivation '/nix/store/ahpp96yyjdfxdz2qslq2czn9nwm67jag-uuid-types-1.0.3.drv': 10 dependencies couldn't be built
cannot build derivation '/nix/store/arzpmycwc4kba5idq880mfsnkrhlrry5-tasty-ant-xml-1.1.4.drv': 6 dependencies couldn't be built
cannot build derivation '/nix/store/rv8xk8wl7vmx4c7y1mjypr7q3bawlhlc-scientific-0.3.6.2.drv': 12 dependencies couldn't be built
cannot build derivation '/nix/store/yj689hd526j91xaz1xgf9d0414ylgfv8-attoparsec-0.13.2.2.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/rmz0jrdi10aknmdxw70h9bh88rlli6hk-quickcheck-instances-0.3.18.drv': 13 dependencies couldn't be built
cannot build derivation '/nix/store/833as91vmwjv3gqya9invsvrni84ay2n-aeson-1.3.1.1.drv': 25 dependencies couldn't be built
error: build of '/nix/store/833as91vmwjv3gqya9invsvrni84ay2n-aeson-1.3.1.1.drv' failed

@GrahamcOfBorg
Copy link

Failure on x86_64-darwin (full log)

Attempted: haskellPackages.aeson

Partial log (click to expand)

cannot build derivation '/nix/store/y1wkhgkgnssk5864fv7vvjwry6c29alc-tasty-quickcheck-0.10.drv': 9 dependencies couldn't be built
cannot build derivation '/nix/store/9fs67lhn1735an8w74x6b5y55m4gx70b-base-orphans-0.7.drv': 5 dependencies couldn't be built
cannot build derivation '/nix/store/6zz43lqpng19qj1439izzd8sp30psabd-generic-deriving-1.12.2.drv': 5 dependencies couldn't be built
cannot build derivation '/nix/store/cxkyag0sgv0qbbg2nkwpy2nl9nn8fb6w-uuid-types-1.0.3.drv': 10 dependencies couldn't be built
cannot build derivation '/nix/store/613g1y5wrl6341f46x0imljhvs4lsf7l-tasty-ant-xml-1.1.4.drv': 6 dependencies couldn't be built
cannot build derivation '/nix/store/s7mmzgk24dpyb2ll7rbfpfqfvw8lhcza-scientific-0.3.6.2.drv': 12 dependencies couldn't be built
cannot build derivation '/nix/store/by703w7aqvx90n5g06cakcwj8qacj821-attoparsec-0.13.2.2.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/9hvjpzyi25i4zpizx0rfzrz528qliaia-quickcheck-instances-0.3.18.drv': 13 dependencies couldn't be built
cannot build derivation '/nix/store/q3m6rdqjjbbsxzsxb7vi9vqdk8k9a52z-aeson-1.3.1.1.drv': 25 dependencies couldn't be built
�[31;1merror:�[0m build of '/nix/store/q3m6rdqjjbbsxzsxb7vi9vqdk8k9a52z-aeson-1.3.1.1.drv' failed

Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

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

Yes I approve of this until we do the mass-rebuild

@dezgeg
Copy link
Contributor

dezgeg commented Jul 20, 2018

Couldn't some build script in principle compile and run some C code that say, generates numeric tables that get embedded in the source code or whatever? Sounds like #43713 achieves the same thing as this PR except breaking such cases.

@peti peti removed their request for review July 20, 2018 16:41
@matthewbauer
Copy link
Member Author

matthewbauer commented Jul 20, 2018

Couldn't some build script in principle compile and run some C code that say, generates numeric tables that get embedded in the source code or whatever? Sounds like #43713 achieves the same thing as this PR except breaking such cases.

I'm a little bit confused because I think the effect of these two PRs should be the same.

I think you're right that in theory a package could have something installed in $out/lib/lib* & want it. But GHC's package.conf.d stuff provides a way to configure the location of these libraries. They shouldn't be relying on LDFLAGS anyway (they can set library locations with library-dirs). I think we want GHC+Cabal to handle as much here as possible.

Once haskell has found a package.conf.d file, it no longer needs the
traditional -L flag. This commit removes the additional arguments from
NIX_LDFLAGS to prevent some systems from hitting the ARG_MAX limit.
This should accomplish the same thing as moving the $libdir somewhere
else without some of the breakages that would come with

/cc @angerman @peti @Ericson2314

- also remove NIX_BUILD_LDFLAGS

- protect against accidental removal of added flags

in the generic-builder, we want to make sure the NIX_LDFLAGS removal
hack only removes the flags that have been added. We make sure that
for instance the pattern:

  -L/nix/store/...-hello-1.0/lib

Doesn’t also remove

  -L/nix/store/...-hello-1.0/lib64

Which must have been added by someone manually (or gotten by some
other setup hook).
@dezgeg
Copy link
Contributor

dezgeg commented Jul 21, 2018

No, I mean that a Haskell package declares a dependency on some C library, then at build time compiles and runs some standalone C code that requires that library. With this solution the C program wouldn't link.

@domenkozar
Copy link
Member

I don't like this approach as well, because it builds on hacks of hacks. I'd rather see stdenv rebuild where we make binutils setup-hook idempotent. I'm going to give that a go.

@dezgeg
Copy link
Contributor

dezgeg commented Jul 21, 2018

Yes I agree, but I think the idea was to have a temporary workaround that isn't a mass rebuild to have Haskell-on-Darwin working sooner. But if you can stand a mass rebuild, I think what I proposed here matthewbauer@110b5e0#r29781349 could do. It's a legit optimization as well to avoid GCC from searching directories that can't possibly contain libraries but might fix Haskell for now.

Of course the duplicate LDFLAGS issue needs fixing regardless.

@domenkozar
Copy link
Member

If I understand that commit correctly it goes into the right direction, but we want to set LDFLAGS once and then skip the rest of invocations. strictDeps fixes that in general case of setup-hooks, but we could only fix it for binutils setup-hook.

@dezgeg
Copy link
Contributor

dezgeg commented Jul 21, 2018

No, what I propose does nothing to the duplicate LDFLAGS problem, it's a totally orthogonal thing. Instead, it skips adding LDFLAGS for derivations that don't contain any 'real' libraries in $out/lib, which is the case for Haskell and Python (and probably other interpreted language) packages.

@domenkozar
Copy link
Member

That's a good optimization, given that lib prefix is always required in general - I thought it's a convention, but maybe we can rebuild nixpkgs and see? Maybe we should allow an escape hatch to override skipping?

@dezgeg I think we can get through staging quickly if we pick a solution that doesn't require lots of overrides.

@domenkozar
Copy link
Member

domenkozar commented Jul 21, 2018

Actually this won't work as you have lib prefix in haskell libs: /nix/store/566jym0vydcdmpz0li5azwh5cxj36hj6-mmorph-1.1.2/lib/ghc-8.4.3/mmorph-1.1.2/libHSmmorph-1.1.2-u5n0PR0ucK5U9RRLpSUlt.

If you limit yourself to depth 1, lots of packages will break since you have $name/lib/$name/libfoo.hs as a common pattern as well.

@dezgeg
Copy link
Contributor

dezgeg commented Jul 21, 2018

If you limit yourself to depth 1, lots of packages will break [...]

No, it won't break. If you have some package creating $foo/lib/foo/libfoo.so, then a linker flag -L $foo/lib cannot possibly be used to reach that .so file. gcc -lfoo won't work since that would look for $foo/lib/libfoo.so. And gcc -lfoo/foo won't work either since GCC will look for $foo/lib/libfoo/foo.so.

Though now I realize that while this should always work for Linux, I have no idea about other platforms.

@angerman
Copy link
Contributor

Linux/BSD/macOS will likely behave quite similar and I think they adhere to the lib... convention, except for frameworks on macOS, but that’s a whole different story with different linker flags and all.

Windows is a completely different beast though. And also often sticks the .dlls into bin. I would just ignore windows for now until we have a unified approach for windows.

@domenkozar
Copy link
Member

@dezgeg happy to throw 10 hetzner machines to the problem if you code that up :)

@dezgeg
Copy link
Contributor

dezgeg commented Jul 21, 2018

I looked around a bit:

  • Slashes in -l arguments (like -lfoo/bar) are already unportable; ld.gold does not support them. I'm not really sure how popular ld.gold actually is, however.
  • Apparently, it's possible to skip the lib prefix with a syntax like gcc -l:foo.a. I have never heard of that syntax, and it's not even documented on gcc manpage, you have to look in ld manpage. And this syntax isn't supported by lld.ld on Darwin.
  • However with ld.lld on Darwin, using an .o suffix like -lfoo.o will search for a file named foo.o. I can't make enough sense of the binutils code to see if it happens with ld.bfd or ld.gold on Darwin... Which one does macOS use nowadays anyway? And what does Nixpkgs use there?

So, I guess there still could be a theoretical problem with this, but it would have to be quite unconventional code. I guess it's worth giving a try. I pushed an attempt at: https://github.com/dezgeg/nixpkgs/tree/binutils-lflags

@matthewbauer
Copy link
Member Author

matthewbauer commented Jul 21, 2018

No, I mean that a Haskell package declares a dependency on some C library, then at build time compiles and runs some standalone C code that requires that library. With this solution the C program wouldn't link.

Well this only removes ldflags it if it has the package.conf.d directory. I guess it's possible for there to be a c library that also has a package.conf.d directory but it seems pretty unlikely (also unsupported by things like stack where I don't think they mess with ldflags at all).

I definitely agree that this is a hack but it seems much safer than moving $out/lib to $out while accomplishing the same thing. As I mentioned there, moving $out/lib will break the withPackages wrapper unless we have some sort of a workaround ready for the moved libdir.

@angerman
Copy link
Contributor

@dezgeg macOS has its own linker ld64.

@domenkozar
Copy link
Member

@dezgeg great, 10 Hetzner servers are crunching. I'll also test macos a tiny bit, then we can push to staging.

@domenkozar
Copy link
Member

@dezgeg seems to be all good, can you make a PR against staging-next?

@domenkozar
Copy link
Member

I took the liberty and pushed the commit to staging, release-small.nix builds on linux.

@matthewbauer
Copy link
Member Author

Ok awesome! I will close this for now. Hopefully it is no longer needed!

@nh2
Copy link
Contributor

nh2 commented Sep 10, 2018

Can somebody update me: Is a fix for this in master by now?

@matthewbauer
Copy link
Member Author

Yes it is definitely in master now.

@nh2
Copy link
Contributor

nh2 commented Sep 10, 2018

I see, it's commit 24596d7, pulled in with 099c13d.

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

7 participants