Merge pull request #323414 from obsidiansystems/openbsd-libc-minimal

openbsd.libc: Create from constituent pkgs not hack
This commit is contained in:
John Ericson 2024-06-29 13:37:05 -04:00 committed by GitHub
commit 498ea1c842
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 268 additions and 75 deletions

View File

@ -40,8 +40,10 @@ makeScopeWithSplicing' {
stdenvLibcMinimal = crossLibcStdenv.override (old: {
cc = old.cc.override {
libc = self.libcMinimal;
noLibc = false;
bintools = old.cc.bintools.override {
libc = self.libcMinimal;
noLibc = false;
sharedLibraryLoader = null;
};
};

View File

@ -2,7 +2,6 @@
lib,
stdenvLibcMinimal,
mkDerivation,
headers,
libcMinimal,
librt,
}:

View File

@ -11,7 +11,6 @@
lorder,
mandoc,
statHook,
headers,
}:
mkDerivation {

View File

@ -1,5 +1,7 @@
{
lib,
crossLibcStdenv,
stdenvNoCC,
makeScopeWithSplicing',
generateSplicesForMkScope,
buildPackages,
@ -19,32 +21,71 @@ makeScopeWithSplicing' {
directory = ./pkgs;
}
// {
libc = self.callPackage ./pkgs/libc/package.nix {
inherit (self) csu include;
inherit (buildOpenbsd) makeMinimal;
inherit (buildPackages.netbsd)
install
gencat
rpcgen
tsort
;
};
version = "7.5";
stdenvLibcMinimal = crossLibcStdenv.override (old: {
cc = old.cc.override {
libc = self.libcMinimal;
noLibc = false;
bintools = old.cc.bintools.override {
libc = self.libcMinimal;
noLibc = false;
sharedLibraryLoader = null;
};
};
});
makeMinimal = buildPackages.netbsd.makeMinimal.override { inherit (self) make-rules; };
mkDerivation = self.callPackage ./pkgs/mkDerivation.nix {
inherit (buildPackages.netbsd) install;
inherit (buildPackages.buildPackages) rsync;
};
# The manual callPackages below should in principle be unnecessary, but are
# necessary. See note in ../netbsd/default.nix
include = self.callPackage ./pkgs/include/package.nix {
inherit (buildOpenbsd) makeMinimal;
inherit (buildPackages.netbsd) install rpcgen mtree;
};
csu = self.callPackage ./pkgs/csu.nix {
inherit (self) include;
inherit (buildOpenbsd) makeMinimal;
inherit (buildPackages.netbsd) install;
};
make-rules = self.callPackage ./pkgs/make-rules/package.nix { };
libcMinimal = self.callPackage ./pkgs/libcMinimal/package.nix {
inherit (self) csu include;
inherit (buildOpenbsd) makeMinimal;
inherit (buildPackages.netbsd)
install
gencat
tsort
rpcgen
;
};
librpcsvc = self.callPackage ./pkgs/librpcsvc.nix {
inherit (buildOpenbsd) openbsdSetupHook makeMinimal lorder;
inherit (buildPackages.netbsd)
install
tsort
statHook
rpcgen
;
};
libutil = self.callPackage ./pkgs/libutil.nix {
inherit (self) libcMinimal;
inherit (buildOpenbsd) openbsdSetupHook makeMinimal lorder;
inherit (buildPackages.netbsd) install tsort statHook;
};
lorder = self.callPackage ./pkgs/lorder.nix { inherit (buildPackages.netbsd) install; };
make-rules = self.callPackage ./pkgs/make-rules/package.nix { };
mkDerivation = self.callPackage ./pkgs/mkDerivation.nix {
inherit (buildPackages.netbsd) install tsort;
inherit (buildPackages.buildPackages) rsync;
};
}
);
}

View File

