netbsd.libc: Create from constituent pkgs not hack

The old `postInstall` was ugly, and made for a needlessly course-grained
package. This makes more smaller derivations, and ones that additionally
can be built in parallel.
This commit is contained in:
John Ericson
2024-06-21 17:06:37 -04:00
parent 8cc7430d51
commit e34c3f7856
15 changed files with 308 additions and 182 deletions
+37 -10
View File
@@ -1,5 +1,6 @@
{
lib,
crossLibcStdenv,
stdenvNoCC,
makeScopeWithSplicing',
generateSplicesForMkScope,
@@ -31,6 +32,16 @@ makeScopeWithSplicing' {
compatIfNeeded = lib.optional (!stdenvNoCC.hostPlatform.isNetBSD) self.compat;
stdenvLibcMinimal = crossLibcStdenv.override (old: {
cc = old.cc.override {
libc = self.libcMinimal;
bintools = old.cc.bintools.override {
libc = self.libcMinimal;
sharedLibraryLoader = null;
};
};
});
# The manual callPackages below should in principle be unnecessary because
# they're just selecting arguments that would be selected anyway. However,
# if we don't perform these manual calls, we get infinite recursion issues
@@ -75,13 +86,9 @@ makeScopeWithSplicing' {
# See note in pkgs/stat/hook.nix
statHook = self.callPackage ./pkgs/stat/hook.nix { inherit (self) stat; };
tsort = self.callPackage ./pkgs/tsort.nix {
inherit (buildPackages.netbsd) makeMinimal install;
};
tsort = self.callPackage ./pkgs/tsort.nix { inherit (buildPackages.netbsd) makeMinimal install; };
lorder = self.callPackage ./pkgs/lorder.nix {
inherit (buildPackages.netbsd) makeMinimal install;
};
lorder = self.callPackage ./pkgs/lorder.nix { inherit (buildPackages.netbsd) makeMinimal install; };
config = self.callPackage ./pkgs/config.nix {
inherit (buildPackages.netbsd) makeMinimal install;
@@ -111,7 +118,16 @@ makeScopeWithSplicing' {
;
};
libutil = self.callPackage ./pkgs/libutil.nix { inherit (self) libc sys; };
libutil = self.callPackage ./pkgs/libutil.nix {
inherit (buildPackages.netbsd)
netbsdSetupHook
makeMinimal
install
lorder
tsort
statHook
;
};
libpthread-headers = self.callPackage ./pkgs/libpthread/headers.nix { };
@@ -129,9 +145,8 @@ makeScopeWithSplicing' {
;
};
libc = self.callPackage ./pkgs/libc.nix {
inherit (self) headers csu librt;
libcMinimal = self.callPackage ./pkgs/libcMinimal.nix {
inherit (self) headers csu;
inherit (buildPackages.netbsd)
netbsdSetupHook
makeMinimal
@@ -145,6 +160,18 @@ makeScopeWithSplicing' {
;
};
librpcsvc = self.callPackage ./pkgs/librpcsvc.nix {
inherit (buildPackages.netbsd)
netbsdSetupHook
makeMinimal
install
lorder
tsort
statHook
rpcgen
;
};
mtree = self.callPackage ./pkgs/mtree.nix { inherit (self) mknod; };
}
);
@@ -1,7 +1,7 @@
prefix=@out@
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
includedir=@includedir@
Name: nbcompat
Description: NetBSD compatibility framework
@@ -20,6 +20,11 @@ mkDerivation (
{
path = "tools/compat";
outputs = [
"out"
"dev"
];
setupHooks = [
../../../../../build-support/setup-hooks/role.bash
./compat-setup-hook.sh
@@ -57,7 +62,7 @@ mkDerivation (
defaultMakeFlags
++ [
"INSTALL=${coreutils}/bin/install"
"DATADIR=$(out)/share"
"DATADIR=$(dev)/share"
# Can't sort object files yet
"LORDER=echo"
"TSORT=cat"
@@ -90,37 +95,38 @@ mkDerivation (
postInstall =
''
# why aren't these installed by netbsd?
install -D compat_defs.h $out/include/compat_defs.h
install -D $BSDSRCDIR/include/cdbw.h $out/include/cdbw.h
install -D $BSDSRCDIR/sys/sys/cdbr.h $out/include/cdbr.h
install -D compat_defs.h $dev/include/compat_defs.h
install -D $BSDSRCDIR/include/cdbw.h $dev/include/cdbw.h
install -D $BSDSRCDIR/sys/sys/cdbr.h $dev/include/cdbr.h
install -D $BSDSRCDIR/sys/sys/featuretest.h \
$out/include/sys/featuretest.h
install -D $BSDSRCDIR/sys/sys/md5.h $out/include/md5.h
install -D $BSDSRCDIR/sys/sys/rmd160.h $out/include/rmd160.h
install -D $BSDSRCDIR/sys/sys/sha1.h $out/include/sha1.h
install -D $BSDSRCDIR/sys/sys/sha2.h $out/include/sha2.h
install -D $BSDSRCDIR/sys/sys/queue.h $out/include/sys/queue.h
install -D $BSDSRCDIR/include/vis.h $out/include/vis.h
install -D $BSDSRCDIR/include/db.h $out/include/db.h
install -D $BSDSRCDIR/include/netconfig.h $out/include/netconfig.h
install -D $BSDSRCDIR/include/utmpx.h $out/include/utmpx.h
install -D $BSDSRCDIR/include/tzfile.h $out/include/tzfile.h
install -D $BSDSRCDIR/sys/sys/tree.h $out/include/sys/tree.h
install -D $BSDSRCDIR/include/nl_types.h $out/include/nl_types.h
install -D $BSDSRCDIR/include/stringlist.h $out/include/stringlist.h
$dev/include/sys/featuretest.h
install -D $BSDSRCDIR/sys/sys/md5.h $dev/include/md5.h
install -D $BSDSRCDIR/sys/sys/rmd160.h $dev/include/rmd160.h
install -D $BSDSRCDIR/sys/sys/sha1.h $dev/include/sha1.h
install -D $BSDSRCDIR/sys/sys/sha2.h $dev/include/sha2.h
install -D $BSDSRCDIR/sys/sys/queue.h $dev/include/sys/queue.h
install -D $BSDSRCDIR/include/vis.h $dev/include/vis.h
install -D $BSDSRCDIR/include/db.h $dev/include/db.h
install -D $BSDSRCDIR/include/netconfig.h $dev/include/netconfig.h
install -D $BSDSRCDIR/include/utmpx.h $dev/include/utmpx.h
install -D $BSDSRCDIR/include/tzfile.h $dev/include/tzfile.h
install -D $BSDSRCDIR/sys/sys/tree.h $dev/include/sys/tree.h
install -D $BSDSRCDIR/include/nl_types.h $dev/include/nl_types.h
install -D $BSDSRCDIR/include/stringlist.h $dev/include/stringlist.h
# Collapse includes slightly to fix dangling reference
install -D $BSDSRCDIR/common/include/rpc/types.h $out/include/rpc/types.h
sed -i '1s;^;#include "nbtool_config.h"\n;' $out/include/rpc/types.h
install -D $BSDSRCDIR/common/include/rpc/types.h $dev/include/rpc/types.h
sed -i '1s;^;#include "nbtool_config.h"\n;' $dev/include/rpc/types.h
''
+ lib.optionalString stdenv.isDarwin ''
mkdir -p $out/include/ssp
touch $out/include/ssp/ssp.h
mkdir -p $dev/include/ssp
touch $dev/include/ssp/ssp.h
''
+ ''
mkdir -p $out/lib/pkgconfig
substitute ${./libbsd-overlay.pc} $out/lib/pkgconfig/libbsd-overlay.pc \
--subst-var-by out $out \
mkdir -p $dev/lib/pkgconfig
substitute ${./libbsd-overlay.pc} $dev/lib/pkgconfig/libbsd-overlay.pc \
--subst-var-by out "$out" \
--subst-var-by includedir "$dev/include" \
--subst-var-by version ${version}
'';
extraPaths = [
@@ -129,8 +135,7 @@ mkDerivation (
"lib/libc"
"lib/libutil"
"external/bsd/flex"
"sys"
"common/include/rpc/types.h"
"sys/sys"
];
}
)
@@ -1,11 +1,20 @@
{
lib,
stdenvLibcMinimal,
mkDerivation,
libc,
libcMinimal,
}:
mkDerivation {
path = "lib/i18n_module";
libcMinimal = true;
# Hack around GCC's limits.h missing the include_next we want See
# https://gcc.gnu.org/legacy-ml/gcc/2003-10/msg01278.html
NIX_CFLAGS_COMPILE_BEFORE = "-isystem ${stdenvLibcMinimal.cc.libc.dev}/include";
extraPaths = [ libcMinimal.path ];
meta.platforms = lib.platforms.netbsd;
extraPaths = [ libc.path ];
}
@@ -1,7 +1,7 @@
{
lib,
mkDerivation,
libc,
libcMinimal,
defaultMakeFlags,
}:
@@ -9,13 +9,16 @@ mkDerivation {
noLibc = true;
path = "libexec/ld.elf_so";
meta.platforms = lib.platforms.netbsd;
LIBC_PIC = "${libc}/lib/libc_pic.a";
LIBC_PIC = "${libcMinimal}/lib/libc_pic.a";
# Hack to prevent a symlink being installed here for compatibility.
SHLINKINSTALLDIR = "/usr/libexec";
USE_FORT = "yes";
makeFlags = defaultMakeFlags ++ [
"BINDIR=$(out)/libexec"
"CLIBOBJ=${libc}/lib"
"CLIBOBJ=${libcMinimal}/lib"
];
extraPaths = [
libcMinimal.path
"sys"
];
extraPaths = [ libc.path ] ++ libc.extraPaths;
}
+40 -108
View File
@@ -1,120 +1,52 @@
{
lib,
mkDerivation,
defaultMakeFlags,
bsdSetupHook,
netbsdSetupHook,
makeMinimal,
install,
mandoc,
groff,
flex,
byacc,
genassym,
gencat,
lorder,
tsort,
statHook,
rpcgen,
csu,
headers,
symlinkJoin,
libcMinimal,
libpthread,
libm,
libresolv,
librpcsvc,
i18n_module,
libutil,
librt,
libcrypt,
version,
}:
mkDerivation {
noLibc = true;
path = "lib/libc";
symlinkJoin rec {
name = "${pname}-${version}";
pname = "libc-netbsd";
inherit version;
outputs = [
"out"
"dev"
"man"
"tags"
];
USE_FORT = "yes";
MKPROFILE = "no";
extraPaths = [
"common"
"lib/i18n_module"
"lib/libcrypt"
"lib/libm"
"lib/libpthread"
"lib/libresolv"
"lib/librpcsvc"
"lib/librt"
"lib/libutil"
"libexec/ld.elf_so"
"sys"
"external/bsd/jemalloc"
];
nativeBuildInputs = [
bsdSetupHook
netbsdSetupHook
makeMinimal
install
mandoc
groff
flex
byacc
genassym
gencat
lorder
tsort
statHook
rpcgen
];
buildInputs = [
headers
csu
];
env.NIX_CFLAGS_COMPILE = "-B${csu}/lib -fcommon";
paths =
lib.concatMap
(p: [
(lib.getDev p)
(lib.getLib p)
(lib.getMan p)
])
[
libcMinimal
libm
libpthread
libresolv
librpcsvc
i18n_module
libutil
librt
libcrypt
];
postBuild = ''
rm -r "$out/nix-support"
fixupPhase
'';
meta.platforms = lib.platforms.netbsd;
SHLIBINSTALLDIR = "$(out)/lib";
MKPICINSTALL = "yes";
NLSDIR = "$(out)/share/nls";
makeFlags = defaultMakeFlags ++ [ "FILESDIR=$(out)/var/db" ];
postInstall = ''
pushd ${headers}
find include -type d -exec mkdir -p "$dev/{}" ';'
find include '(' -type f -o -type l ')' -exec cp -pr "{}" "$dev/{}" ';'
popd
pushd ${csu}
find lib -type d -exec mkdir -p "$out/{}" ';'
find lib '(' -type f -o -type l ')' -exec cp -pr "{}" "$out/{}" ';'
popd
NIX_CFLAGS_COMPILE+=" -B$out/lib"
NIX_CFLAGS_COMPILE+=" -I$dev/include"
NIX_LDFLAGS+=" -L$out/lib"
make -C $BSDSRCDIR/lib/libpthread $makeFlags
make -C $BSDSRCDIR/lib/libpthread $makeFlags install
make -C $BSDSRCDIR/lib/libm $makeFlags
make -C $BSDSRCDIR/lib/libm $makeFlags install
make -C $BSDSRCDIR/lib/libresolv $makeFlags
make -C $BSDSRCDIR/lib/libresolv $makeFlags install
make -C $BSDSRCDIR/lib/librpcsvc $makeFlags
make -C $BSDSRCDIR/lib/librpcsvc $makeFlags install
make -C $BSDSRCDIR/lib/i18n_module $makeFlags
make -C $BSDSRCDIR/lib/i18n_module $makeFlags install
make -C $BSDSRCDIR/lib/libutil $makeFlags
make -C $BSDSRCDIR/lib/libutil $makeFlags install
make -C $BSDSRCDIR/lib/librt $makeFlags
make -C $BSDSRCDIR/lib/librt $makeFlags install
make -C $BSDSRCDIR/lib/libcrypt $makeFlags
make -C $BSDSRCDIR/lib/libcrypt $makeFlags install
moveToOutput var/db/libc.tags "$tags"
'';
postPatch = ''
sed -i 's,/usr\(/include/sys/syscall.h\),${headers}\1,g' \
$BSDSRCDIR/lib/{libc,librt}/sys/Makefile.inc
'';
}
@@ -0,0 +1,85 @@
{
lib,
mkDerivation,
defaultMakeFlags,
bsdSetupHook,
netbsdSetupHook,
makeMinimal,
install,
mandoc,
groff,
flex,
byacc,
genassym,
gencat,
lorder,
tsort,
statHook,
rpcgen,
csu,
headers,
}:
mkDerivation {
noLibc = true;
path = "lib/libc";
pname = "libcMinimal-netbsd";
outputs = [
"out"
"dev"
"man"
"tags"
];
USE_FORT = "yes";
MKPROFILE = "no";
extraPaths = [
"common"
"lib/i18n_module"
"libexec/ld.elf_so"
"sys"
"external/bsd/jemalloc"
];
nativeBuildInputs = [
bsdSetupHook
netbsdSetupHook
makeMinimal
install
mandoc
groff
flex
byacc
genassym
gencat
lorder
tsort
statHook
rpcgen
];
buildInputs = [
headers
csu
];
env.NIX_CFLAGS_COMPILE = "-B${csu}/lib -fcommon";
meta.platforms = lib.platforms.netbsd;
SHLIBINSTALLDIR = "$(out)/lib";
MKPICINSTALL = "yes";
NLSDIR = "$(out)/share/nls";
makeFlags = defaultMakeFlags ++ [ "FILESDIR=$(out)/var/db" ];
postInstall = ''
pushd ${headers}
find include -type d -exec mkdir -p "$dev/{}" ';'
find include '(' -type f -o -type l ')' -exec cp -pr "{}" "$dev/{}" ';'
popd
pushd ${csu}
find lib -type d -exec mkdir -p "$out/{}" ';'
find lib '(' -type f -o -type l ')' -exec cp -pr "{}" "$out/{}" ';'
popd
moveToOutput var/db/libc.tags "$tags"
'';
postPatch = ''
sed -i 's,/usr\(/include/sys/syscall.h\),${headers}\1,g' lib/lib*/sys/Makefile.inc
'';
}
@@ -2,6 +2,14 @@
mkDerivation {
path = "lib/libcrypt";
libcMinimal = true;
outputs = [
"out"
"man"
];
SHLIBINSTALLDIR = "$(out)/lib";
meta.platforms = lib.platforms.netbsd;
}
+12 -6
View File
@@ -1,12 +1,18 @@
{
lib,
mkDerivation,
sys,
}:
{ lib, mkDerivation }:
mkDerivation {
path = "lib/libm";
libcMinimal = true;
outputs = [
"out"
"man"
];
SHLIBINSTALLDIR = "$(out)/lib";
extraPaths = [ "sys" ];
meta.platforms = lib.platforms.netbsd;
extraPaths = [ sys.path ];
}
@@ -1,27 +1,37 @@
{
lib,
stdenvLibcMinimal,
mkDerivation,
headers,
libc,
libcMinimal,
librt,
sys,
}:
mkDerivation (
import ./base.nix
// {
pname = "libpthread";
installPhase = null;
noCC = false;
dontBuild = false;
buildInputs = [ headers ];
libcMinimal = true;
outputs = [
"out"
"dev"
"man"
];
SHLIBINSTALLDIR = "$(out)/lib";
# Hack around GCC's limits.h missing the include_next we want See
# https://gcc.gnu.org/legacy-ml/gcc/2003-10/msg01278.html
NIX_CFLAGS_COMPILE_BEFORE = "-isystem ${stdenvLibcMinimal.cc.libc.dev}/include";
extraPaths = [
"common"
libc.path
libcMinimal.path
librt.path
sys.path
"sys"
];
meta.platforms = lib.platforms.netbsd;
}
)
@@ -1,11 +1,15 @@
{
lib,
mkDerivation,
libc,
libcMinimal,
}:
mkDerivation {
path = "lib/libresolv";
libcMinimal = true;
extraPaths = [ libcMinimal.path ];
meta.platforms = lib.platforms.netbsd;
extraPaths = [ libc.path ];
}
+12 -2
View File
@@ -14,8 +14,14 @@
mkDerivation {
path = "lib/librpcsvc";
makeFlags = defaultMakeFlags ++ [ "INCSDIR=$(out)/include/rpcsvc" ];
meta.platforms = lib.platforms.netbsd;
libcMinimal = true;
outputs = [
"out"
"dev"
];
nativeBuildInputs = [
bsdSetupHook
netbsdSetupHook
@@ -26,4 +32,8 @@ mkDerivation {
rpcgen
statHook
];
makeFlags = defaultMakeFlags ++ [ "INCSDIR=$(dev)/include/rpcsvc" ];
meta.platforms = lib.platforms.netbsd;
}
+13 -4
View File
@@ -1,13 +1,22 @@
{
lib,
mkDerivation,
libc,
headers,
libcMinimal,
}:
mkDerivation {
path = "lib/librt";
libcMinimal = true;
outputs = [
"out"
"man"
];
extraPaths = [ libcMinimal.path ] ++ libcMinimal.extraPaths;
inherit (libcMinimal) postPatch;
meta.platforms = lib.platforms.netbsd;
extraPaths = [ libc.path ] ++ libc.extraPaths;
inherit (libc) postPatch;
}
+22 -7
View File
@@ -1,7 +1,7 @@
{
lib,
stdenvLibcMinimal,
mkDerivation,
libc,
sys,
bsdSetupHook,
netbsdSetupHook,
makeMinimal,
@@ -16,11 +16,14 @@
mkDerivation {
path = "lib/libutil";
extraPaths = [
"common"
"lib/libc"
"sys"
libcMinimal = true;
outputs = [
"out"
"man"
];
nativeBuildInputs = [
bsdSetupHook
netbsdSetupHook
@@ -32,6 +35,18 @@ mkDerivation {
mandoc
statHook
];
buildInputs = [ headers ];
SHLIBINSTALLDIR = "$(out)/lib";
# Hack around GCC's limits.h missing the include_next we want See
# https://gcc.gnu.org/legacy-ml/gcc/2003-10/msg01278.html
NIX_CFLAGS_COMPILE_BEFORE = "-isystem ${stdenvLibcMinimal.cc.libc.dev}/include";
extraPaths = [
"common"
"lib/libc"
"sys"
];
meta.platforms = lib.platforms.netbsd;
}
@@ -3,6 +3,7 @@
stdenv,
stdenvNoCC,
crossLibcStdenv,
stdenvLibcMinimal,
runCommand,
rsync,
source,
@@ -28,6 +29,8 @@ lib.makeOverridable (
stdenvNoCC
else if attrs.noLibc or false then
crossLibcStdenv
else if attrs.libcMinimal or false then
stdenvLibcMinimal
else
stdenv;
in