Files
sempiternal-aurora accd3f9567 minimal-bootstrap.gcc_latest: 15.2.0 -> 15.3.0
Also update mpc at the same time, 1.3.1 -> 1.4.1
2026-07-15 16:29:38 +12:00

163 lines
3.7 KiB
Nix

{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
coreutils,
gcc,
musl,
binutils,
gnumake,
gnused,
gnugrep,
gawk,
diffutils,
findutils,
gnutar,
gzip,
bzip2,
xz,
}:
let
pname = "gcc";
# Cannot use 10.5.0, see:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?format=multiple&id=110716
version = "10.4.0";
src = fetchurl {
url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.xz";
hash = "sha256-ySl9W818tD89/C/tU4npSMkxL9li72pM5FXP+WPr5PE=";
};
# last version to compile with gcc 4.6
gmpVersion = "6.2.1";
gmp = fetchurl {
url = "mirror://gnu/gmp/gmp-${gmpVersion}.tar.xz";
hash = "sha256-/UgpkSzd0S+EGBw0Ucx1K+IkZD6H+sSXtp7d2txJtPI=";
};
mpfrVersion = "4.2.2";
mpfr = fetchurl {
url = "mirror://gnu/mpfr/mpfr-${mpfrVersion}.tar.xz";
hash = "sha256-tnugOD736KhWNzTi6InvXsPDuJigHQD6CmhprYHGzgE=";
};
mpcVersion = "1.4.1";
mpc = fetchurl {
url = "mirror://gnu/mpc/mpc-${mpcVersion}.tar.xz";
hash = "sha256-kSBM0y8WS9O3yZLUpqjOZRlRGq2rMPeLaYLQv41z6TE=";
};
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
gcc
binutils
gnumake
gnused
gnugrep
gawk
diffutils
findutils
gnutar
gzip
bzip2
xz
];
passthru.tests.hello-world =
result:
bash.runCommand "${pname}-simple-program-${version}"
{
nativeBuildInputs = [
binutils
musl
result
];
}
''
cat <<EOF >> test.c
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
}
EOF
musl-gcc -o test test.c
./test
mkdir $out
'';
meta = {
description = "GNU Compiler Collection, version ${version}";
homepage = "https://gcc.gnu.org";
license = lib.licenses.gpl3Plus;
teams = [ lib.teams.minimal-bootstrap ];
platforms = lib.platforms.unix;
mainProgram = "gcc";
};
}
''
# Unpack
tar xf ${src}
tar xf ${gmp}
tar xf ${mpfr}
tar xf ${mpc}
cd gcc-${version}
ln -s ../gmp-${gmpVersion} gmp
ln -s ../mpfr-${mpfrVersion} mpfr
ln -s ../mpc-${mpcVersion} mpc
# Patch
# doesn't recognise musl
sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host
# Configure
export CC="gcc -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
export CXX="g++ -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
export CFLAGS="-O1"
export CXXFLAGS="-O1"
export CFLAGS_FOR_TARGET="-O0 -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
export CXXFLAGS_FOR_TARGET="$CFLAGS_FOR_TARGET"
export C_INCLUDE_PATH="${musl}/include"
export CPLUS_INCLUDE_PATH="$C_INCLUDE_PATH"
export LIBRARY_PATH="${musl}/lib"
bash ./configure \
--prefix=$out \
--build=${buildPlatform.config} \
--host=${hostPlatform.config} \
--with-native-system-header-dir=/include \
--with-sysroot=${musl} \
--enable-languages=c,c++ \
--enable-checking=release \
--disable-bootstrap \
--disable-dependency-tracking \
--disable-libmpx \
--disable-libsanitizer \
--disable-libssp \
--disable-libgomp \
--disable-libquadmath \
--disable-libitm \
--disable-libvtv \
--disable-libatomic \
--disable-libstdcxx-pch \
--disable-lto \
--disable-multilib \
--disable-nls \
--disable-plugin \
--without-isl \
--disable-libstdcxx-filesystem-ts \
--disable-shared
# Build
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install-strip
''