-
Notifications
You must be signed in to change notification settings - Fork 81
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
Support GHC with static RTS #970
Conversation
To test rules_haskell with a static GHC on Unix you can apply the following patch to define the corresponding Nix override: diff --git a/nixpkgs/default.nix b/nixpkgs/default.nix
index f4303b0..c2e01ca 100644
--- a/nixpkgs/default.nix
+++ b/nixpkgs/default.nix
@@ -1,5 +1,31 @@
+{ ... }@args:
import (fetchTarball {
# Checkout from 2019-05-06.
url = https://github.com/mboes/nixpkgs/archive/361e9185c83166b44419e05e75fc8473875df6ea.tar.gz;
sha256 = "0c6izp9i1ln4yy2h9jlm48k94f018h8pw60jfbhq49p076aaafrb";
+}) (args // {
+ overlays = (args.overlays or []) ++ [
+ (_: pkgs: {
+ haskell = pkgs.haskell // {
+ compiler = pkgs.haskell.compiler // {
+ ghc865 = (pkgs.haskell.compiler.ghc865.override {
+ enableRelocatedStaticLibs = true;
+ enableShared = false;
+ }).overrideAttrs (attrs: {
+ # enableRelocatedStaticLibs = true only sets -fPIC. However, with
+ # enableShared = false we also require -fexternal-dynamic-refs,
+ # otherwise GHC still generates R_X86_64_PC32 relocations which
+ # prevents loading these static libraries as PIC.
+ preConfigure = ''
+ ${attrs.preConfigure or ""}
+ cat <<EOF >>mk/build.mk
+ GhcLibHcOpts += -fPIC -fexternal-dynamic-refs
+ GhcRtsHcOpts += -fPIC -fexternal-dynamic-refs
+ EOF
+ '';
+ });
+ };
+ };
+ })
+ ];
}) |
dd9384e
to
5afbc0d
Compare
Rebased on master and awaiting review. |
haskell/private/workspace_utils.bzl
Outdated
|
||
return ghc | ||
|
||
def ghc_is_static(repository_ctx): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't play nicely with RBE, or any cross-compilation for that matter.
Rather than autodetection, it may be better to ask the user to say whether the toolchain is static or not, since this is going to complicate the cross compilation case. It's like compiler versions. In the case of Nixpkgs, compiler versions in the WORKSPACE file are redundant, since we can auto detect them. But we can only reliably detect them in narrow cases: when the build architecture matches the host architecture. Here, if the target architecture is different from host or build, |
I agree that we shouldn’t do autodetection because of RBE (haven’t reviewed yet though). |
Addressing review comment #970 (comment) The predifined bindists only come with a static GHC on Windows. Nixpkgs defaults to a dynamic GHC, but the user can override that default.
I was hoping we could go the opposite direction and also autodetect the version, since a wrong version setting can lead to pretty confusing error messages. However, it seems that wouldn't work RBE either then. Static GHC seems like a niche use-case, so I'm fine with it requiring some manual setup. |
GHC can be compiled with a static RTS. This allows static only linking with GHC, including for GHCi and Template Haskell. The RTS mode of GHC is detected automatically on toolchain setup.
Addressing review comment #970 (comment) The predifined bindists only come with a static GHC on Windows. Nixpkgs defaults to a dynamic GHC, but the user can override that default.
Debian seems to have updated the default to libtinfo6, but the GHC bindist requires libtinfo5.
GHC can be compiled with a static RTS. This allows to use only static Haskell librarires including for GHCi and Template Haskell. This is the default on Windows.
This PR adds support for a static GHC on Unix as well. The mode of GHC (static or dynamic) is detected automatically during toolchain setup.