git.iko.soy/typeable/nixpkgs
on master help sign in
Refactor Gerbil support

- Use the new Gambit support. - Move files from $out to $out/gerbil. - Use new Gerbil configuration and installation scripts. - Move some fixups from preBuild to postPatch. - Give up on previous failed attempts at using static libraries. - Add support for compiling libraries written in Gerbil. - Build using NIX_BUILD_CORES. - Register all those things in all-packages.

commit90835bc666881cfc9d4f632379f58684dea4a590 authorFrancois-Rene Rideau <fare@tunes.org> dateSat 21 Mar 2020, 00:53 (7 years ago) parent9456522
5 files changed+161−60
pkgs/development/compilers/gerbil/build.nix+31−50 pkgs/development/compilers/gerbil/default.nix+39−3 pkgs/development/compilers/gerbil/gerbil-support.nix+63 pkgs/development/compilers/gerbil/unstable.nix+23−4 pkgs/top-level/all-packages.nix+5−3
pkgs/development/compilers/gerbil/build.nix+31−50
@@ -1,34 +1,35 @@
1−{ stdenv, makeStaticLibraries,
2− coreutils, rsync, bash,
1+{ pkgs, gccStdenv, lib, coreutils, # makeStaticLibraries,
32 openssl, zlib, sqlite, libxml2, libyaml, libmysqlclient, lmdb, leveldb, postgresql,
4− version, git-version, gambit, src }:
3+ version, git-version,
4+ gambit-support,
5+ gambit ? pkgs.gambit, gambit-params ? pkgs.gambit-support.stable-params,
6+ src, configurePhase, installPhase }:
7+
8+# We use Gambit, that works 10x better with GCC than Clang. See ../gambit/build.nix
9+let stdenv = gccStdenv; in
510
611stdenv.mkDerivation rec {
712 pname = "gerbil";
813 inherit version;
914 inherit src;
1015
11− # Use makeStaticLibraries to enable creation of statically linked binaries
1216 buildInputs_libraries = [ openssl zlib sqlite libxml2 libyaml libmysqlclient lmdb leveldb postgresql ];
13− buildInputs_staticLibraries = map makeStaticLibraries buildInputs_libraries;
1417
15− buildInputs = [ gambit rsync bash ]
16− ++ buildInputs_libraries ++ buildInputs_staticLibraries;
18+ # TODO: either fix all of Gerbil's dependencies to provide static libraries,
19+ # or give up and delete all tentative support for static libraries.
20+ #buildInputs_staticLibraries = map makeStaticLibraries buildInputs_libraries;
21+
22+ buildInputs = [ gambit ]
23+ ++ buildInputs_libraries; # ++ buildInputs_staticLibraries;
1724
1825 NIX_CFLAGS_COMPILE = "-I${libmysqlclient}/include/mysql -L${libmysqlclient}/lib/mysql";
1926
2027 postPatch = ''
21− echo '(define (gerbil-version-string) "v${git-version}")' > src/gerbil/runtime/gx-version.scm
22−
23− patchShebangs .
24−
28+ echo '(define (gerbil-version-string) "v${git-version}")' > src/gerbil/runtime/gx-version.scm ;
29+ patchShebangs . ;
2530 grep -Fl '#!/usr/bin/env' `find . -type f -executable` | while read f ; do
26− substituteInPlace "$f" --replace '#!/usr/bin/env' '#!${coreutils}/bin/env'
27− done
28− grep -Fl '"gsc"' `find . -type f -name '*.s*'` | while read f ; do
29− substituteInPlace "$f" --replace '"gsc"' '"${gambit}/bin/gsc"'
30− done
31− substituteInPlace "etc/gerbil.el" --replace '"gxc"' "\"$out/bin/gxc\""
31+ substituteInPlace "$f" --replace '#!/usr/bin/env' '#!${coreutils}/bin/env' ;
32+ done ;
3233'';
3334
3435## TODO: make static compilation work.
@@ -47,22 +48,20 @@ stdenv.mkDerivation rec {
4748# LEVELDB=${makeStaticLibraries leveldb}/lib/libleveldb.a
4849# EOF
4950
51+ inherit configurePhase installPhase;
52+
5053 buildPhase = ''
5154 runHook preBuild
5255
53− # Enable all optional libraries
54− substituteInPlace "src/std/build-features.ss" --replace '#f' '#t'
55−
56− # Enable autodetection of a default GERBIL_HOME
57− for i in src/gerbil/boot/gx-init-exe.scm src/gerbil/boot/gx-init.scm ; do
58− substituteInPlace "$i" --replace '(getenv "GERBIL_HOME" #f)' "(getenv \"GERBIL_HOME\" \"$out\")"
59− done
60− for i in src/gerbil/boot/gxi-init.scm src/gerbil/compiler/driver.ss src/gerbil/runtime/gx-gambc.scm src/std/build.ss src/tools/build.ss ; do
61− substituteInPlace "$i" --replace '(getenv "GERBIL_HOME")' "(getenv \"GERBIL_HOME\" \"$out\")"
62− done
63−
6456 # gxprof testing uses $HOME/.cache/gerbil/gxc
65− export HOME=$$PWD
57+ export HOME=$PWD
58+ export GERBIL_BUILD_CORES=$NIX_BUILD_CORES
59+ export GERBIL_GXC=$PWD/bin/gxc
60+ export GERBIL_BASE=$PWD
61+ export GERBIL_HOME=$PWD
62+ export GERBIL_PATH=$PWD/lib
63+ export PATH=$PWD/bin:$PATH
64+ ${gambit-support.export-gambopt gambit-params}
6665
6766 # Build, replacing make by build.sh
6867 ( cd src && sh build.sh )
@@ -70,33 +69,15 @@ stdenv.mkDerivation rec {
7069 runHook postBuild
7170 '';
7271
73− installPhase = ''
74− runHook preInstall
75− mkdir -p $out/
76− cp -fa bin lib etc doc $out/
77−
78− cat > $out/bin/gxi <<EOF
79−#!${bash}/bin/bash -e
80−export GERBIL_HOME=$out
81−case "\$1" in -:*) GSIOPTIONS=\$1 ; shift ;; esac
82−if [[ \$# = 0 ]] ; then
83− exec ${gambit}/bin/gsi \$GSIOPTIONS \$GERBIL_HOME/lib/gxi-init \$GERBIL_HOME/lib/gxi-interactive -
84−else
85− exec ${gambit}/bin/gsi \$GSIOPTIONS \$GERBIL_HOME/lib/gxi-init "\$@"
86−fi
87−EOF
88− runHook postInstall
89− '';
90−
9172 dontStrip = true;
9273
9374 meta = {
9475 description = "Gerbil Scheme";
9576 homepage = "https://github.com/vyzo/gerbil";
96− license = stdenv.lib.licenses.lgpl2;
77+ license = lib.licenses.lgpl21; # also asl20, like Gambit
9778 # NB regarding platforms: regularly tested on Linux, only occasionally on macOS.
9879 # Please report success and/or failure to fare.
99− platforms = stdenv.lib.platforms.unix;
100− maintainers = with stdenv.lib.maintainers; [ fare ];
80+ platforms = lib.platforms.unix;
81+ maintainers = with lib.maintainers; [ fare ];
10182 };
10283}
pkgs/development/compilers/gerbil/default.nix+39−3
@@ -1,14 +1,50 @@
1−{ stdenv, callPackage, fetchFromGitHub, gambit }:
1+{ callPackage, fetchFromGitHub, gambit, bash }:
22
33callPackage ./build.nix rec {
44 version = "0.15.1";
55 git-version = "0.15.1";
6− inherit gambit;
76 src = fetchFromGitHub {
87 owner = "vyzo";
98 repo = "gerbil";
109 rev = "v${version}";
1110 sha256 = "0qpqms66hz41wwhxb1z0fnzj96ivkm7qi9h9d7lhlr3fsxm1kp1n";
1211 };
13− inherit stdenv;
12+ configurePhase = ''
13+ grep -Fl '"gsc"' `find . -type f -name '*.s*'` | while read f ; do
14+ substituteInPlace "$f" --replace '"gsc"' '"${gambit}/bin/gsc"' ;
15+ done ;
16+ for f in etc/gerbil.el src/std/make.ss ; do
17+ substituteInPlace "$f" --replace '"gxc"' "\"$out/bin/gxc\"" ;
18+ done ;
19+
20+ # Enable all optional libraries
21+ substituteInPlace "src/std/build-features.ss" --replace '#f' '#t' ;
22+
23+ # Enable autodetection of a default GERBIL_HOME
24+ for i in src/gerbil/boot/gx-init-exe.scm src/gerbil/boot/gx-init.scm ; do
25+ substituteInPlace "$i" --replace '(define default-gerbil-home #f)' "(define default-gerbil-home \"$out/gerbil\")" ;
26+ substituteInPlace "$i" --replace '(getenv "GERBIL_HOME" #f)' "(getenv \"GERBIL_HOME\" \"$out/gerbil\")" ;
27+ done ;
28+ for i in src/gerbil/boot/gxi-init.scm src/gerbil/compiler/driver.ss src/gerbil/runtime/gx-gambc.scm src/std/build.ss src/tools/build.ss ; do
29+ substituteInPlace "$i" --replace '(getenv "GERBIL_HOME")' "(getenv \"GERBIL_HOME\" \"$out/gerbil\")" ;
30+ done
31+ '';
32+ installPhase = ''
33+ runHook preInstall
34+ mkdir -p $out/gerbil $out/bin
35+ cp -fa bin lib etc doc $out/gerbil
36+ cat > $out/gerbil/bin/gxi <<EOF
37+#!${bash}/bin/bash -e
38+GERBIL_GSI=${gambit}/bin/gsi
39+export GERBIL_HOME=$out/gerbil
40+case "\$1" in -:*) GSIOPTIONS="\$1" ; shift ;; esac
41+if [[ \$# = 0 ]] ; then
42+ exec "\$GERBIL_GSI" \$GSIOPTIONS "\$GERBIL_HOME/lib/gxi-init" "\$GERBIL_HOME/lib/gxi-interactive" -
43+else
44+ exec "\$GERBIL_GSI" \$GSIOPTIONS "\$GERBIL_HOME/lib/gxi-init" "\$@"
45+fi
46+EOF
47+ (cd $out/bin ; ln -s ../gerbil/bin/* .)
48+ runHook postInstall
49+ '';
1450}
pkgs/development/compilers/gerbil/gerbil-support.nixnew file+63
@@ -0,0 +1,63 @@
1+{ pkgs, gccStdenv, callPackage, fetchFromGitHub }:
2+# See ../gambit/build.nix regarding gccStdenv
3+
4+rec {
5+ # Gerbil libraries
6+ gerbilPackages-unstable = {
7+ };
8+
9+ # Use this function in any package that uses Gerbil libraries, to define the GERBIL_LOADPATH.
10+ gerbilLoadPath =
11+ gerbilInputs : builtins.concatStringsSep ":" (map (x : x + "/gerbil/lib") gerbilInputs);
12+
13+ # Use this function to create a Gerbil library. See gerbil-utils as an example.
14+ gerbilPackage = {
15+ pname, version, src, meta, package,
16+ git-version ? "", version-path ? "config/version.ss",
17+ gerbil ? pkgs.gerbil-unstable,
18+ gambit-params ? pkgs.gambit-support.stable-params,
19+ gerbilInputs ? [],
20+ buildInputs ? [],
21+ softwareName ? "" } :
22+ let buildInputs_ = buildInputs; in
23+ gccStdenv.mkDerivation rec {
24+ inherit src meta pname version;
25+ buildInputs = [ gerbil ] ++ gerbilInputs ++ buildInputs_;
26+ postPatch = ''
27+ set -e ;
28+ if [ -n "${version-path}" ] ; then
29+ echo '(import :clan/utils/version)\n(register-software "${softwareName}" "${git-version}")\n' > "${version-path}"
30+ fi
31+ patchShebangs . ;
32+ '';
33+
34+ postConfigure = ''
35+ export GERBIL_BUILD_CORES=$NIX_BUILD_CORES
36+ export GERBIL_PATH=$PWD/.build
37+ export GERBIL_LOADPATH=${gerbilLoadPath gerbilInputs}
38+ ${pkgs.gambit-support.export-gambopt gambit-params}
39+ '';
40+
41+ buildPhase = ''
42+ runHook preBuild
43+ ./build.ss
44+ runHook postBuild
45+ '';
46+
47+ installPhase = ''
48+ runHook preInstall
49+ mkdir -p $out/gerbil/lib
50+ cp -fa .build/lib $out/gerbil/
51+ bins=(.build/bin/*)
52+ if [ 0 -lt ''${#bins} ] ; then
53+ cp -fa .build/bin $out/gerbil/
54+ mkdir $out/bin
55+ cd $out/bin
56+ ln -s ../gerbil/bin/* .
57+ fi
58+ runHook postInstall
59+ '';
60+
61+ dontFixup = true;
62+ };
63+}
pkgs/development/compilers/gerbil/unstable.nix+23−4
@@ -1,15 +1,34 @@
1−{ stdenv, callPackage, fetchFromGitHub, gambit, gambit-unstable }:
1+{ callPackage, fetchFromGitHub, gambit-unstable, gambit-support, coreutils, bash }:
22
33callPackage ./build.nix {
44 version = "unstable-2020-02-27";
55 git-version = "0.16-DEV-493-g1ffb74db";
6− #gambit = gambit-unstable;
7− gambit = gambit;
86 src = fetchFromGitHub {
97 owner = "vyzo";
108 repo = "gerbil";
119 rev = "1ffb74db5ffd49b4bad751586cef5e619c891d41";
1210 sha256 = "1szmdp8lvy5gpcwn5bpa7x383m6vywl35xa7hz9a5vs1rq4w2097";
1311 };
14− inherit stdenv;
12+ inherit gambit-support;
13+ gambit = gambit-unstable;
14+ gambit-params = gambit-support.unstable-params;
15+ configurePhase = ''
16+ (cd src && ./configure \
17+ --prefix=$out/gerbil \
18+ --with-gambit=${gambit}/gambit \
19+ --enable-libxml \
20+ --enable-libyaml \
21+ --enable-zlib \
22+ --enable-sqlite \
23+ --enable-mysql \
24+ --enable-lmdb \
25+ --enable-leveldb)
26+ '';
27+ installPhase = ''
28+ runHook preInstall
29+ mkdir -p $out/gerbil $out/bin
30+ (cd src; ./install)
31+ (cd $out/bin ; ln -s ../gerbil/bin/* .)
32+ runHook postInstall
33+ '';
1534}
pkgs/top-level/all-packages.nix+5−3
@@ -8202,11 +8202,13 @@ in
82028202
82038203 fpc = callPackage ../development/compilers/fpc { };
82048204
8205− gambit = callPackage ../development/compilers/gambit { stdenv = gccStdenv; };
8205+ gambit = callPackage ../development/compilers/gambit { };
82068206 gambit-unstable = callPackage ../development/compilers/gambit/unstable.nix { };
82078207 gambit-support = callPackage ../development/compilers/gambit/gambit-support.nix { };
8208− gerbil = callPackage ../development/compilers/gerbil { stdenv = gccStdenv; };
8209− gerbil-unstable = callPackage ../development/compilers/gerbil/unstable.nix { stdenv = gccStdenv; };
8208+ gerbil = callPackage ../development/compilers/gerbil { };
8209+ gerbil-unstable = callPackage ../development/compilers/gerbil/unstable.nix { };
8210+ gerbil-support = callPackage ../development/compilers/gerbil/gerbil-support.nix { };
8211+ gerbilPackages-unstable = gerbil-support.gerbilPackages-unstable; # NB: don't recurseIntoAttrs for (unstable!) libraries
82108212
82118213 gccFun = callPackage (if stdenv.targetPlatform.isVc4 then ../development/compilers/gcc/6 else ../development/compilers/gcc/9);
82128214 gcc = if stdenv.targetPlatform.isVc4 then gcc6 else gcc9;