lol

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.

+89 -44
+11 -11
pkgs/development/compilers/gambit/bootstrap.nix
··· 1 - { stdenv, fetchurl, autoconf, gcc, coreutils, ... }: 1 + # This derivation is a reduced-functionality variant of Gambit stable, 2 + # used to compile the full version of Gambit stable *and* unstable. 2 3 3 - stdenv.mkDerivation { 4 + { gccStdenv, lib, fetchurl, autoconf, gcc, coreutils, gambit-support, ... }: 5 + # As explained in build.nix, GCC compiles Gambit 10x faster than Clang, for code 3x better 6 + 7 + gccStdenv.mkDerivation { 4 8 pname = "gambit-bootstrap"; 5 9 version = "4.9.3"; 6 10 ··· 16 20 CPP=${gcc}/bin/cpp CXXCPP=${gcc}/bin/cpp LD=${gcc}/bin/ld \ 17 21 XMKMF=${coreutils}/bin/false 18 22 unset CFLAGS LDFLAGS LIBS CPPFLAGS CXXFLAGS 19 - ./configure --prefix=$out 23 + ./configure --prefix=$out/gambit 20 24 ''; 21 25 22 26 buildPhase = '' 23 27 # Copy the (configured) sources now, not later, so we don't have to filter out 24 28 # all the intermediate build products. 25 - mkdir -p $out ; cp -rp . $out/ 29 + mkdir -p $out/gambit ; cp -rp . $out/gambit/ 26 30 27 31 # build the gsc-boot* compiler 28 - make bootstrap 32 + make -j$NIX_BUILD_CORES bootstrap 29 33 ''; 30 34 31 35 installPhase = '' 32 - cp -fa ./ $out/ 36 + cp -fa ./ $out/gambit/ 33 37 ''; 34 38 35 39 forceShare = [ "info" ]; 36 40 37 - meta = { 41 + meta = gambit-support.meta // { 38 42 description = "Optimizing Scheme to C compiler, bootstrap step"; 39 - homepage = "http://gambitscheme.org"; 40 - license = stdenv.lib.licenses.lgpl2; 41 - platforms = stdenv.lib.platforms.unix; 42 - maintainers = with stdenv.lib.maintainers; [ thoughtpolice raskin fare ]; 43 43 }; 44 44 }
+37 -26
pkgs/development/compilers/gambit/build.nix
··· 1 - { stdenv, git, openssl, autoconf, pkgs, makeStaticLibraries, version, gcc, src, coreutils }: 1 + { gccStdenv, lib, git, openssl, autoconf, pkgs, makeStaticLibraries, gcc, coreutils, gnused, gnugrep, 2 + src, version, git-version, 3 + gambit-support, optimizationSetting ? "-O1", gambit-params ? pkgs.gambit-support.stable-params }: 2 4 3 5 # Note that according to a benchmark run by Marc Feeley on May 2018, 4 6 # clang is 10x (with default settings) to 15% (with -O2) slower than GCC at compiling 5 7 # Gambit output, producing code that is 3x slower. IIRC the benchmarks from Gambit@30, 6 8 # the numbers were still heavily in favor of GCC in October 2019. 7 9 # Thus we use GCC over clang, even on macOS. 8 - 10 + # 9 11 # Also note that I (fare) just ran benchmarks from https://github.com/ecraven/r7rs-benchmarks 10 12 # with Gambit 4.9.3 with -O1 vs -O2 vs -Os on Feb 2020. Which wins depends on the benchmark. 11 13 # The fight is unclear between -O1 and -O2, where -O1 wins more often, by up to 17%, ··· 13 15 # However, -Os seems more consistent in winning slightly against both -O1 and -O2, 14 16 # and is overall 15% faster than -O2. As for compile times, -O1 is fastest, 15 17 # -Os is about 29%-33% slower than -O1, while -O2 is about 40%-50% slower than -O1. 16 - # Overall, -Os seems like the best choice, and that's what we now use. 18 + # 19 + # Overall, -Os seems like the best choice, but I care more about compile-time, 20 + # so I stick with -O1 (in the defaults above), which is also the default for Gambit. 17 21 18 - stdenv.mkDerivation rec { 19 - pname = "gambit"; 20 - inherit version; 21 - inherit src; 22 + gccStdenv.mkDerivation rec { 22 23 23 - bootstrap = import ./bootstrap.nix ( pkgs ); 24 + pname = "gambit"; 25 + inherit src version git-version; 26 + bootstrap = gambit-support.gambit-bootstrap; 24 27 25 28 # TODO: if/when we can get all the library packages we depend on to have static versions, 26 29 # we could use something like (makeStaticLibraries openssl) to enable creation 27 30 # of statically linked binaries by gsc. 28 31 buildInputs = [ git autoconf bootstrap openssl ]; 29 32 33 + # TODO: patch gambit's source so it has the full path to sed, grep, fgrep? Is there more? 34 + # Or wrap relevant programs to add a suitable PATH ? 35 + #runtimeDeps = [ gnused gnugrep ]; 36 + 30 37 configureFlags = [ 31 38 "--enable-single-host" 32 - "--enable-c-opt=-Os" 39 + "--enable-c-opt=${optimizationSetting}" 33 40 "--enable-gcc-opts" 34 41 "--enable-shared" 35 42 "--enable-absolute-shared-libs" # Yes, NixOS will want an absolute path, and fix it. 36 43 "--enable-poll" 37 44 "--enable-openssl" 38 - "--enable-default-runtime-options=f8,-8,t8" # Default to UTF-8 for source and all I/O 45 + "--enable-default-runtime-options=${gambit-params.defaultRuntimeOptions}" 39 46 # "--enable-debug" # Nope: enables plenty of good stuff, but also the costly console.log 40 47 # "--enable-multiple-versions" # Nope, NixOS already does version multiplexing 41 48 # "--enable-guide" ··· 53 60 ]; 54 61 55 62 configurePhase = '' 56 - export CC=${gcc}/bin/gcc CXX=${gcc}/bin/g++ \ 57 - CPP=${gcc}/bin/cpp CXXCPP=${gcc}/bin/cpp LD=${gcc}/bin/ld \ 63 + export CC=${gcc}/bin/gcc \ 64 + CXX=${gcc}/bin/g++ \ 65 + CPP=${gcc}/bin/cpp \ 66 + CXXCPP=${gcc}/bin/cpp \ 67 + LD=${gcc}/bin/ld \ 58 68 XMKMF=${coreutils}/bin/false 59 69 unset CFLAGS LDFLAGS LIBS CPPFLAGS CXXFLAGS 60 - ./configure --prefix=$out ${builtins.concatStringsSep " " configureFlags} 70 + 71 + ${gambit-params.fix-stamp git-version} 72 + 73 + ./configure --prefix=$out/gambit ${builtins.concatStringsSep " " configureFlags} 61 74 62 75 # OS-specific paths are hardcoded in ./configure 63 76 substituteInPlace config.status \ ··· 69 82 buildPhase = '' 70 83 # Make bootstrap compiler, from release bootstrap 71 84 mkdir -p boot && 72 - cp -rp ${bootstrap}/. boot/. && 85 + cp -rp ${bootstrap}/gambit/. boot/. && 73 86 chmod -R u+w boot && 74 87 cd boot && 75 - cp ../gsc/makefile.in ../gsc/*.scm gsc && # */ 88 + cp ../gsc/makefile.in ../gsc/*.scm gsc/ && # */ 76 89 ./configure && 77 - for i in lib gsi gsc ; do (cd $i ; make ) ; done && 90 + for i in lib gsi gsc ; do (cd $i ; make -j$NIX_BUILD_CORES) ; done && 78 91 cd .. && 79 92 cp boot/gsc/gsc gsc-boot && 80 93 81 94 # Now use the bootstrap compiler to build the real thing! 82 - make -j2 from-scratch 95 + make -j$NIX_BUILD_CORES from-scratch 96 + ''; 97 + 98 + postInstall = '' 99 + mkdir $out/bin 100 + cd $out/bin 101 + ln -s ../gambit/bin/* . 83 102 ''; 84 103 85 104 doCheck = true; 86 105 87 - meta = { 88 - description = "Optimizing Scheme to C compiler"; 89 - homepage = "http://gambitscheme.org"; 90 - license = stdenv.lib.licenses.lgpl2; 91 - # NB regarding platforms: only actually tested on Linux, *should* work everywhere, 92 - # but *might* need adaptation e.g. on macOS. 93 - platforms = stdenv.lib.platforms.unix; 94 - maintainers = with stdenv.lib.maintainers; [ thoughtpolice raskin fare ]; 95 - }; 106 + meta = gambit-support.meta; 96 107 }
+3 -3
pkgs/development/compilers/gambit/default.nix
··· 1 - { stdenv, callPackage, fetchurl }: 1 + { callPackage, fetchurl }: 2 2 3 - callPackage ./build.nix { 3 + callPackage ./build.nix rec { 4 4 version = "4.9.3"; 5 + git-version = version; 5 6 src = fetchurl { 6 7 url = "http://www.iro.umontreal.ca/~gambit/download/gambit/v4.9/source/gambit-v4_9_3.tgz"; 7 8 sha256 = "1p6172vhcrlpjgia6hsks1w4fl8rdyjf9xjh14wxfkv7dnx8a5hk"; 8 9 }; 9 - inherit stdenv; 10 10 }
+33
pkgs/development/compilers/gambit/gambit-support.nix
··· 1 + { pkgs, lib }: 2 + 3 + rec { 4 + stable-params = { 5 + defaultRuntimeOptions = "f8,-8,t8"; 6 + buildRuntimeOptions = "f8,-8,t8"; 7 + fix-stamp = git-version : ""; 8 + }; 9 + 10 + unstable-params = { 11 + defaultRuntimeOptions = "iL,fL,-L,tL"; 12 + buildRuntimeOptions = "i8,f8,-8,t8"; 13 + fix-stamp = git-version : '' 14 + substituteInPlace configure \ 15 + --replace "$(grep '^PACKAGE_VERSION=.*$' configure)" 'PACKAGE_VERSION="v${git-version}"' \ 16 + --replace "$(grep '^PACKAGE_STRING=.*$' configure)" 'PACKAGE_STRING="Gambit v${git-version}"' ; 17 + ''; 18 + }; 19 + 20 + export-gambopt = params : "export GAMBOPT=${params.buildRuntimeOptions} ;"; 21 + 22 + gambit-bootstrap = import ./bootstrap.nix ( pkgs ); 23 + 24 + meta = { 25 + description = "Optimizing Scheme to C compiler"; 26 + homepage = "http://gambitscheme.org"; 27 + license = lib.licenses.lgpl21; # dual, also asl20 28 + # NB regarding platforms: continuously tested on Linux, 29 + # tested on macOS once in a while, *should* work everywhere. 30 + platforms = lib.platforms.unix; 31 + maintainers = with lib.maintainers; [ thoughtpolice raskin fare ]; 32 + }; 33 + }
+3 -3
pkgs/development/compilers/gambit/unstable.nix
··· 1 - { stdenv, callPackage, fetchFromGitHub }: 1 + { callPackage, fetchFromGitHub, gambit-support }: 2 2 3 3 callPackage ./build.nix { 4 4 version = "unstable-2020-02-24"; 5 - # git-version = "4.9.3-979-gc69e9f70"; 5 + git-version = "4.9.3-979-gc69e9f70"; 6 6 src = fetchFromGitHub { 7 7 owner = "feeley"; 8 8 repo = "gambit"; 9 9 rev = "c69e9f70dfdc6545353b135a5d5e2f9234f1e1cc"; 10 10 sha256 = "1f69n7yzzdv3wpnjlrbck38xpa8115vbady43mc544l39ckklr0k"; 11 11 }; 12 - inherit stdenv; 12 + gambit-params = gambit-support.unstable-params; 13 13 }
+2 -1
pkgs/top-level/all-packages.nix
··· 8203 8203 fpc = callPackage ../development/compilers/fpc { }; 8204 8204 8205 8205 gambit = callPackage ../development/compilers/gambit { stdenv = gccStdenv; }; 8206 - gambit-unstable = callPackage ../development/compilers/gambit/unstable.nix { stdenv = gccStdenv; }; 8206 + gambit-unstable = callPackage ../development/compilers/gambit/unstable.nix { }; 8207 + gambit-support = callPackage ../development/compilers/gambit/gambit-support.nix { }; 8207 8208 gerbil = callPackage ../development/compilers/gerbil { stdenv = gccStdenv; }; 8208 8209 gerbil-unstable = callPackage ../development/compilers/gerbil/unstable.nix { stdenv = gccStdenv; }; 8209 8210