I agree building vanilla gcc
is not trivial on NixOS
. And doing upstream development using nixpkgs
derivations is even harder. I suggest a simple hack: use buildFHSEnv to get development environment. Something like the following:
# shell.nix:
{ pkgs ? import <nixpkgs> {} }:
let e =
pkgs.buildFHSEnv {
name = "gcc-git-build-env";
targetPkgs = ps: with ps; [
# library depends
gmp gmp.dev
isl
libffi libffi.dev
libmpc
libxcrypt
mpfr mpfr.dev
xz xz.dev
zlib zlib.dev
# git checkout need flex as they are not complete release tarballs
m4
bison
flex
texinfo
# test harness
dejagnu
autogen
# valgrind annotations
valgrind valgrind.dev
# toolchain itself
gcc
stdenv.cc
stdenv.cc.libc stdenv.cc.libc_dev
];
};
in e.env
The full session would look like that:
$ nix-shell
# fetch
$$ git clone --depth 1 https://gcc.gnu.org/git/gcc.git
# build / install
$$ mkdir gcc-build
$$ cd gcc-build
$$ ../gcc/configure --disable-multilib --prefix=$PWD/../gcc-installed
$$ make -j $(nproc)
$$ make install
# test basics
$$ printf '#include <iostream>\nint main() { std::cout << "Hello!" << std::endl ; }' > a.cc
$$ ../gcc-installed/bin/g++ a.cc -o a -static-libstdc++
$$ ./a
Hello!
# run testsuite
$$ make check
...
=== gcc Summary ===
# of expected passes 191743
# of unexpected failures 107
I hope it will help you get started.