git.iko.soy/typeable/nixpkgs
on master help sign in
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.

commit9456522528a118d9eeb078a77064a4f85ae9b887 authorFrancois-Rene Rideau <fare@tunes.org> dateSat 21 Mar 2020, 00:52 (7 years ago) parent28c2c01
6 files changed+89−44
pkgs/development/compilers/gambit/bootstrap.nix+11−11 pkgs/development/compilers/gambit/build.nix+37−26 pkgs/development/compilers/gambit/default.nix+3−3 pkgs/development/compilers/gambit/gambit-support.nix+33 pkgs/development/compilers/gambit/unstable.nix+3−3 pkgs/top-level/all-packages.nix+2−1
pkgs/development/compilers/gambit/bootstrap.nix+11−11
@@ -1,6 +1,10 @@
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.
23
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 {
48 pname = "gambit-bootstrap";
59 version = "4.9.3";
610
@@ -16,29 +20,25 @@ stdenv.mkDerivation {
1620 CPP=${gcc}/bin/cpp CXXCPP=${gcc}/bin/cpp LD=${gcc}/bin/ld \
1721 XMKMF=${coreutils}/bin/false
1822 unset CFLAGS LDFLAGS LIBS CPPFLAGS CXXFLAGS
19− ./configure --prefix=$out
23+ ./configure --prefix=$out/gambit
2024 '';
2125
2226 buildPhase = ''
2327 # Copy the (configured) sources now, not later, so we don't have to filter out
2428 # all the intermediate build products.
25− mkdir -p $out ; cp -rp . $out/
29+ mkdir -p $out/gambit ; cp -rp . $out/gambit/
2630
2731 # build the gsc-boot* compiler
28− make bootstrap
32+ make -j$NIX_BUILD_CORES bootstrap
2933 '';
3034
3135 installPhase = ''
32− cp -fa ./ $out/
36+ cp -fa ./ $out/gambit/
3337 '';
3438
3539 forceShare = [ "info" ];
3640
37− meta = {
41+ meta = gambit-support.meta // {
3842 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 ];
4343 };
4444}
pkgs/development/compilers/gambit/build.nix+37−26
@@ -1,11 +1,13 @@
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 }:
24
35# Note that according to a benchmark run by Marc Feeley on May 2018,
46# clang is 10x (with default settings) to 15% (with -O2) slower than GCC at compiling
57# Gambit output, producing code that is 3x slower. IIRC the benchmarks from Gambit@30,
68# the numbers were still heavily in favor of GCC in October 2019.
79# Thus we use GCC over clang, even on macOS.
8−
10+#
911# Also note that I (fare) just ran benchmarks from https://github.com/ecraven/r7rs-benchmarks
1012# with Gambit 4.9.3 with -O1 vs -O2 vs -Os on Feb 2020. Which wins depends on the benchmark.
1113# The fight is unclear between -O1 and -O2, where -O1 wins more often, by up to 17%,
@@ -13,29 +15,34 @@
1315# However, -Os seems more consistent in winning slightly against both -O1 and -O2,
1416# and is overall 15% faster than -O2. As for compile times, -O1 is fastest,
1517# -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.
1721
18−stdenv.mkDerivation rec {
19− pname = "gambit";
20− inherit version;
21− inherit src;
22+gccStdenv.mkDerivation rec {
2223
23− bootstrap = import ./bootstrap.nix ( pkgs );
24+ pname = "gambit";
25+ inherit src version git-version;
26+ bootstrap = gambit-support.gambit-bootstrap;
2427
2528 # TODO: if/when we can get all the library packages we depend on to have static versions,
2629 # we could use something like (makeStaticLibraries openssl) to enable creation
2730 # of statically linked binaries by gsc.
2831 buildInputs = [ git autoconf bootstrap openssl ];
2932
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+
3037 configureFlags = [
3138 "--enable-single-host"
32− "--enable-c-opt=-Os"
39+ "--enable-c-opt=${optimizationSetting}"
3340 "--enable-gcc-opts"
3441 "--enable-shared"
3542 "--enable-absolute-shared-libs" # Yes, NixOS will want an absolute path, and fix it.
3643 "--enable-poll"
3744 "--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}"
3946 # "--enable-debug" # Nope: enables plenty of good stuff, but also the costly console.log
4047 # "--enable-multiple-versions" # Nope, NixOS already does version multiplexing
4148 # "--enable-guide"
@@ -53,11 +60,17 @@ stdenv.mkDerivation rec {
5360 ];
5461
5562 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 \
5868 XMKMF=${coreutils}/bin/false
5969 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}
6174
6275 # OS-specific paths are hardcoded in ./configure
6376 substituteInPlace config.status \
@@ -69,28 +82,26 @@ stdenv.mkDerivation rec {
6982 buildPhase = ''
7083 # Make bootstrap compiler, from release bootstrap
7184 mkdir -p boot &&
72− cp -rp ${bootstrap}/. boot/. &&
85+ cp -rp ${bootstrap}/gambit/. boot/. &&
7386 chmod -R u+w boot &&
7487 cd boot &&
75− cp ../gsc/makefile.in ../gsc/*.scm gsc && # */
88+ cp ../gsc/makefile.in ../gsc/*.scm gsc/ && # */
7689 ./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 &&
7891 cd .. &&
7992 cp boot/gsc/gsc gsc-boot &&
8093
8194 # 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/* .
83102 '';
84103
85104 doCheck = true;
86105
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;
96107}
pkgs/development/compilers/gambit/default.nix+3−3
@@ -1,10 +1,10 @@
1−{ stdenv, callPackage, fetchurl }:
1+{ callPackage, fetchurl }:
22
3−callPackage ./build.nix {
3+callPackage ./build.nix rec {
44 version = "4.9.3";
5+ git-version = version;
56 src = fetchurl {
67 url = "http://www.iro.umontreal.ca/~gambit/download/gambit/v4.9/source/gambit-v4_9_3.tgz";
78 sha256 = "1p6172vhcrlpjgia6hsks1w4fl8rdyjf9xjh14wxfkv7dnx8a5hk";
89 };
9− inherit stdenv;
1010}
pkgs/development/compilers/gambit/gambit-support.nixnew file+33
@@ -0,0 +1,33 @@
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+}
pkgs/development/compilers/gambit/unstable.nix+3−3
@@ -1,13 +1,13 @@
1−{ stdenv, callPackage, fetchFromGitHub }:
1+{ callPackage, fetchFromGitHub, gambit-support }:
22
33callPackage ./build.nix {
44 version = "unstable-2020-02-24";
5−# git-version = "4.9.3-979-gc69e9f70";
5+ git-version = "4.9.3-979-gc69e9f70";
66 src = fetchFromGitHub {
77 owner = "feeley";
88 repo = "gambit";
99 rev = "c69e9f70dfdc6545353b135a5d5e2f9234f1e1cc";
1010 sha256 = "1f69n7yzzdv3wpnjlrbck38xpa8115vbady43mc544l39ckklr0k";
1111 };
12− inherit stdenv;
12+ gambit-params = gambit-support.unstable-params;
1313}
pkgs/top-level/all-packages.nix+2−1
@@ -8203,7 +8203,8 @@ in
82038203 fpc = callPackage ../development/compilers/fpc { };
82048204
82058205 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 { };
82078208 gerbil = callPackage ../development/compilers/gerbil { stdenv = gccStdenv; };
82088209 gerbil-unstable = callPackage ../development/compilers/gerbil/unstable.nix { stdenv = gccStdenv; };
82098210