summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrancois-Rene Rideau <fare@tunes.org>2020-03-21 00:52:59 -0400
committerFrancois-Rene Rideau <fare@tunes.org>2020-05-17 15:48:12 -0400
commit9456522528a118d9eeb078a77064a4f85ae9b887 (patch)
tree476061b28ef59a7feb81becb7c6e81572d626446
parent28c2c0156da98dbe553490f904da92ed436df134 (diff)
downloadnixpkgs-9456522528a118d9eeb078a77064a4f85ae9b887.tar
nixpkgs-9456522528a118d9eeb078a77064a4f85ae9b887.tar.gz
nixpkgs-9456522528a118d9eeb078a77064a4f85ae9b887.tar.bz2
nixpkgs-9456522528a118d9eeb078a77064a4f85ae9b887.tar.lz
nixpkgs-9456522528a118d9eeb078a77064a4f85ae9b887.tar.xz
nixpkgs-9456522528a118d9eeb078a77064a4f85ae9b887.tar.zst
nixpkgs-9456522528a118d9eeb078a77064a4f85ae9b887.zip
Refactor Gambit support
Refactor the build rule:
- Put files in $out/gambit instead of $out.
- Make the optimization setting easy to override.
- Make use of gccStdenv more explicit at this level.
- Support new-style runtime options for forcing UTF-8 I/O.
- Override the PACKAGE_VERSION and PACKAGE_STRING with git version.
- Note that the license is lgpl21, not lpgl2 (Note: also dual asl20).
- Try and fail to meaningfully add missing runtimeDeps.
- Build using NIX_BUILD_CORES.
-rw-r--r--pkgs/development/compilers/gambit/bootstrap.nix22
-rw-r--r--pkgs/development/compilers/gambit/build.nix63
-rw-r--r--pkgs/development/compilers/gambit/default.nix6
-rw-r--r--pkgs/development/compilers/gambit/gambit-support.nix33
-rw-r--r--pkgs/development/compilers/gambit/unstable.nix6
-rw-r--r--pkgs/top-level/all-packages.nix3
6 files changed, 89 insertions, 44 deletions
diff --git a/pkgs/development/compilers/gambit/bootstrap.nix b/pkgs/development/compilers/gambit/bootstrap.nix
index 2fb9e3ce2fc..ec963ab3b8d 100644
--- a/pkgs/development/compilers/gambit/bootstrap.nix
+++ b/pkgs/development/compilers/gambit/bootstrap.nix
@@ -1,6 +1,10 @@
-{ stdenv, fetchurl, autoconf, gcc, coreutils, ... }:
+# This derivation is a reduced-functionality variant of Gambit stable,
+# used to compile the full version of Gambit stable *and* unstable.
 
