speed up kernel build

by having two separate derivations for patching the kernel source tree
and building it, we have to copy said source trees from one store
location to another which takes non-neglible time on spinning rust
(literally minutes on my machine). Replace with a single derivation
that can do more things on one tree in-place
This commit is contained in:
Daniel Barlow
2022-10-19 17:34:22 +01:00
parent d1dda7bf74
commit f1b7780537
7 changed files with 77 additions and 101 deletions

View File

@@ -1,15 +1,10 @@
{
stdenv
, openwrt
, dtc
, kernel
}:
{ dts
, includes
}:let
includes = [
"${openwrt}/target/linux/ath79/dts"
"${kernel}/include"
];
cppDtSearchFlags = builtins.concatStringsSep " " (map (f: "-I${f}") includes);
dtcSearchFlags = builtins.concatStringsSep " " (map (f: "-i${f}") includes);
in stdenv.mkDerivation {
@@ -17,7 +12,7 @@ in stdenv.mkDerivation {
phases = [ "buildPhase" ];
nativeBuildInputs = [ dtc ];
buildPhase = ''
${stdenv.cc.targetPrefix}cpp -nostdinc -x assembler-with-cpp ${cppDtSearchFlags} -undef -D__DTS__ -o dtb.tmp ${openwrt}/target/linux/ath79/dts/${dts}
${stdenv.cc.targetPrefix}cpp -nostdinc -x assembler-with-cpp ${cppDtSearchFlags} -undef -D__DTS__ -o dtb.tmp ${dts}
dtc ${dtcSearchFlags} -I dts -O dtb -o $out dtb.tmp
test -e $out
'';

View File

@@ -7,7 +7,7 @@
let
objcopy = "${stdenv.cc.bintools.targetPrefix}objcopy";
in {
vmlinux
kernel
, commandLine
, entryPoint
, extraName ? "" # e.g. socFamily
@@ -28,7 +28,7 @@ stdenv.mkDerivation {
ubootTools
];
preparePhase = ''
cp ${vmlinux} vmlinux.elf; chmod +w vmlinux.elf
cp ${kernel} vmlinux.elf; chmod +w vmlinux.elf
'';
dtbPhase = ''
dtc -I dtb -O dts -o tmp.dts ${dtb}

View File

@@ -1,101 +0,0 @@
{ stdenv
, buildPackages
, runCommand
, writeText
, lib
, config
, checkedConfig ? {}
, tree
} :
let writeConfig = name : config: writeText name
(builtins.concatStringsSep
"\n"
(lib.mapAttrsToList
(name: value: (if value == "n" then "# CONFIG_${name} is not set" else "CONFIG_${name}=${value}"))
config
));
kconfigFile = writeConfig "kconfig" (config // checkedConfig);
# KLUDGE FIXME. some symbols we need to enable in some configurations don't
# have a prompt (!), so we can't turn them on just by adding FOO=y and make oldconfig
#
# (!) yes, that was my reaction too
kconfigLocal = writeText "Kconfig.local" ''
config LIMINIX
prompt "Local symbols"
bool
default y
select SOC_QCA955X
'';
checkedConfigFile = writeConfig "checked_kconfig" checkedConfig ;
inherit lib; in
stdenv.mkDerivation rec {
name = "vmlinux";
hardeningDisable = ["all"];
nativeBuildInputs = [buildPackages.stdenv.cc] ++
(with buildPackages.pkgs;
[rsync bc bison flex pkgconfig openssl ncurses.all perl]);
CC = "${stdenv.cc.bintools.targetPrefix}gcc";
HOSTCC = with buildPackages.pkgs;
"gcc -I${openssl}/include -I${ncurses}/include";
HOST_EXTRACFLAGS = with buildPackages.pkgs;
"-I${openssl.dev}/include -L${openssl.out}/lib -L${ncurses.out}/lib";
PKG_CONFIG_PATH = "./pkgconfig";
CROSS_COMPILE = stdenv.cc.bintools.targetPrefix;
ARCH = "mips"; # kernel uses "mips" here for both mips and mipsel
dontStrip = true;
dontPatchELF = true;
outputs = ["out" "modulesupport"];
phases = [
"butcherPkgconfig"
"configurePhase"
"checkConfigurationPhase"
"buildPhase"
"installPhase"
];
# this is here to work around what I think is a bug in nixpkgs
# packaging of ncurses: it installs pkg-config data files which
# don't produce any -L options when queried with "pkg-config --lib
# ncurses". For a regular build you'll never even notice, this only
# becomes an issue if you do a nix-shell in this derivation and
# expect "make nconfig" to work.
butcherPkgconfig = ''
cp -r ${buildPackages.pkgs.ncurses.dev}/lib/pkgconfig .
chmod +w pkgconfig pkgconfig/*.pc
for i in pkgconfig/*.pc; do test -f $i && sed -i 's/^Libs:/Libs: -L''${libdir} /' $i;done
'';
configurePhase = ''
export KBUILD_OUTPUT=`pwd`
cp ${kconfigFile} .config
cp ${kconfigFile} .config.orig
cp ${kconfigLocal} Kconfig.local
( cd ${tree} && make V=1 olddefconfig )
'';
checkConfigurationPhase = ''
echo Checking required config items:
if comm -2 -3 <(grep 'CONFIG' ${checkedConfigFile} |sort) <(grep 'CONFIG' .config|sort) |grep '.' ; then
echo -e "^^^ Some configuration lost :-(\nPerhaps you have mutually incompatible settings, or have disabled options on which these depend.\n"
exit 0
fi
echo "OK"
'';
KBUILD_BUILD_HOST = "liminix.builder";
buildPhase = ''
make -C ${tree} vmlinux modules_prepare
'';
installPhase = ''
${CROSS_COMPILE}strip -d vmlinux
cp vmlinux $out
mkdir -p $modulesupport
cp .config $modulesupport/config
make clean
cp -a . $modulesupport
'';
}