Skip to content

Commit

Permalink
ghc: support building with integer-simple
Browse files Browse the repository at this point in the history
If the flag enableIntegerSimple is true GHC will be build with the
GPL-free but slower integer-simple library instead of the faster but
GPLed integer-gmp library.
  • Loading branch information
basvandijk committed Jan 28, 2017
1 parent 4a914f2 commit e1e19a0
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 38 deletions.
35 changes: 35 additions & 0 deletions doc/languages-frameworks/haskell.md
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,41 @@ 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 compiler build with `integer-simple` instead of `integer-gmp` override an
existing compiler and set `enableIntegerSimple = true`. For example:

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

## 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

0 comments on commit e1e19a0

Please sign in to comment.