minimal-bootstrap: Minor improvements (#496543)

This commit is contained in:
Jo
2026-03-06 08:50:41 +00:00
committed by GitHub
20 changed files with 44 additions and 148 deletions
@@ -20,21 +20,18 @@ let
# Based on https://github.com/ZilchOS/bootstrap-from-tcc/blob/2e0c68c36b3437386f786d619bc9a16177f2e149/using-nix/2a1-static-binutils.nix
inherit (import ./common.nix { inherit lib; }) meta;
pname = "binutils";
# Unfortunately, this is the latest version (as of 2.45.1) that works for
# - tinycc that compiles gcc 4.6.4 (ar in 2.45.* produce incompatible archives for tcc linker)
# - gcc 4.6.4 that compiles musl 1.2.5 (ld crashes in 2.43 and 2.44)
# This might need some further investigation.
version = "2.42";
version = "2.46.0";
src = fetchurl {
url = "mirror://gnu/binutils/binutils-${version}.tar.xz";
hash = "sha256-9uTUH9X8d4sGt4kUV7NiDaXs6hAGxqSkGumYEJ+FqAA=";
hash = "sha256-11qU9Nc+ekCG91E+Z+Q56Pzcu3Jv/mP0ZhdE5iVrLPI=";
};
patches = [
# Make binutils output deterministic by default.
./deterministic.patch
# Fix __attribute__, to fix mmap-related assertion failures.
./fix-tinycc-attribute.patch
];
configureFlags = [
@@ -105,11 +102,6 @@ bash.runCommand "${pname}-${version}"
export AR="tcc -ar"
export lt_cv_sys_max_cmd_len=32768
# binutils 2.42 has a broken check for TLS storage class, which results
# in the TLS macro begin undefined.
# Let's help it along. We won't need TLS anyway.
export ac_cv_tls=" "
export CFLAGS="-D__LITTLE_ENDIAN__=1"
bash ./configure ${lib.concatStringsSep " " configureFlags}
@@ -0,0 +1,13 @@
diff --git a/include/ansidecl.h b/include/ansidecl.h
index 0ae6a986..214a41f9 100644
--- a/include/ansidecl.h
+++ b/include/ansidecl.h
@@ -68,7 +68,7 @@ So instead we use the macro below and test it against specific values. */
macros freely, and know that they will come into play for the
version of gcc in which they are supported. */
-#if (GCC_VERSION < 2007)
+#if (GCC_VERSION < 2007) && !defined(__TINYC__)
# define __attribute__(x)
#endif
@@ -20,11 +20,11 @@
let
inherit (import ./common.nix { inherit lib; }) meta;
pname = "binutils-static";
version = "2.45.1";
version = "2.46.0";
src = fetchurl {
url = "mirror://gnu/binutils/binutils-${version}.tar.xz";
hash = "sha256-X+EB5v6dGP3slZYtge1nD97l834/SPC++Hvd+GJROqU=";
hash = "sha256-11qU9Nc+ekCG91E+Z+Q56Pzcu3Jv/mP0ZhdE5iVrLPI=";
};
patches = [
@@ -77,5 +77,5 @@ bash.runCommand "${pname}-${version}"
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
make -j $NIX_BUILD_CORES install-strip
''
@@ -1,23 +0,0 @@
Allow BusyBox to be invoked as "<something>-busybox". This is
necessary when it's run from the Nix store as <hash>-busybox during
stdenv bootstrap.
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -947,7 +947,7 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **ar
static NORETURN void run_applet_and_exit(const char *name, char **argv)
{
# if ENABLE_BUSYBOX
- if (is_prefixed_with(name, "busybox"))
+ if (strstr(name, "busybox") != 0)
exit(busybox_main(/*unused:*/ 0, argv));
# endif
# if NUM_APPLETS > 0
@@ -1045,7 +1045,7 @@ int main(int argc UNUSED_PARAM, char **argv)
lbb_prepare("busybox" IF_FEATURE_INDIVIDUAL(, argv));
# if !ENABLE_BUSYBOX
- if (argv[1] && is_prefixed_with(bb_basename(argv[0]), "busybox"))
+ if (argv[1] && strstr(bb_basename(argv[0]), "busybox") != 0)
argv++;
# endif
applet_name = argv[0];
@@ -1,92 +0,0 @@
{
lib,
fetchurl,
bash,
gcc,
musl,
binutils,
linux-headers,
gnumake,
gnupatch,
gnused,
gnugrep,
gawk,
diffutils,
findutils,
gnutar,
bzip2,
}:
let
pname = "busybox-static";
version = "1.36.1";
src = fetchurl {
url = "https://busybox.net/downloads/busybox-${version}.tar.bz2";
hash = "sha256-uMwkyVdNgJ5yecO+NJeVxdXOtv3xnKcJ+AzeUOR94xQ=";
};
patches = [
./busybox-in-store.patch
];
busyboxConfig = [
"CC=musl-gcc"
"HOSTCC=musl-gcc"
"CFLAGS=-I${linux-headers}/include"
"KCONFIG_NOTIMESTAMP=y"
"CONFIG_PREFIX=${placeholder "out"}"
"CONFIG_STATIC=y"
];
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
gcc
musl
binutils
gnumake
gnupatch
gnused
gnugrep
gawk
diffutils
findutils
gnutar
bzip2
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}
mkdir $out
'';
meta = {
description = "Tiny versions of common UNIX utilities in a single small executable";
homepage = "https://busybox.net/";
license = lib.licenses.gpl2Only;
platforms = lib.platforms.linux;
teams = [ lib.teams.minimal-bootstrap ];
};
}
''
# Unpack
tar xf ${src}
cd busybox-${version}
# Patch
${lib.concatMapStringsSep "\n" (f: "patch -Np1 -i ${f}") patches}
# Configure
BUSYBOX_FLAGS="${lib.concatStringsSep " " busyboxConfig}"
make -j $NIX_BUILD_CORES $BUSYBOX_FLAGS defconfig
# Build
make -j $NIX_BUILD_CORES $BUSYBOX_FLAGS
# Install
cp busybox $out
''
@@ -5,6 +5,7 @@
gcc,
musl,
binutils,
findutils,
gnumake,
gnutar,
gzip,
@@ -26,6 +27,7 @@ bash.runCommand "${pname}-${version}"
gcc
musl
binutils
findutils
gnumake
gnutar
gzip
@@ -60,4 +62,8 @@ bash.runCommand "${pname}-${version}"
# Install
make install -j $NIX_BUILD_CORES PREFIX=$out
# Strip
# Ignore failures, because strip may fail on non-elf files.
find $out/{bin,lib} -type f -exec strip --strip-debug {} + || true
''
@@ -76,5 +76,5 @@ bash.runCommand "${pname}-${version}"
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
make -j $NIX_BUILD_CORES install-strip
''
@@ -71,12 +71,6 @@ lib.makeScope
gnutar = gnutar-latest;
};
busybox-static = callPackage ./busybox/static.nix {
gcc = gcc-latest;
gnumake = gnumake-musl;
gnutar = gnutar-latest;
};
bzip2 = callPackage ./bzip2 {
tinycc = tinycc-musl;
gnumake = gnumake-musl;
@@ -376,7 +370,6 @@ lib.makeScope
echo ${binutils.tests.get-version}
echo ${binutils-static.tests.get-version}
echo ${bison.tests.get-version}
echo ${busybox-static.tests.get-version}
echo ${bzip2.tests.get-version}
echo ${bzip2-static.tests.get-version}
echo ${coreutils-musl.tests.get-version}
@@ -77,5 +77,5 @@ bash.runCommand "${pname}-${version}"
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
make -j $NIX_BUILD_CORES install-strip
''
@@ -76,6 +76,6 @@ bash.runCommand "${pname}-${version}"
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
make -j $NIX_BUILD_CORES install-strip
rm $out/bin/updatedb
''
@@ -69,6 +69,6 @@ bash.runCommand "${pname}-${version}"
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
make -j $NIX_BUILD_CORES install-strip
rm $out/bin/gawkbug
''
@@ -77,6 +77,6 @@ bash.runCommand "${pname}-${version}"
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
make -j $NIX_BUILD_CORES install-strip
rm $out/bin/{egrep,fgrep}
''
@@ -86,5 +86,5 @@ bash.runCommand "${pname}-${version}"
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
make -j $NIX_BUILD_CORES install-strip
''
@@ -77,5 +77,5 @@ bash.runCommand "${pname}-${version}"
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
make -j $NIX_BUILD_CORES install-strip
''
@@ -69,5 +69,5 @@ bash.runCommand "${pname}-${version}"
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
make -j $NIX_BUILD_CORES install-strip
''
@@ -69,5 +69,5 @@ bash.runCommand "${pname}-${version}"
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
make -j $NIX_BUILD_CORES install-strip
''
@@ -76,5 +76,5 @@ bash.runCommand "${pname}-${version}"
make -j $NIX_BUILD_CORES bin_SCRIPTS=
# Install
make -j $NIX_BUILD_CORES bin_SCRIPTS= install
make -j $NIX_BUILD_CORES bin_SCRIPTS= install-strip
''
@@ -6,6 +6,7 @@
bash,
gcc,
binutils,
findutils,
gnumake,
gnugrep,
gnused,
@@ -29,6 +30,7 @@ bash.runCommand "${pname}-${version}"
nativeBuildInputs = [
gcc
binutils
findutils
gnumake
gnused
gnugrep
@@ -90,4 +92,8 @@ bash.runCommand "${pname}-${version}"
sed -i 's|/bin/sh|${lib.getExe bash}|' $out/bin/*
ln -s ../lib/libc.so $out/bin/ldd
ln -s $(ls -d ${linux-headers}/include/* | grep -v scsi\$) $out/include/
# Strip
# Ignore failures, because strip may fail on non-elf files.
find $out/{bin,lib} -type f -exec strip --strip-debug {} + || true
''
@@ -77,11 +77,12 @@ bash.runCommand "${pname}-${version}"
--disable-silent-rules \
--disable-nls \
--disable-shared \
--disable-scripts \
--disable-assembler
# Build
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
make -j $NIX_BUILD_CORES install-strip
''