bump Nim to 0.4.6

This commit is contained in:
Christian Ulrich 2021-05-04 23:10:44 +02:00
parent 395ed03a05
commit ca0abdd819
No known key found for this signature in database
GPG Key ID: 8241BE099775A097
2 changed files with 214 additions and 173 deletions

View File

@ -17,9 +17,8 @@ self: super:
ngtcp2 = super.callPackage ./pkgs/ngtcp2/default.nix { }; ngtcp2 = super.callPackage ./pkgs/ngtcp2/default.nix { };
nim = super.callPackage ./pkgs/nim/default.nix { }; inherit (super.callPackages ./pkgs/nim { })
nim-unwrapped nimble-unwrapped nim;
nimble-unwrapped = self.nim.nimble-unwrapped;
picotls = super.callPackage ./pkgs/picotls/default.nix { }; picotls = super.callPackage ./pkgs/picotls/default.nix { };

View File

@ -1,22 +1,10 @@
# https://nim-lang.github.io/Nim/packaging.html # https://nim-lang.github.io/Nim/packaging.html
# https://nim-lang.org/docs/nimc.html
{ stdenv, lib, fetchurl, fetchgit, fetchFromGitHub, makeWrapper, gdb, openssl { lib, buildPackages, stdenv, fetchurl, fetchgit, fetchFromGitHub, makeWrapper
, pcre, readline, boehmgc, sqlite, nim-unwrapped, nimble-unwrapped }: , openssl, pcre, readline, boehmgc, sqlite, nim-unwrapped }:
let let
version = "1.4.2";
src = fetchurl {
url = "https://nim-lang.org/download/nim-${version}.tar.xz";
sha256 = "0q8i56343b69f1bh48a8vxkqman9i2kscyj0lf017n3xfy1pb903";
};
meta = with lib; {
description = "Statically typed, imperative programming language";
homepage = "https://nim-lang.org/";
license = licenses.mit;
maintainers = with maintainers; [ ehmry ];
};
parseCpu = platform: parseCpu = platform:
with platform; with platform;
# Derive a Nim CPU identifier # Derive a Nim CPU identifier
@ -83,16 +71,14 @@ let
nimHost = parsePlatform stdenv.hostPlatform; nimHost = parsePlatform stdenv.hostPlatform;
nimTarget = parsePlatform stdenv.targetPlatform; nimTarget = parsePlatform stdenv.targetPlatform;
wrapperInputs = rec { bootstrapCompiler = stdenv.mkDerivation rec {
bootstrap = stdenv.mkDerivation rec {
pname = "nim-bootstrap"; pname = "nim-bootstrap";
version = "0.20.0"; version = "0.20.0";
src = fetchgit { src = fetchgit {
# A Git checkout is much smaller than a GitHub tarball. # A Git checkout is much smaller than a GitHub tarball.
url = "https://github.com/nim-lang/csources.git"; url = "https://github.com/nim-lang/csources.git";
rev = "v" + version; rev = "v${version}";
sha256 = "0i6vsfy1sgapx43n226q8m0pvn159sw2mhp50zm3hhb9zfijanis"; sha256 = "0i6vsfy1sgapx43n226q8m0pvn159sw2mhp50zm3hhb9zfijanis";
}; };
@ -105,9 +91,17 @@ let
''; '';
}; };
unwrapped = stdenv.mkDerivation { in {
nim-unwrapped = stdenv.mkDerivation rec {
pname = "nim-unwrapped"; pname = "nim-unwrapped";
inherit version src; version = "1.4.6";
strictDeps = true;
src = fetchurl {
url = "https://nim-lang.org/download/nim-${version}.tar.xz";
hash = "sha256-D7wPkoLP/oXembxHv6h2Ulud3aKi6uVcGFoIgEuY070=";
};
buildInputs = [ boehmgc openssl pcre readline sqlite ]; buildInputs = [ boehmgc openssl pcre readline sqlite ];
@ -121,7 +115,7 @@ let
configurePhase = '' configurePhase = ''
runHook preConfigure runHook preConfigure
cp ${bootstrap}/bin/nim bin/ cp ${bootstrapCompiler}/bin/nim bin/
echo 'define:nixbuild' >> config/nim.cfg echo 'define:nixbuild' >> config/nim.cfg
runHook postConfigure runHook postConfigure
''; '';
@ -131,8 +125,7 @@ let
"--os:${nimHost.os}" "--os:${nimHost.os}"
"-d:release" "-d:release"
"-d:useGnuReadline" "-d:useGnuReadline"
] ++ lib.optional (stdenv.isDarwin || stdenv.isLinux) ] ++ lib.optional (stdenv.isDarwin || stdenv.isLinux) "-d:nativeStacktrace";
"-d:nativeStacktrace";
buildPhase = '' buildPhase = ''
runHook preBuild runHook preBuild
@ -151,21 +144,27 @@ let
runHook postInstall runHook postInstall
''; '';
inherit meta; meta = with lib; {
description = "Statically typed, imperative programming language";
homepage = "https://nim-lang.org/";
license = licenses.mit;
maintainers = with maintainers; [ ehmry ];
};
}; };
nimble-unwrapped = stdenv.mkDerivation rec { nimble-unwrapped = stdenv.mkDerivation rec {
pname = "nimble-unwrapped"; pname = "nimble-unwrapped";
version = "0.12.0"; version = "0.13.1";
strictDeps = true;
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "nim-lang"; owner = "nim-lang";
repo = "nimble"; repo = "nimble";
rev = "v" + version; rev = "v${version}";
sha256 = "0vx0mdk31n00dr2rhiip6f4x7aa3z3mnblnmwk7f65ixd5hayq6y"; sha256 = "1idb4r0kjbqv16r6bgmxlr13w2vgq5332hmnc8pjbxiyfwm075x8";
}; };
nativeBuildInputs = [ nim-unwrapped ]; depsBuildBuild = [ nim-unwrapped ];
buildInputs = [ openssl ]; buildInputs = [ openssl ];
nimFlags = [ "--cpu:${nimHost.cpu}" "--os:${nimHost.os}" "-d:release" ]; nimFlags = [ "--cpu:${nimHost.cpu}" "--os:${nimHost.os}" "-d:release" ];
@ -183,63 +182,103 @@ let
''; '';
}; };
}; nim = let
nim' = buildPackages.nim-unwrapped;
wrapped = let nimble' = buildPackages.nimble-unwrapped;
nim' = nim-unwrapped;
nimble' = nimble-unwrapped;
inherit (stdenv) targetPlatform; inherit (stdenv) targetPlatform;
in stdenv.mkDerivation { in stdenv.mkDerivation {
name = "${targetPlatform.config}-nim-wrapper-${nim'.version}"; name = "${targetPlatform.config}-nim-wrapper-${nim'.version}";
inherit (nim') version; inherit (nim') version;
preferLocalBuild = true; preferLocalBuild = true;
strictDeps = true;
nativeBuildInputs = [ makeWrapper ]; nativeBuildInputs = [ makeWrapper ];
patches = [
./nim.cfg.patch
# Remove configurations that clash with ours
];
unpackPhase = '' unpackPhase = ''
runHook preUnpack runHook preUnpack
tar xf ${nim'.src} nim-$version/config/nim.cfg tar xf ${nim'.src} nim-$version/config
cd nim-$version cd nim-$version
runHook postUnpack runHook postUnpack
''; '';
dontConfigure = true; dontConfigure = true;
buildPhase =
# Configure the Nim compiler to use $CC and $CXX as backends
# The compiler is configured by two configuration files, each with
# a different DSL. The order of evaluation matters and that order
# is not documented, so duplicate the configuration across both files.
''
runHook preBuild
cat >> config/config.nims << WTF
switch("os", "${nimTarget.os}")
switch("cpu", "${nimTarget.cpu}")
switch("define", "nixbuild")
# Configure the compiler using the $CC set by Nix at build time
import strutils
let cc = getEnv"CC"
if cc.contains("gcc"):
switch("cc", "gcc")
elif cc.contains("clang"):
switch("cc", "clang")
WTF
mv config/nim.cfg config/nim.cfg.old
cat > config/nim.cfg << WTF
os = "${nimTarget.os}"
cpu = "${nimTarget.cpu}"
define:"nixbuild"
WTF
cat >> config/nim.cfg < config/nim.cfg.old
rm config/nim.cfg.old
cat >> config/nim.cfg << WTF
clang.cpp.exe %= "\$CXX"
clang.cpp.linkerexe %= "\$CXX"
clang.exe %= "\$CC"
clang.linkerexe %= "\$CC"
gcc.cpp.exe %= "\$CXX"
gcc.cpp.linkerexe %= "\$CXX"
gcc.exe %= "\$CC"
gcc.linkerexe %= "\$CC"
WTF
runHook postBuild
'';
wrapperArgs = [ wrapperArgs = [
"--prefix PATH : ${lib.makeBinPath [ stdenv.cc gdb ]}:${ "--prefix PATH : ${lib.makeBinPath [ buildPackages.gdb ]}:${
placeholder "out" placeholder "out"
}/bin" }/bin"
"--prefix LD_LIBRARY_PATH : ${ # Used by nim-gdb
lib.makeLibraryPath [ stdenv.cc.libc openssl ]
}" "--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ openssl pcre ]}"
# These libraries may be referred to by the standard library.
# This is broken for cross-compilation because the package
# set will be shifted back by nativeBuildInputs.
"--set NIM_CONFIG_PATH ${placeholder "out"}/etc/nim" "--set NIM_CONFIG_PATH ${placeholder "out"}/etc/nim"
# Use the custom configuration
''--set NIX_HARDENING_ENABLE "''${NIX_HARDENING_ENABLE/fortify}"'' ''--set NIX_HARDENING_ENABLE "''${NIX_HARDENING_ENABLE/fortify}"''
# Fortify hardening appends -O2 to gcc flags which is unwanted for unoptimized nim builds. # Fortify hardening appends -O2 to gcc flags which is unwanted for unoptimized nim builds.
]; ];
buildPhase = with stdenv; installPhase = ''
let runHook preInstall
ccType = if cc.isGNU then
"gcc"
else if cc.isClang then
"clang"
else
abort "no Nim configuration available for ${cc.name}";
in ''
runHook preBuild
cat >> config/nim.cfg << EOF
define:nixbuild mkdir -p $out/bin $out/etc
os = ${nimTarget.os}
cpu = ${nimTarget.cpu}
cc = ${ccType}
EOF
mkdir -p $out/bin $out/etc/nim cp -r config $out/etc/nim
export cc=$CC
export cxx=$CXX
substituteAll config/nim.cfg $out/etc/nim/nim.cfg \
--replace "cc = gcc" ""
for binpath in ${nim'}/bin/nim?*; do for binpath in ${nim'}/bin/nim?*; do
local binname=`basename $binpath` local binname=`basename $binpath`
@ -264,16 +303,19 @@ let
--suffix PATH : $out/bin --suffix PATH : $out/bin
ln -s $out/bin/${targetPlatform.config}-nimble $out/bin/nimble ln -s $out/bin/${targetPlatform.config}-nimble $out/bin/nimble
runHook postBuild runHook postInstall
''; '';
dontInstall = true; passthru = {
nim = nim';
nimble = nimble';
};
meta = meta // { meta = nim'.meta // {
description = nim'.meta.description description = nim'.meta.description
+ " (${targetPlatform.config} wrapper)"; + " (${targetPlatform.config} wrapper)";
platforms = lib.platforms.unix; platforms = with lib.platforms; unix ++ genode;
}; };
}; };
in wrapped // wrapperInputs }