@ -0,0 +1,47 @@
{
lib,
symlinkJoin,
libcMinimal,
librthread,
libm,
librpcsvc,
libutil,
version,
}:
symlinkJoin rec {
name = "${pname}-${version}";
pname = "libc-openbsd";
inherit version;
outputs = [
"out"
"dev"
"man"
];
paths =
lib.concatMap
(p: [
(lib.getDev p)
(lib.getLib p)
(lib.getMan p)
])
[
libcMinimal
libm
librthread
librpcsvc
libutil
];
postBuild = ''
rm -r "$out/nix-support"
mkdir -p "$man/share/man"
mv "$out/share"/man* "$man/share/man"
rmdir "$out/share"
fixupPhase
'';
meta.platforms = lib.platforms.openbsd;
}

View File

@ -20,18 +20,16 @@
mkDerivation {
noLibc = true;
pname = "libc";
path = "lib/libc";
pname = "libcMinimal-openbsd";
outputs = [
"out"
"dev"
"man"
];
extraPaths = [
"lib/csu/os-note-elf.h"
"sys/arch"
"lib/libm"
"lib/libpthread"
"lib/librpcsvc"
"lib/librpcsvc"
"lib/librthread"
"lib/libutil"
];
patches = [
@ -48,12 +46,8 @@ mkDerivation {
openbsdSetupHook
makeMinimal
install
flex
byacc
gencat
rpcgen
ctags
tsort
gencat
];
buildInputs = [
@ -73,49 +67,22 @@ mkDerivation {
) "--undefined-version";
makeFlags = [
"STRIP=-s" # flag to install, not command
"COMPILER_VERSION=clang"
"LIBC_TAGS=no"
];
postInstall = ''
symlink_so () {
pushd $out/lib
ln -s "lib$1".so.* "lib$1.so"
popd
}
symlink_so c
pushd ${include}
find . -type d -exec mkdir -p $out/\{} \;
find . \( -type f -o -type l \) -exec cp -pr \{} $out/\{} \;
find include -type d -exec mkdir -p "$dev/{}" ';'
find include '(' -type f -o -type l ')' -exec cp -pr "{}" "$dev/{}" ';'
popd
substituteInPlace $out/include/sys/time.h --replace "defined (_LIBC)" "true"
substituteInPlace "$dev/include/sys/time.h" --replace "defined (_LIBC)" "true"
pushd ${csu}
find . -type d -exec mkdir -p $out/\{} \;
find . \( -type f -o -type l \) -exec cp -pr \{} $out/\{} \;
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$out/include"
NIX_LDFLAGS+=" -L$out/lib"
make -C $BSDSRCDIR/lib/libm $makeFlags
make -C $BSDSRCDIR/lib/libm $makeFlags install
symlink_so m
make -C $BSDSRCDIR/lib/librthread $makeFlags
make -C $BSDSRCDIR/lib/librthread $makeFlags install
symlink_so pthread
make -C $BSDSRCDIR/lib/librpcsvc $makeFlags
make -C $BSDSRCDIR/lib/librpcsvc $makeFlags install
symlink_so rpcsv
make -C $BSDSRCDIR/lib/libutil $makeFlags
make -C $BSDSRCDIR/lib/libutil $makeFlags install
symlink_so util
'';
meta.platforms = lib.platforms.openbsd;
}

View File

@ -0,0 +1,16 @@
{ lib, mkDerivation }:
mkDerivation {
path = "lib/libm";
libcMinimal = true;
outputs = [
"out"
"man"
];
extraPaths = [ "sys" ];
meta.platforms = lib.platforms.openbsd;
}

View File

@ -0,0 +1,38 @@
{
lib,
mkDerivation,
bsdSetupHook,
openbsdSetupHook,
makeMinimal,
install,
tsort,
lorder,
rpcgen,
statHook,
}:
mkDerivation {
path = "lib/librpcsvc";
libcMinimal = true;
outputs = [
"out"
"dev"
];
nativeBuildInputs = [
bsdSetupHook
openbsdSetupHook
makeMinimal
install
tsort
lorder
rpcgen
statHook
];
makeFlags = [ "INCSDIR=$(dev)/include/rpcsvc" ];
meta.platforms = lib.platforms.openbsd;
}

View File

@ -0,0 +1,29 @@
{
lib,
stdenvLibcMinimal,
mkDerivation,
libcMinimal,
}:
mkDerivation {
path = "lib/librthread";
libcMinimal = true;
outputs = [
"out"
"dev"
];
makeFlags = [ "LIBCSRCDIR=../libc" ];
env.NIX_CFLAGS_COMPILE = "-Wno-error";
extraPaths = [
"lib/libpthread"
libcMinimal.path
#"sys"
];
meta.platforms = lib.platforms.openbsd;
}

View File

@ -0,0 +1,40 @@
{
lib,
stdenvLibcMinimal,
mkDerivation,
libcMinimal,
bsdSetupHook,
openbsdSetupHook,
makeMinimal,
byacc,
install,
tsort,
lorder,
mandoc,
statHook,
}:
mkDerivation {
path = "lib/libutil";
libcMinimal = true;
outputs = [
"out"
"man"
];
nativeBuildInputs = [
bsdSetupHook
openbsdSetupHook
makeMinimal
byacc
install
tsort
lorder
mandoc
statHook
];
meta.platforms = lib.platforms.openbsd;
}

View File

@ -3,6 +3,7 @@
stdenv,
stdenvNoCC,
crossLibcStdenv,
stdenvLibcMinimal,
runCommand,
rsync,
source,
@ -10,6 +11,8 @@
openbsdSetupHook,
makeMinimal,
install,
tsort,
lorder,
}:
lib.makeOverridable (
@ -20,6 +23,8 @@ lib.makeOverridable (
stdenvNoCC
else if attrs.noLibc or false then
crossLibcStdenv
else if attrs.libcMinimal or false then
stdenvLibcMinimal
else
stdenv;
in
@ -46,15 +51,12 @@ lib.makeOverridable (
openbsdSetupHook
makeMinimal
install
tsort
lorder
];
HOST_SH = stdenv'.shell;
makeFlags = [
"STRIP=-s" # flag to install, not command
"-B"
];
MACHINE_ARCH =
{
# amd64 not x86_64 for this on unlike NetBSD
@ -85,9 +87,6 @@ lib.makeOverridable (
// lib.optionalAttrs stdenv'.hasCC {
# TODO should CC wrapper set this?
CPP = "${stdenv'.cc.targetPrefix}cpp";
# Since STRIP in `makeFlags` has to be a flag, not the binary itself
STRIPBIN = "${stdenv'.cc.bintools.targetPrefix}strip";
}
// lib.optionalAttrs (attrs.headersOnly or false) {
installPhase = "includesPhase";

View File

@ -17,5 +17,18 @@ setBinownBingrp() {
export BINGRP=$(id -g)
}
makeOpenBSDUnversionedLinks() {
[[ -d "$out/lib" ]] || return 0
pushd "$out/lib"
local l
for l in lib*.so.*; do
l="${l//.so.*/}"
[[ ! -f "$l.so" ]] || continue
ln -s "$l".so.* "$l.so"
done
popd
}
preConfigureHooks+=(addOpenBSDMakeFlags)
postPatchHooks+=(fixOpenBSDInstallDirs setBinownBingrp)
preFixupHooks+=(makeOpenBSDUnversionedLinks)

View File

@ -1,8 +1,12 @@
{ fetchcvs }:
{
lib,
fetchcvs,
version,
}:
fetchcvs {
cvsRoot = "anoncvs@anoncvs.fr.openbsd.org/cvs";
module = "src";
tag = "OPENBSD_7_5";
tag = "OPENBSD_${lib.replaceStrings [ "." ] [ "_" ] version}-RELEASE";
sha256 = "sha256-hzdATew6h/FQV72SWtg3YvUXdPoGjm2SoUS7m3c3fSU=";
}

View File

@ -28,7 +28,6 @@ addMakeFlags() {
# Definitions passed to share/mk/*.mk. Should be pretty simple -
# eventually maybe move it to a configure script.
export DESTDIR=
export USETOOLS=never
export NOCLANGERROR=yes
export NOGCCERROR=yes