on iko/ghcjs-patch-master help sign in
Split configured-src out of ghc/default.nix (#701)

* Split configured-src out of ghc/default.nix

commitdc7acfeb7628032d5109747a8b330d58817b953f authorMoritz Angermann <moritz.angermann@gmail.com> dateMon 22 Jun 2020, 12:53 (6 years ago) parent3c18a7a
2 files changed+134−106
compiler/ghc/configured-src.nix+114 compiler/ghc/default.nix+20−106
compiler/ghc/configured-src.nixnew file+114
@@ -0,0 +1,114 @@
1+{ stdenv, fetchurl
2+, ghc-version, ghc-patches, src-spec
3+, targetPrefix
4+, targetPlatform, hostPlatform
5+, targetPackages
6+, perl, autoconf, automake, m4, python3, sphinx, ghc, bootPkgs
7+, autoreconfHook, toolsForTarget, bash
8+, libDeps
9+, useLLVM, llvmPackages
10+, targetCC
11+, enableIntegerSimple, targetGmp
12+, ncurses, targetLibffi, libiconv
13+, disableLargeAddressSpace
14+, buildMK
15+}:
16+stdenv.mkDerivation (rec {
17+
18+ version = ghc-version;
19+ patches = ghc-patches;
20+ name = "${targetPrefix}ghc-${ghc-version}-configured-src";
21+
22+ # Make sure we never relax`$PATH` and hooks support for compatability.
23+ strictDeps = true;
24+
25+ nativeBuildInputs = [
26+ perl autoconf automake m4 python3 sphinx
27+ ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
28+ ] ++ stdenv.lib.optional (patches != []) autoreconfHook;
29+
30+ # For building runtime libs
31+ depsBuildTarget = toolsForTarget;
32+
33+ buildInputs = [ perl bash ] ++ (libDeps hostPlatform);
34+
35+ propagatedBuildInputs = [ targetPackages.stdenv.cc ]
36+ ++ stdenv.lib.optional useLLVM llvmPackages.llvm;
37+
38+ depsTargetTarget = map stdenv.lib.getDev (libDeps targetPlatform);
39+ depsTargetTargetPropagated = map (stdenv.lib.getOutput "out") (libDeps targetPlatform);
40+
41+ postPatch = "patchShebangs .";
42+
43+ src = fetchurl { inherit (src-spec) url sha256; };
44+
45+ # GHC is a bit confused on its cross terminology.
46+ preConfigure = ''
47+ for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do
48+ export "''${env#TARGET_}=''${!env}"
49+ done
50+ # GHC is a bit confused on its cross terminology, as these would normally be
51+ # the *host* tools.
52+ export CC="${targetCC}/bin/${targetCC.targetPrefix}cc"
53+ export CXX="${targetCC}/bin/${targetCC.targetPrefix}cxx"
54+ # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177
55+ export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${stdenv.lib.optionalString targetPlatform.isAarch32 ".gold"}"
56+ export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as"
57+ export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar"
58+ export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm"
59+ export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib"
60+ export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf"
61+ export STRIP="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}strip"
62+
63+ echo -n "${buildMK}" > mk/build.mk
64+ sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
65+ '' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
66+ export NIX_LDFLAGS+=" -rpath $out/lib/${targetPrefix}ghc-${version}"
67+ '' + stdenv.lib.optionalString stdenv.isDarwin ''
68+ export NIX_LDFLAGS+=" -no_dtrace_dof"
69+ '' + stdenv.lib.optionalString targetPlatform.useAndroidPrebuilt ''
70+ sed -i -e '5i ,("armv7a-unknown-linux-androideabi", ("e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", "cortex-a8", ""))' llvm-targets
71+ '' + stdenv.lib.optionalString targetPlatform.isMusl ''
72+ echo "patching llvm-targets for musl targets..."
73+ echo "Cloning these existing '*-linux-gnu*' targets:"
74+ grep linux-gnu llvm-targets | sed 's/^/ /'
75+ echo "(go go gadget sed)"
76+ sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets
77+ echo "llvm-targets now contains these '*-linux-musl*' targets:"
78+ grep linux-musl llvm-targets | sed 's/^/ /'
79+
80+ echo "And now patching to preserve '-musleabi' as done with '-gnueabi'"
81+ # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen)
82+ for x in configure aclocal.m4; do
83+ substituteInPlace $x \
84+ --replace '*-android*|*-gnueabi*)' \
85+ '*-android*|*-gnueabi*|*-musleabi*)'
86+ done
87+ '';
88+
89+ configurePlatforms = [ "build" "host" "target" ];
90+ # `--with` flags for libraries needed for RTS linker
91+ configureFlags = [
92+ "--datadir=$doc/share/doc/ghc"
93+ "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
94+ ] ++ stdenv.lib.optionals (targetLibffi != null) ["--with-system-libffi" "--with-ffi-includes=${targetLibffi.dev}/include" "--with-ffi-libraries=${targetLibffi.out}/lib"
95+ ] ++ stdenv.lib.optional (!enableIntegerSimple) [
96+ "--with-gmp-includes=${targetGmp.dev}/include" "--with-gmp-libraries=${targetGmp.out}/lib"
97+ ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
98+ "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
99+ ] ++ stdenv.lib.optionals (targetPlatform != hostPlatform) [
100+ "--enable-bootstrap-with-devel-snapshot"
101+ ] ++ stdenv.lib.optionals (disableLargeAddressSpace) [
102+ "--disable-large-address-space"
103+ ] ++ stdenv.lib.optionals (targetPlatform.isAarch32) [
104+ "CFLAGS=-fuse-ld=gold"
105+ "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"
106+ "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"
107+ ] ;
108+
109+ outputs = [ "out" ];
110+ phases = [ "unpackPhase" "patchPhase" ]
111+ ++ stdenv.lib.optional (ghc-patches != []) "autoreconfPhase"
112+ ++ [ "configurePhase" "installPhase" ];
113+ installPhase = "cp -r . $out";
114+})
compiler/ghc/default.nix+20−106
@@ -131,109 +131,25 @@ let
131131
132132 targetCC = builtins.head toolsForTarget;
133133
134−in let configured-src = stdenv.mkDerivation (rec {
135−
136− version = ghc-version;
137−
138− patches = ghc-patches;
139−
140− name = "${targetPrefix}ghc-${ghc-version}-configured-src";
141−
142− # Make sure we never relax`$PATH` and hooks support for compatability.
143− strictDeps = true;
144−
145− nativeBuildInputs = [
146− perl autoconf automake m4 python3 sphinx
147− ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
148− ] ++ stdenv.lib.optional (patches != []) autoreconfHook;
149−
150− # For building runtime libs
151− depsBuildTarget = toolsForTarget;
152−
153− buildInputs = [ perl bash ] ++ (libDeps hostPlatform);
154−
155− propagatedBuildInputs = [ targetPackages.stdenv.cc ]
156− ++ stdenv.lib.optional useLLVM llvmPackages.llvm;
157−
158− depsTargetTarget = map stdenv.lib.getDev (libDeps targetPlatform);
159− depsTargetTargetPropagated = map (stdenv.lib.getOutput "out") (libDeps targetPlatform);
160−
161− postPatch = "patchShebangs .";
162−
163− src = fetchurl { inherit (src-spec) url sha256; };
164−
165− # GHC is a bit confused on its cross terminology.
166− preConfigure = ''
167− for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do
168− export "''${env#TARGET_}=''${!env}"
169− done
170− # GHC is a bit confused on its cross terminology, as these would normally be
171− # the *host* tools.
172− export CC="${targetCC}/bin/${targetCC.targetPrefix}cc"
173− export CXX="${targetCC}/bin/${targetCC.targetPrefix}cxx"
174− # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177
175− export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${stdenv.lib.optionalString targetPlatform.isAarch32 ".gold"}"
176− export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as"
177− export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar"
178− export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm"
179− export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib"
180− export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf"
181− export STRIP="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}strip"
182−
183− echo -n "${buildMK}" > mk/build.mk
184− sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
185− '' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
186− export NIX_LDFLAGS+=" -rpath $out/lib/${targetPrefix}ghc-${version}"
187− '' + stdenv.lib.optionalString stdenv.isDarwin ''
188− export NIX_LDFLAGS+=" -no_dtrace_dof"
189− '' + stdenv.lib.optionalString targetPlatform.useAndroidPrebuilt ''
190− sed -i -e '5i ,("armv7a-unknown-linux-androideabi", ("e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", "cortex-a8", ""))' llvm-targets
191− '' + stdenv.lib.optionalString targetPlatform.isMusl ''
192− echo "patching llvm-targets for musl targets..."
193− echo "Cloning these existing '*-linux-gnu*' targets:"
194− grep linux-gnu llvm-targets | sed 's/^/ /'
195− echo "(go go gadget sed)"
196− sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets
197− echo "llvm-targets now contains these '*-linux-musl*' targets:"
198− grep linux-musl llvm-targets | sed 's/^/ /'
199−
200− echo "And now patching to preserve '-musleabi' as done with '-gnueabi'"
201− # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen)
202− for x in configure aclocal.m4; do
203− substituteInPlace $x \
204− --replace '*-android*|*-gnueabi*)' \
205− '*-android*|*-gnueabi*|*-musleabi*)'
206− done
207− '';
208−
209− configurePlatforms = [ "build" "host" "target" ];
210− # `--with` flags for libraries needed for RTS linker
211− configureFlags = [
212− "--datadir=$doc/share/doc/ghc"
213− "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
214− ] ++ stdenv.lib.optionals (targetLibffi != null) ["--with-system-libffi" "--with-ffi-includes=${targetLibffi.dev}/include" "--with-ffi-libraries=${targetLibffi.out}/lib"
215− ] ++ stdenv.lib.optional (!enableIntegerSimple) [
216− "--with-gmp-includes=${targetGmp.dev}/include" "--with-gmp-libraries=${targetGmp.out}/lib"
217− ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
218− "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
219− ] ++ stdenv.lib.optionals (targetPlatform != hostPlatform) [
220− "--enable-bootstrap-with-devel-snapshot"
221− ] ++ stdenv.lib.optionals (disableLargeAddressSpace) [
222− "--disable-large-address-space"
223− ] ++ stdenv.lib.optionals (targetPlatform.isAarch32) [
224− "CFLAGS=-fuse-ld=gold"
225− "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"
226− "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"
227− ] ;
228−
229− outputs = [ "out" ];
230− phases = [ "unpackPhase" "patchPhase" ]
231− ++ stdenv.lib.optional (ghc-patches != []) "autoreconfPhase"
232− ++ [ "configurePhase" "installPhase" ];
233− installPhase = "cp -r . $out";
234− });
235−
236− drv =stdenv.mkDerivation (rec {
134+ configured-src = import ./configured-src.nix {
135+ inherit stdenv fetchurl
136+ ghc-version ghc-patches src-spec
137+ targetPrefix
138+ targetPlatform hostPlatform
139+ targetPackages
140+ perl autoconf automake m4 python3 sphinx ghc bootPkgs
141+ autoreconfHook toolsForTarget bash
142+ libDeps
143+ useLLVM llvmPackages
144+ targetCC
145+ enableIntegerSimple targetGmp
146+ ncurses targetLibffi libiconv
147+ disableLargeAddressSpace
148+ buildMK
149+ ;
150+ };
151+in
152+stdenv.mkDerivation (rec {
237153 version = ghc-version;
238154 name = "${targetPrefix}ghc-${version}";
239155
@@ -405,6 +321,4 @@ in let configured-src = stdenv.mkDerivation (rec {
405321 dontStrip = true;
406322 dontPatchELF = true;
407323 noAuditTmpdir = true;
408−});
409−
410−in drv
324+})