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

haskellPackages: add ghcForStatic #3194

Closed
wants to merge 2 commits into from
Closed

Conversation

vcunat
Copy link
Member

@vcunat vcunat commented Jul 6, 2014

It's built with gmp that contains static libraries as well,
so one is able to build statically linked haskell programs.

Example:

$ echo "main = undefined" > test.hs

$ ghc -optl-static -optl-pthread test.hs
[1 of 1] Compiling Main             ( test.hs, test.o )
Linking test ...
/nix/store/1qqhbh9w3mhsl48bsn73ln68ixxv7frz-ghc-7.6.3/lib/ghc-7.6.3/libHSrts.a(Linker.o): In function `addDLL':
Linker.c:(.text+0x1a19): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

$ ldd ./test
        not a dynamic executable

This is just a proof of concept:

  • I don't really use Haskell for anything, so it's likely that a different way of plugging into haskellPackages will be better. CC: @peti, etc.?
  • It's probable that when using stuff linked against more non-haskell libs, the static part of those might be missing.

It's built with gmp that contains static libraries as well,
so one is able to build statically linked haskell programs.
@vcunat
Copy link
Member Author

vcunat commented Jul 6, 2014

Hmm, maybe I should've made the wrapper pass these additional flags automatically. Well, I believe some real users are needed to finish this.

@peti
Copy link
Member

peti commented Jul 7, 2014

Shouldn't GHC refer unconditionally to a static-linking-enabled version of GMP? I mean, having those additional *.a files lying around doesn't cost much, right? It seems okay to just hard-code that variant instead of introducing yet another different flavor of the GHC compiler.

@peti peti added the haskell label Jul 7, 2014
@vcunat
Copy link
Member Author

vcunat commented Jul 7, 2014

Yes, thanks, I was being blind. I did check that the additional files add ~1.5 MB and the rest of gmp is even smaller. When I look at the sizes of Haskell stuff, this is really negligible :-D

@vcunat
Copy link
Member Author

vcunat commented Jul 7, 2014

Updated. This will result into recompilation of all haskell stuff, so the interested people should test before merging. Otherwise we might find soon that e.g. zlib or something is also causing problems.

Also, I read this links glibc in statically, which can cause problems running on a system with even a slightly different version of (g)libc (they write). http://stackoverflow.com/questions/8657908/deploying-yesod-to-heroku-cant-build-statically/8658468#8658468

# see thread http://permalink.gmane.org/gmane.linux.distributions.nixos/13526
gmp = gmp.override { withStatic = true; };
};
};
Copy link
Member

Choose a reason for hiding this comment

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

This kind of override probably won't work because pkgs is a recursive set. When I run

nix-build ~/.nix-defexpr -A haskellPackages_ghc782.ghcPlain --dry-run

with this patch applied, it doesn't re-build anything. I'm still trying to figure out what the proper way is to achieve the desired effect.

@peti
Copy link
Member

peti commented Jul 7, 2014

Okay ... the following code snippet in all-packages.nix does the trick:

haskell = let pkgs_       = pkgs // { gmp = gmp.override { withStatic = true; }; };
              callPackage = newScope pkgs_;
          in callPackage ./haskell-defaults.nix { pkgs = pkgs_; inherit callPackage; };

I'm not sure whether it's a good idea for haskell-defaults.nix to take both pkgs and callPackage as arguments, because the latter is a part of the former, actually, but figuring out the proper way to refactor this requires more brain power than I have right now.

@peti
Copy link
Member

peti commented Jul 7, 2014

I've committed the patch to a branch as e7cd8178c00d8731873cd80313f7772276ecdea4. Hydra is building it at http://hydra.nixos.org/jobset/nixpkgs/haskell-updates.

@vcunat
Copy link
Member Author

vcunat commented Jul 7, 2014

Ah, I didn't notice that callPackage was passed as well. (I'm too overheated these days to be able to think properly.)

@peti
Copy link
Member

peti commented Jul 7, 2014

Frankly, the code that sets up these Haskell packages is a mess. I'm sure this whole boot-strapping logic can be simplified quite a bit. It's just that worrying about this kind of thing is exhausting and inconvenient, so I typically prefer flashier tasks such as updating some library. :-)

@pSub
Copy link
Member

pSub commented Jul 12, 2014

Is this pull request still relevant in the presence of #3232?

@vcunat
Copy link
Member Author

vcunat commented Jul 13, 2014

@pSub: I guess #3232 contains the haskell-updates branch which contains an equivalent of this PR. (Github will probably close this when it gets into master, which is the right moment IMO.)

@peti
Copy link
Member

peti commented Jul 13, 2014

Merged. Thanks for patch, Vladimir!

@peti peti closed this Jul 13, 2014
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

3 participants