-stdenv.mkDerivation {
+{ gccStdenv, lib, fetchurl, autoconf, gcc, coreutils, gambit-support, ... }:
+# As explained in build.nix, GCC compiles Gambit 10x faster than Clang, for code 3x better
+
+gccStdenv.mkDerivation {
   pname = "gambit-bootstrap";
   version = "4.9.3";
 
@@ -16,29 +20,25 @@ stdenv.mkDerivation {
            CPP=${gcc}/bin/cpp CXXCPP=${gcc}/bin/cpp LD=${gcc}/bin/ld \
            XMKMF=${coreutils}/bin/false
     unset CFLAGS LDFLAGS LIBS CPPFLAGS CXXFLAGS
-    ./configure --prefix=$out
+    ./configure --prefix=$out/gambit
   '';
 
   buildPhase = ''
     # Copy the (configured) sources now, not later, so we don't have to filter out
     # all the intermediate build products.
-    mkdir -p $out ; cp -rp . $out/
+    mkdir -p $out/gambit ; cp -rp . $out/gambit/
 
     # build the gsc-boot* compiler
-    make bootstrap
+    make -j$NIX_BUILD_CORES bootstrap
   '';
 
   installPhase = ''
-    cp -fa ./ $out/
+    cp -fa ./ $out/gambit/
   '';
 
   forceShare = [ "info" ];
 
-  meta = {
+  meta = gambit-support.meta // {
     description = "Optimizing Scheme to C compiler, bootstrap step";
-    homepage    = "http://gambitscheme.org";
-    license     = stdenv.lib.licenses.lgpl2;
-    platforms   = stdenv.lib.platforms.unix;
-    maintainers = with stdenv.lib.maintainers; [ thoughtpolice raskin fare ];
   };
 }
diff --git a/pkgs/development/compilers/gambit/build.nix b/pkgs/development/compilers/gambit/build.nix
index e17241b6d98..fc71128eb37 100644
--- a/pkgs/development/compilers/gambit/build.nix
+++ b/pkgs/development/compilers/gambit/build.nix
@@ -1,11 +1,13 @@
-{ stdenv, git, openssl, autoconf, pkgs, makeStaticLibraries, version, gcc, src, coreutils }:
+{ gccStdenv, lib, git, openssl, autoconf, pkgs, makeStaticLibraries, gcc, coreutils, gnused, gnugrep,
+  src, version, git-version,
+  gambit-support, optimizationSetting ? "-O1", gambit-params ? pkgs.gambit-support.stable-params }:
 
 # Note that according to a benchmark run by Marc Feeley on May 2018,
 # clang is 10x (with default settings) to 15% (with -O2) slower than GCC at compiling
 # Gambit output, producing code that is 3x slower. IIRC the benchmarks from Gambit@30,
 # the numbers were still heavily in favor of GCC in October 2019.
 # Thus we use GCC over clang, even on macOS.
-
+#
 # Also note that I (fare) just ran benchmarks from https://github.com/ecraven/r7rs-benchmarks
 # with Gambit 4.9.3 with -O1 vs -O2 vs -Os on Feb 2020. Which wins depends on the benchmark.
 # The fight is unclear between -O1 and -O2, where -O1 wins more often, by up to 17%,
@@ -13,29 +15,34 @@
 # However, -Os seems more consistent in winning slightly against both -O1 and -O2,
 # and is overall 15% faster than -O2. As for compile times, -O1 is fastest,
 # -Os is about 29%-33% slower than -O1, while -O2 is about 40%-50% slower than -O1.
-# Overall, -Os seems like the best choice, and that's what we now use.
+#
+# Overall, -Os seems like the best choice, but I care more about compile-time,
+# so I stick with -O1 (in the defaults above), which is also the default for Gambit.
 
-stdenv.mkDerivation rec {
-  pname = "gambit";
-  inherit version;
-  inherit src;
+gccStdenv.mkDerivation rec {
 
-  bootstrap = import ./bootstrap.nix ( pkgs );
+  pname = "gambit";
+  inherit src version git-version;
+  bootstrap = gambit-support.gambit-bootstrap;
 
   # TODO: if/when we can get all the library packages we depend on to have static versions,
   # we could use something like (makeStaticLibraries openssl) to enable creation
   # of statically linked binaries by gsc.
   buildInputs = [ git autoconf bootstrap openssl ];
 
+  # TODO: patch gambit's source so it has the full path to sed, grep, fgrep? Is there more?
+  # Or wrap relevant programs to add a suitable PATH ?
+  #runtimeDeps = [ gnused gnugrep ];
+
   configureFlags = [
     "--enable-single-host"
-    "--enable-c-opt=-Os"
+    "--enable-c-opt=${optimizationSetting}"
     "--enable-gcc-opts"
     "--enable-shared"
     "--enable-absolute-shared-libs" # Yes, NixOS will want an absolute path, and fix it.
     "--enable-poll"
     "--enable-openssl"
-    "--enable-default-runtime-options=f8,-8,t8" # Default to UTF-8 for source and all I/O
+    "--enable-default-runtime-options=${gambit-params.defaultRuntimeOptions}"
     # "--enable-debug" # Nope: enables plenty of good stuff, but also the costly console.log
     # "--enable-multiple-versions" # Nope, NixOS already does version multiplexing
     # "--enable-guide"
@@ -53,11 +60,17 @@ stdenv.mkDerivation rec {
   ];
 
   configurePhase = ''
-    export CC=${gcc}/bin/gcc CXX=${gcc}/bin/g++ \
-           CPP=${gcc}/bin/cpp CXXCPP=${gcc}/bin/cpp LD=${gcc}/bin/ld \
+    export CC=${gcc}/bin/gcc \
+           CXX=${gcc}/bin/g++ \
+           CPP=${gcc}/bin/cpp \
+           CXXCPP=${gcc}/bin/cpp \
+           LD=${gcc}/bin/ld \
            XMKMF=${coreutils}/bin/false
     unset CFLAGS LDFLAGS LIBS CPPFLAGS CXXFLAGS
-    ./configure --prefix=$out ${builtins.concatStringsSep " " configureFlags}
+
+    ${gambit-params.fix-stamp git-version}
+
+    ./configure --prefix=$out/gambit ${builtins.concatStringsSep " " configureFlags}
 
     # OS-specific paths are hardcoded in ./configure
     substituteInPlace config.status \
@@ -69,28 +82,26 @@ stdenv.mkDerivation rec {
   buildPhase = ''
     # Make bootstrap compiler, from release bootstrap
     mkdir -p boot &&
-    cp -rp ${bootstrap}/. boot/. &&
+    cp -rp ${bootstrap}/gambit/. boot/. &&
     chmod -R u+w boot &&
     cd boot &&
-    cp ../gsc/makefile.in ../gsc/*.scm gsc && # */
+    cp ../gsc/makefile.in ../gsc/*.scm gsc/ && # */
     ./configure &&
-    for i in lib gsi gsc ; do (cd $i ; make ) ; done &&
+    for i in lib gsi gsc ; do (cd $i ; make -j$NIX_BUILD_CORES) ; done &&
     cd .. &&
     cp boot/gsc/gsc gsc-boot &&
 
     # Now use the bootstrap compiler to build the real thing!
-    make -j2 from-scratch
+    make -j$NIX_BUILD_CORES from-scratch
+  '';
+
+  postInstall = ''
+    mkdir $out/bin
+    cd $out/bin
+    ln -s ../gambit/bin/* .
   '';
 
   doCheck = true;
 
-  meta = {
-    description = "Optimizing Scheme to C compiler";
-    homepage    = "http://gambitscheme.org";
-    license     = stdenv.lib.licenses.lgpl2;
-    # NB regarding platforms: only actually tested on Linux, *should* work everywhere,
-    # but *might* need adaptation e.g. on macOS.
-    platforms   = stdenv.lib.platforms.unix;
-    maintainers = with stdenv.lib.maintainers; [ thoughtpolice raskin fare ];
-  };
+  meta = gambit-support.meta;
 }
diff --git a/pkgs/development/compilers/gambit/default.nix b/pkgs/development/compilers/gambit/default.nix
index 303f6a30aad..8f77daa4173 100644
--- a/pkgs/development/compilers/gambit/default.nix
+++ b/pkgs/development/compilers/gambit/default.nix
@@ -1,10 +1,10 @@
-{ stdenv, callPackage, fetchurl }:
+{ callPackage, fetchurl }:
 
-callPackage ./build.nix {
+callPackage ./build.nix rec {
   version = "4.9.3";
+  git-version = version;
   src = fetchurl {
     url = "http://www.iro.umontreal.ca/~gambit/download/gambit/v4.9/source/gambit-v4_9_3.tgz";
     sha256 = "1p6172vhcrlpjgia6hsks1w4fl8rdyjf9xjh14wxfkv7dnx8a5hk";
   };
-  inherit stdenv;
 }
diff --git a/pkgs/development/compilers/gambit/gambit-support.nix b/pkgs/development/compilers/gambit/gambit-support.nix
new file mode 100644
index 00000000000..0e78831f2e4
--- /dev/null
+++ b/pkgs/development/compilers/gambit/gambit-support.nix
@@ -0,0 +1,33 @@
+{ pkgs, lib }:
+
+rec {
+  stable-params = {
+    defaultRuntimeOptions = "f8,-8,t8";
+    buildRuntimeOptions = "f8,-8,t8";
+    fix-stamp = git-version : "";
+  };
+
+  unstable-params = {
+    defaultRuntimeOptions = "iL,fL,-L,tL";
+    buildRuntimeOptions = "i8,f8,-8,t8";
+    fix-stamp = git-version : ''
+      substituteInPlace configure \
+        --replace "$(grep '^PACKAGE_VERSION=.*$' configure)" 'PACKAGE_VERSION="v${git-version}"' \
+        --replace "$(grep '^PACKAGE_STRING=.*$' configure)" 'PACKAGE_STRING="Gambit v${git-version}"' ;
+    '';
+  };
+
+  export-gambopt = params : "export GAMBOPT=${params.buildRuntimeOptions} ;";
+
+  gambit-bootstrap = import ./bootstrap.nix ( pkgs );
+
+  meta = {
+    description = "Optimizing Scheme to C compiler";
+    homepage    = "http://gambitscheme.org";
+    license     = lib.licenses.lgpl21; # dual, also asl20
+    # NB regarding platforms: continuously tested on Linux,
+    # tested on macOS once in a while, *should* work everywhere.
+    platforms   = lib.platforms.unix;
+    maintainers = with lib.maintainers; [ thoughtpolice raskin fare ];
+  };
+}
diff --git a/pkgs/development/compilers/gambit/unstable.nix b/pkgs/development/compilers/gambit/unstable.nix
index 4c33c83c67b..7c4434acdc3 100644
--- a/pkgs/development/compilers/gambit/unstable.nix
+++ b/pkgs/development/compilers/gambit/unstable.nix
@@ -1,13 +1,13 @@
-{ stdenv, callPackage, fetchFromGitHub }:
+{ callPackage, fetchFromGitHub, gambit-support }:
 
 callPackage ./build.nix {
   version = "unstable-2020-02-24";
-# git-version = "4.9.3-979-gc69e9f70";
+  git-version = "4.9.3-979-gc69e9f70";
   src = fetchFromGitHub {
     owner = "feeley";
     repo = "gambit";
     rev = "c69e9f70dfdc6545353b135a5d5e2f9234f1e1cc";
     sha256 = "1f69n7yzzdv3wpnjlrbck38xpa8115vbady43mc544l39ckklr0k";
   };
-  inherit stdenv;
+  gambit-params = gambit-support.unstable-params;
 }
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 729f97d65a1..8a26aea2beb 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -8203,7 +8203,8 @@ in
   fpc = callPackage ../development/compilers/fpc { };
 
   gambit = callPackage ../development/compilers/gambit { stdenv = gccStdenv; };
-  gambit-unstable = callPackage ../development/compilers/gambit/unstable.nix { stdenv = gccStdenv; };
+  gambit-unstable = callPackage ../development/compilers/gambit/unstable.nix { };
+  gambit-support = callPackage ../development/compilers/gambit/gambit-support.nix { };
   gerbil = callPackage ../development/compilers/gerbil { stdenv = gccStdenv; };
   gerbil-unstable = callPackage ../development/compilers/gerbil/unstable.nix { stdenv = gccStdenv; };