on e94de40 help sign in
haskell.nix/overlays/linux-cross.nix
79 lines 3.2 kB history raw
1let
2 # Here we try to figure out which qemu to use based on the host platform.
3 # This guess can be overridden by passing qemuSuffix
4 qemuByHostPlatform = hostPlatform:
5 # I'd prefer this was a dictionary lookup, with a fall through into abort,
6 # that would make this more readable I guess. I think there is some similar
7 # mapping somewhere in haskell.nix
8 if hostPlatform.isAarch32
9 then "arm"
10 else if hostPlatform.isAarch64
11 then "aarch64"
12 else abort "Don't know which QEMU to use for hostPlatform ${hostPlatform.config}. Please provide qemuSuffix";
13in
14{ stdenv
15, lib
16, writeScriptBin
17, qemu
18, qemuSuffix ? (qemuByHostPlatform hostPlatform)
19, iserv-proxy
20, remote-iserv
21, gmp
22, extra-test-libs ? []
23, buildPlatform
24, hostPlatform
25, ...
26}:
27let
29 # we want this to hold only for arm (32 and 64bit) for now.
30 isLinuxCross = buildPlatform != hostPlatform && hostPlatform.isLinux && (hostPlatform.isAarch32 || hostPlatform.isAarch64);
31 qemuIservWrapper = writeScriptBin "iserv-wrapper" ''
32 #!${stdenv.shell}
33 set -euo pipefail
34 # Unset configure flags as configure should have run already
35 unset configureFlags
36 PORT=$((5000 + $RANDOM % 5000))
37 (>&2 echo "---> Starting remote-iserv on port $PORT")
38 ${qemu}/bin/qemu-${qemuSuffix} ${remote-iserv}/bin/remote-iserv tmp $PORT &
39 (>&2 echo "---| remote-iserv should have started on $PORT")
40 RISERV_PID="$!"
41 ${iserv-proxy}/bin/iserv-proxy $@ 127.0.0.1 "$PORT"
42 (>&2 echo "---> killing remote-iserve...")
43 kill $RISERV_PID
44 '';
45 configureFlags = lib.optional hostPlatform.isAarch32 "--disable-split-sections";
46 setupBuildFlags = map (opt: "--ghc-option=" + opt) ((lib.optionals isLinuxCross
47 [ "-fexternal-interpreter"
48 "-pgmi" "${qemuIservWrapper}/bin/iserv-wrapper"
49 "-L${gmp}/lib"
50 # Required to work-around https://gitlab.haskell.org/ghc/ghc/issues/15275
51 ] ++ lib.optionals hostPlatform.isAarch64 ["-fPIC"]))
52 ++ lib.optionals hostPlatform.isAarch32 (map (opt: "--gcc-option=" + opt) [ "-fno-pic" "-fno-plt" ])
53 # Also for GHC #15275
54 ++ lib.optionals hostPlatform.isAarch64 ["--gcc-option=-fPIC"];
55 qemuTestWrapper = writeScriptBin "test-wrapper" ''
56 #!${stdenv.shell}
57 set -euo pipefail
58 ${qemu}/bin/qemu-${qemuSuffix} $@*
59 '';
60 testWrapper = lib.optional isLinuxCross "${qemuTestWrapper}/bin/test-wrapper";
62 preCheck = lib.optionalString isLinuxCross ''
63 echo "================================================================="
64 echo "RUNNING TESTS for $name via qemu-${qemuSuffix}"
65 echo "================================================================="
66 echo "Copying extra test libraries"
67 for p in ${lib.concatStringsSep " " extra-test-libs}; do
68 find "$p" -iname '*.so*' -exec cp {} . \;
69 done
70 '';
71 postCheck = lib.optionalString isLinuxCross ''
72 echo "================================================================="
73 echo "END RUNNING TESTS"
74 echo "================================================================="
75 '';
77 enableShared = lib.mkDefault (!isLinuxCross);
79in { inherit preCheck postCheck configureFlags setupBuildFlags testWrapper enableShared; }