Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at flake-libs 163 lines 5.9 kB view raw
1{ 2 gccStdenv, 3 lib, 4 pkgs, 5 git, 6 openssl, 7 autoconf, 8 coreutils, 9 src, 10 version, 11 git-version, 12 stampYmd ? 0, 13 stampHms ? 0, 14 gambit-support, 15 optimizationSetting ? "-O1", 16 gambit-params ? pkgs.gambit-support.stable-params, 17 rev ? git-version, 18}: 19 20# Note that according to a benchmark run by Marc Feeley on May 2018, 21# clang is 10x (with default settings) to 15% (with -O2) slower than GCC at compiling 22# Gambit output, producing code that is 3x slower. IIRC the benchmarks from Gambit@30, 23# the numbers were still heavily in favor of GCC in October 2019. 24# Thus we use GCC over clang, even on macOS. 25# 26# Also note that I (fare) just ran benchmarks from https://github.com/ecraven/r7rs-benchmarks 27# with Gambit 4.9.3 with -O1 vs -O2 vs -Os on Feb 2020. Which wins depends on the benchmark. 28# The fight is unclear between -O1 and -O2, where -O1 wins more often, by up to 17%, 29# but sometimes -O2 wins, once by up to 43%, so that overall -O2 is 5% faster. 30# However, -Os seems more consistent in winning slightly against both -O1 and -O2, 31# and is overall 15% faster than -O2. As for compile times, -O1 is fastest, 32# -Os is about 29%-33% slower than -O1, while -O2 is about 40%-50% slower than -O1. 33# 34# Overall, -Os seems like the best choice, but I care more about compile-time, 35# so I stick with -O1 (in the defaults above), which is also the default for Gambit. 36 37gccStdenv.mkDerivation rec { 38 39 pname = "gambit"; 40 inherit src version git-version; 41 bootstrap = gambit-support.gambit-bootstrap; 42 43 passthru = { 44 inherit 45 src 46 version 47 git-version 48 rev 49 stampYmd 50 stampHms 51 optimizationSetting 52 openssl 53 ; 54 }; 55 56 nativeBuildInputs = [ 57 git 58 autoconf 59 ]; 60 61 # TODO: if/when we can get all the library packages we depend on to have static versions, 62 # we could use something like (makeStaticLibraries openssl) to enable creation 63 # of statically linked binaries by gsc. 64 buildInputs = [ openssl ]; 65 66 # TODO: patch gambit's source so it has the full path to sed, grep, fgrep? Is there more? 67 # Or wrap relevant programs to add a suitable PATH ? 68 #runtimeDeps = [ gnused gnugrep ]; 69 70 configureFlags = 71 [ 72 "--enable-targets=${gambit-params.targets}" 73 "--enable-single-host" 74 "--enable-c-opt=${optimizationSetting}" 75 "--enable-c-opt-rts=-O2" 76 "--enable-gcc-opts" 77 "--enable-trust-c-tco" 78 "--enable-shared" 79 "--enable-absolute-shared-libs" # Yes, NixOS will want an absolute path, and fix it. 80 "--enable-openssl" 81 "--enable-dynamic-clib" 82 #"--enable-default-compile-options='(compactness 9)'" # Make life easier on the JS backend 83 "--enable-default-runtime-options=${gambit-params.defaultRuntimeOptions}" 84 # "--enable-rtlib-debug" # used by Geiser, but only on recent-enough gambit, and messes js runtime 85 # "--enable-debug" # Nope: enables plenty of good stuff, but also the costly console.log 86 # "--enable-multiple-versions" # Nope, NixOS already does version multiplexing 87 # "--enable-guide" 88 # "--enable-track-scheme" 89 # "--enable-high-res-timing" 90 # "--enable-max-processors=4" 91 # "--enable-multiple-vms" 92 # "--enable-dynamic-tls" 93 # "--enable-multiple-threaded-vms" # when SMP branch is merged in 94 # "--enable-thread-system=posix" # default when --enable-multiple-vms is on. 95 # "--enable-profile" 96 # "--enable-coverage" 97 # "--enable-inline-jumps" 98 # "--enable-char-size=1" # default is 4 99 # "--enable-march=native" # Nope, makes it not work on machines older than the builder 100 ] 101 ++ gambit-params.extraOptions 102 # TODO: pick an appropriate architecture to optimize on on x86-64? 103 # https://gcc.gnu.org/onlinedocs/gcc-4.8.4/gcc/i386-and-x86-64-Options.html#i386-and-x86-64-Options 104 # ++ lib.optional pkgs.stdenv.hostPlatform.isx86_64 "--enable-march=core-avx2" 105 # Do not enable poll on darwin due to https://github.com/gambit/gambit/issues/498 106 ++ lib.optional (!gccStdenv.hostPlatform.isDarwin) "--enable-poll"; 107 108 configurePhase = '' 109 export CC=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}gcc \ 110 CXX=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}g++ \ 111 CPP=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}cpp \ 112 CXXCPP=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}cpp \ 113 LD=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}ld \ 114 XMKMF=${coreutils}/bin/false 115 unset CFLAGS LDFLAGS LIBS CPPFLAGS CXXFLAGS 116 117 ${gambit-params.fixStamp git-version stampYmd stampHms} 118 119 ./configure --prefix=$out/gambit ${builtins.concatStringsSep " " configureFlags} 120 121 # OS-specific paths are hardcoded in ./configure 122 substituteInPlace config.status \ 123 ${ 124 lib.optionalString ( 125 gccStdenv.hostPlatform.isDarwin && !gambit-params.stable 126 ) ''--replace "/usr/local/opt/openssl@1.1" "${lib.getLib openssl}"'' 127 } \ 128 --replace "/usr/local/opt/openssl" "${lib.getLib openssl}" 129 130 ./config.status 131 ''; 132 133 buildPhase = '' 134 # The MAKEFLAGS setting is a workaround for https://github.com/gambit/gambit/issues/833 135 export MAKEFLAGS="--output-sync=recurse" 136 echo "Make bootstrap compiler, from release bootstrap" 137 mkdir -p boot 138 cp -rp ${bootstrap}/gambit/. boot/. 139 chmod -R u+w boot 140 cd boot 141 cp ../gsc/makefile.in ../gsc/*.scm gsc/ 142 echo > include/stamp.h # No stamp needed for the bootstrap compiler 143 ./configure 144 for i in lib gsi gsc ; do (cd $i ; make -j$NIX_BUILD_CORES) ; done 145 cd .. 146 cp boot/gsc/gsc gsc-boot 147 148 echo "Now use the bootstrap compiler to build the real thing!" 149 make -j$NIX_BUILD_CORES from-scratch 150 ${lib.optionalString gambit-params.modules "make -j$NIX_BUILD_CORES modules"} 151 ''; 152 153 postInstall = '' 154 mkdir $out/bin 155 cd $out/bin 156 ln -s ../gambit/bin/* . 157 ''; 158 159 doCheck = true; 160 dontStrip = true; 161 162 meta = gambit-support.meta; 163}