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

ghc: support building with integer-simple #22121

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions doc/languages-frameworks/haskell.md
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,64 @@ It's important to realize, however, that most system libraries in Nix are built
as shared libraries only, i.e. there is just no static library available that
Cabal could link!

### Building GHC with integer-simple

By default GHC implements the Integer type using the
[GNU Multiple Precision Arithmetic (GMP) library](https://gmplib.org/).
The implementation can be found in the
[integer-gmp](http://hackage.haskell.org/package/integer-gmp) package.

A potential problem with this is that GMP is licensed under the
[​GNU Lesser General Public License (LGPL)](http://www.gnu.org/copyleft/lesser.html),
a kind of "copyleft" license. According to the terms of the LGPL, paragraph 5,
you may distribute a program that is designed to be compiled and dynamically
linked with the library under the terms of your choice (i.e., commercially) but
if your program incorporates portions of the library, if it is linked
statically, then your program is a "derivative"--a "work based on the
library"--and according to paragraph 2, section c, you "must cause the whole of
the work to be licensed" under the terms of the LGPL (including for free).

The LGPL licensing for GMP is a problem for the overall licensing of binary
programs compiled with GHC because most distributions (and builds) of GHC use
static libraries. (Dynamic libraries are currently distributed only for OS X.)
The LGPL licensing situation may be worse: even though
​[The Glasgow Haskell Compiler License](https://www.haskell.org/ghc/license)
is essentially a "free software" license (BSD3), according to
paragraph 2 of the LGPL, GHC must be distributed under the terms of the LGPL!

To work around these problems GHC can be build with a slower but LGPL-free
alternative implemention for Integer called
[integer-simple](http://hackage.haskell.org/package/integer-simple).

To get a GHC compiler build with `integer-simple` instead of `integer-gmp` use
the attribute: `pkgs.haskell.compiler.integer-simple."${ghcVersion}"`.
For example:

$ nix-build -E '(import <nixpkgs> {}).pkgs.haskell.compiler.integer-simple.ghc802'
...
$ result/bin/ghc-pkg list | grep integer
integer-simple-0.1.1.1

The following command displays the complete list of GHC compilers build with `integer-simple`:

$ nix-env -f "<nixpkgs>" -qaP -A haskell.compiler.integer-simple
haskell.compiler.integer-simple.ghc7102 ghc-7.10.2
haskell.compiler.integer-simple.ghc7103 ghc-7.10.3
haskell.compiler.integer-simple.ghc722 ghc-7.2.2
haskell.compiler.integer-simple.ghc742 ghc-7.4.2
haskell.compiler.integer-simple.ghc763 ghc-7.6.3
haskell.compiler.integer-simple.ghc783 ghc-7.8.3
haskell.compiler.integer-simple.ghc784 ghc-7.8.4
haskell.compiler.integer-simple.ghc801 ghc-8.0.1
haskell.compiler.integer-simple.ghc802 ghc-8.0.2
haskell.compiler.integer-simple.ghcHEAD ghc-8.1.20170106

To get a package set supporting `integer-simple` use the attribute:
`pkgs.haskell.packages.integer-simple."${ghcVersion}"`. For example
use the following to get the `scientific` package build with `integer-simple`:

$ nix-build -A pkgs.haskell.packages.integer-simple.ghc802.scientific


## Other resources

Expand Down
18 changes: 13 additions & 5 deletions pkgs/development/compilers/ghc/7.10.2.nix
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
{ stdenv, fetchurl, fetchpatch, bootPkgs, perl, gmp, ncurses, libiconv, binutils, coreutils
{ stdenv, fetchurl, fetchpatch, bootPkgs, perl, ncurses, libiconv, binutils, coreutils
, libxml2, libxslt, docbook_xsl, docbook_xml_dtd_45, docbook_xml_dtd_42, hscolour

# If enabled GHC will be build with the GPL-free but slower integer-simple
# library instead of the faster but GPLed integer-gmp library.
, enableIntegerSimple ? false, gmp
}:

let
inherit (bootPkgs) ghc;

buildMK = ''
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses.dev}/include"
libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses.out}/lib"
${stdenv.lib.optionalString stdenv.isDarwin ''
libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-includes="${libiconv}/include"
libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-libraries="${libiconv}/lib"
''}
'';
'' + (if enableIntegerSimple then ''
INTEGER_LIBRARY=integer-simple
'' else ''
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
'');

in

Expand Down Expand Up @@ -46,8 +53,9 @@ stdenv.mkDerivation rec {

configureFlags = [
"--with-gcc=${stdenv.cc}/bin/cc"
"--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
"--datadir=$doc/share/doc/ghc"
] ++ stdenv.lib.optional (! enableIntegerSimple) [
"--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
];

# required, because otherwise all symbols from HSffi.o are stripped, and
Expand Down
11 changes: 9 additions & 2 deletions pkgs/development/compilers/ghc/7.10.3.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{ stdenv, fetchurl, fetchpatch, bootPkgs, perl, gmp, ncurses, libiconv, binutils, coreutils
{ stdenv, fetchurl, fetchpatch, bootPkgs, perl, ncurses, libiconv, binutils, coreutils
, libxml2, libxslt, docbook_xsl, docbook_xml_dtd_45, docbook_xml_dtd_42, hscolour

# If enabled GHC will be build with the GPL-free but slower integer-simple
# library instead of the faster but GPLed integer-gmp library.
, enableIntegerSimple ? false, gmp
}:

let
Expand Down Expand Up @@ -38,13 +42,16 @@ stdenv.mkDerivation rec {
export NIX_LDFLAGS="$NIX_LDFLAGS -rpath $out/lib/ghc-${version}"
'' + stdenv.lib.optionalString stdenv.isDarwin ''
export NIX_LDFLAGS+=" -no_dtrace_dof"
'' + stdenv.lib.optionalString enableIntegerSimple ''
echo "INTEGER_LIBRARY=integer-simple" > mk/build.mk
'';

configureFlags = [
"--with-gcc=${stdenv.cc}/bin/cc"
"--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
"--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
"--datadir=$doc/share/doc/ghc"
] ++ stdenv.lib.optional (! enableIntegerSimple) [
"--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
] ++ stdenv.lib.optional stdenv.isDarwin [
"--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
];
Expand Down
19 changes: 14 additions & 5 deletions pkgs/development/compilers/ghc/7.2.2.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{ stdenv, fetchurl, ghc, perl, gmp, ncurses, libiconv }:
{ stdenv, fetchurl, ghc, perl, ncurses, libiconv

# If enabled GHC will be build with the GPL-free but slower integer-simple
# library instead of the faster but GPLed integer-gmp library.
, enableIntegerSimple ? false, gmp
}:

stdenv.mkDerivation rec {
version = "7.2.2";
Expand All @@ -11,18 +16,22 @@ stdenv.mkDerivation rec {

patches = [ ./fix-7.2.2-clang.patch ./relocation.patch ];

buildInputs = [ ghc perl gmp ncurses ];
buildInputs = [ ghc perl ncurses ]
++ stdenv.lib.optional (!enableIntegerSimple) gmp;

buildMK = ''
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses.dev}/include"
libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses.out}/lib"
${stdenv.lib.optionalString stdenv.isDarwin ''
libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-includes="${libiconv}/include"
libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-libraries="${libiconv}/lib"
''}
'';
'' + (if enableIntegerSimple then ''
INTEGER_LIBRARY=integer-simple
'' else ''
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
'');

preConfigure = ''
echo "${buildMK}" > mk/build.mk
Expand Down
19 changes: 14 additions & 5 deletions pkgs/development/compilers/ghc/7.4.2.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{ stdenv, fetchurl, ghc, perl, gmp, ncurses, libiconv }:
{ stdenv, fetchurl, ghc, perl, ncurses, libiconv

# If enabled GHC will be build with the GPL-free but slower integer-simple
# library instead of the faster but GPLed integer-gmp library.
, enableIntegerSimple ? false, gmp
}:

stdenv.mkDerivation rec {
version = "7.4.2";
Expand All @@ -12,18 +17,22 @@ stdenv.mkDerivation rec {

patches = [ ./fix-7.4.2-clang.patch ./relocation.patch ];

buildInputs = [ ghc perl gmp ncurses ];
buildInputs = [ ghc perl ncurses ]
++ stdenv.lib.optional (!enableIntegerSimple) gmp;

buildMK = ''
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses.dev}/include"
libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses.out}/lib"
${stdenv.lib.optionalString stdenv.isDarwin ''
libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-includes="${libiconv}/include"
libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-libraries="${libiconv}/lib"
''}
'';
'' + (if enableIntegerSimple then ''
INTEGER_LIBRARY=integer-simple
'' else ''
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
'');

preConfigure = ''
echo "${buildMK}" > mk/build.mk
Expand Down
19 changes: 14 additions & 5 deletions pkgs/development/compilers/ghc/7.6.3.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{ stdenv, fetchurl, ghc, perl, gmp, ncurses, binutils, libiconv }:
{ stdenv, fetchurl, ghc, perl, ncurses, binutils, libiconv

# If enabled GHC will be build with the GPL-free but slower integer-simple
# library instead of the faster but GPLed integer-gmp library.
, enableIntegerSimple ? false, gmp
}:

let
# The "-Wa,--noexecstack" options might be needed only with GNU ld (as opposed
Expand All @@ -19,11 +24,10 @@ in stdenv.mkDerivation rec {

patches = [ ./fix-7.6.3-clang.patch ./relocation.patch ];

buildInputs = [ ghc perl gmp ncurses ];
buildInputs = [ ghc perl ncurses ]
++ stdenv.lib.optional (!enableIntegerSimple) gmp;

buildMK = ''
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses.dev}/include"
libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses.out}/lib"
${stdenv.lib.optionalString stdenv.isDarwin ''
Expand All @@ -34,7 +38,12 @@ in stdenv.mkDerivation rec {
# Set ghcFlags for building ghc itself
SRC_HC_OPTS += ${ghcFlags}
SRC_CC_OPTS += ${cFlags}
'';
'' + (if enableIntegerSimple then ''
INTEGER_LIBRARY=integer-simple
'' else ''
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
'');

preConfigure = ''
echo "${buildMK}" > mk/build.mk
Expand Down
19 changes: 14 additions & 5 deletions pkgs/development/compilers/ghc/7.8.3.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{ stdenv, fetchurl, ghc, perl, gmp, ncurses, libiconv }:
{ stdenv, fetchurl, ghc, perl, ncurses, libiconv

# If enabled GHC will be build with the GPL-free but slower integer-simple
# library instead of the faster but GPLed integer-gmp library.
, enableIntegerSimple ? false, gmp
}:

stdenv.mkDerivation rec {
version = "7.8.3";
Expand All @@ -11,21 +16,25 @@ stdenv.mkDerivation rec {

patches = [ ./relocation.patch ];

buildInputs = [ ghc perl gmp ncurses ];
buildInputs = [ ghc perl ncurses ]
++ stdenv.lib.optional (!enableIntegerSimple) gmp;

enableParallelBuilding = true;

buildMK = ''
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses.dev}/include"
libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses.out}/lib"
DYNAMIC_BY_DEFAULT = NO
${stdenv.lib.optionalString stdenv.isDarwin ''
libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-includes="${libiconv}/include"
libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-libraries="${libiconv}/lib"
''}
'';
'' + (if enableIntegerSimple then ''
INTEGER_LIBRARY=integer-simple
'' else ''
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
'');

preConfigure = ''
echo "${buildMK}" > mk/build.mk
Expand Down
19 changes: 14 additions & 5 deletions pkgs/development/compilers/ghc/7.8.4.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{ stdenv, fetchurl, ghc, perl, gmp, ncurses, libiconv }:
{ stdenv, fetchurl, ghc, perl, ncurses, libiconv

# If enabled GHC will be build with the GPL-free but slower integer-simple
# library instead of the faster but GPLed integer-gmp library.
, enableIntegerSimple ? false, gmp
}:

stdenv.mkDerivation (rec {
version = "7.8.4";
Expand All @@ -11,21 +16,25 @@ stdenv.mkDerivation (rec {

patches = [ ./relocation.patch ];

buildInputs = [ ghc perl gmp ncurses ];
buildInputs = [ ghc perl ncurses ]
++ stdenv.lib.optional (!enableIntegerSimple) gmp;

enableParallelBuilding = true;

buildMK = ''
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-includes="${ncurses.dev}/include"
libraries/terminfo_CONFIGURE_OPTS += --configure-option=--with-curses-libraries="${ncurses.out}/lib"
DYNAMIC_BY_DEFAULT = NO
${stdenv.lib.optionalString stdenv.isDarwin ''
libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-includes="${libiconv}/include"
libraries/base_CONFIGURE_OPTS += --configure-option=--with-iconv-libraries="${libiconv}/lib"
''}
'';
'' + (if enableIntegerSimple then ''
INTEGER_LIBRARY=integer-simple
'' else ''
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-libraries="${gmp.out}/lib"
libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-gmp-includes="${gmp.dev}/include"
'');

preConfigure = ''
echo "${buildMK}" > mk/build.mk
Expand Down
11 changes: 9 additions & 2 deletions pkgs/development/compilers/ghc/8.0.1.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{ stdenv, fetchurl, fetchpatch, bootPkgs, perl, gmp, ncurses, libiconv, binutils, coreutils
{ stdenv, fetchurl, fetchpatch, bootPkgs, perl, ncurses, libiconv, binutils, coreutils
, hscolour, patchutils, sphinx

# If enabled GHC will be build with the GPL-free but slower integer-simple
# library instead of the faster but GPLed integer-gmp library.
, enableIntegerSimple ? false, gmp
}:

let
Expand Down Expand Up @@ -41,13 +45,16 @@ stdenv.mkDerivation rec {
export NIX_LDFLAGS="$NIX_LDFLAGS -rpath $out/lib/ghc-${version}"
'' + stdenv.lib.optionalString stdenv.isDarwin ''
export NIX_LDFLAGS+=" -no_dtrace_dof"
'' + stdenv.lib.optionalString enableIntegerSimple ''
echo "INTEGER_LIBRARY=integer-simple" > mk/build.mk
'';

configureFlags = [
"--with-gcc=${stdenv.cc}/bin/cc"
"--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
"--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
"--datadir=$doc/share/doc/ghc"
] ++ stdenv.lib.optional (! enableIntegerSimple) [
"--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
] ++ stdenv.lib.optional stdenv.isDarwin [
"--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
];
Expand Down
11 changes: 9 additions & 2 deletions pkgs/development/compilers/ghc/8.0.2.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{ stdenv, fetchurl, fetchpatch, bootPkgs, perl, gmp, ncurses, libiconv, binutils, coreutils
{ stdenv, fetchurl, fetchpatch, bootPkgs, perl, ncurses, libiconv, binutils, coreutils
, hscolour, patchutils, sphinx

# If enabled GHC will be build with the GPL-free but slower integer-simple
# library instead of the faster but GPLed integer-gmp library.
, enableIntegerSimple ? false, gmp
}:

let
Expand Down Expand Up @@ -35,13 +39,16 @@ stdenv.mkDerivation rec {
export NIX_LDFLAGS="$NIX_LDFLAGS -rpath $out/lib/ghc-${version}"
'' + stdenv.lib.optionalString stdenv.isDarwin ''
export NIX_LDFLAGS+=" -no_dtrace_dof"
'' + stdenv.lib.optionalString enableIntegerSimple ''
echo "INTEGER_LIBRARY=integer-simple" > mk/build.mk
'';

configureFlags = [
"--with-gcc=${stdenv.cc}/bin/cc"
"--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
"--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
"--datadir=$doc/share/doc/ghc"
] ++ stdenv.lib.optional (! enableIntegerSimple) [
"--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
] ++ stdenv.lib.optional stdenv.isDarwin [
"--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
];
Expand Down
Loading