@@ -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}