nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 buildPlatform,
4 hostPlatform,
5 fetchurl,
6 bash,
7 coreutils,
8 gcc,
9 musl,
10 binutils,
11 gnumake,
12 gnused,
13 gnugrep,
14 gawk,
15 diffutils,
16 findutils,
17 gnutar,
18 gzip,
19 bzip2,
20 xz,
21}:
22let
23 pname = "gcc";
24 version = "13.2.0";
25
26 src = fetchurl {
27 url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.xz";
28 hash = "sha256-4nXnZEKmBnNBon8Exca4PYYTFEAEwEE1KIY9xrXHQ9o=";
29 };
30
31 gmpVersion = "6.3.0";
32 gmp = fetchurl {
33 url = "mirror://gnu/gmp/gmp-${gmpVersion}.tar.xz";
34 hash = "sha256-o8K4AgG4nmhhb0rTC8Zq7kknw85Q4zkpyoGdXENTiJg=";
35 };
36
37 mpfrVersion = "4.2.1";
38 mpfr = fetchurl {
39 url = "mirror://gnu/mpfr/mpfr-${mpfrVersion}.tar.xz";
40 hash = "sha256-J3gHNTpnJpeJlpRa8T5Sgp46vXqaW3+yeTiU4Y8fy7I=";
41 };
42
43 mpcVersion = "1.3.1";
44 mpc = fetchurl {
45 url = "mirror://gnu/mpc/mpc-${mpcVersion}.tar.gz";
46 hash = "sha256-q2QkkvXPiCt0qgy3MM1BCoHtzb7IlRg86TDnBsHHWbg=";
47 };
48
49 islVersion = "0.24";
50 isl = fetchurl {
51 url = "https://gcc.gnu.org/pub/gcc/infrastructure/isl-${islVersion}.tar.bz2";
52 hash = "sha256-/PeN2WVsEOuM+fvV9ZoLawE4YgX+GTSzsoegoYmBRcA=";
53 };
54in
55bash.runCommand "${pname}-${version}"
56 {
57 inherit pname version;
58
59 nativeBuildInputs = [
60 gcc
61 binutils
62 gnumake
63 gnused
64 gnugrep
65 gawk
66 diffutils
67 findutils
68 gnutar
69 gzip
70 bzip2
71 xz
72 ];
73
74 passthru.tests.hello-world =
75 result:
76 bash.runCommand "${pname}-simple-program-${version}"
77 {
78 nativeBuildInputs = [
79 binutils
80 musl
81 result
82 ];
83 }
84 ''
85 cat <<EOF >> test.c
86 #include <stdio.h>
87 int main() {
88 printf("Hello World!\n");
89 return 0;
90 }
91 EOF
92 musl-gcc -o test test.c
93 ./test
94 mkdir $out
95 '';
96
97 meta = with lib; {
98 description = "GNU Compiler Collection, version ${version}";
99 homepage = "https://gcc.gnu.org";
100 license = licenses.gpl3Plus;
101 teams = [ teams.minimal-bootstrap ];
102 platforms = platforms.unix;
103 };
104 }
105 ''
106 # Unpack
107 tar xf ${src}
108 tar xf ${gmp}
109 tar xf ${mpfr}
110 tar xf ${mpc}
111 tar xf ${isl}
112 cd gcc-${version}
113
114 ln -s ../gmp-${gmpVersion} gmp
115 ln -s ../mpfr-${mpfrVersion} mpfr
116 ln -s ../mpc-${mpcVersion} mpc
117 ln -s ../isl-${islVersion} isl
118
119 # Patch
120 # force musl even if host triple is gnu
121 sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host
122
123 # Configure
124 export CC="gcc -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
125 export CXX="g++ -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
126 export CFLAGS_FOR_TARGET="-Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
127 export LIBRARY_PATH="${musl}/lib"
128
129 bash ./configure \
130 --prefix=$out \
131 --build=${buildPlatform.config} \
132 --host=${hostPlatform.config} \
133 --with-native-system-header-dir=/include \
134 --with-sysroot=${musl} \
135 --enable-languages=c,c++ \
136 --disable-bootstrap \
137 --disable-libsanitizer \
138 --disable-lto \
139 --disable-multilib \
140 --disable-plugin
141
142 # Build
143 make -j $NIX_BUILD_CORES
144
145 # Install
146 make -j $NIX_BUILD_CORES install-strip
147 ''