Skip to content

Commit 1590e5c

Browse files
Fix cross compilation TH in devShells (#2415)
* Add haskell-nix.templateHaskell.ghcOptions * Update overlays/armv6l-linux.nix Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update overlays/windows.nix Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Disable macOS ci for now * Bump head.hackage * Disable macOS ci for now * Fix testWrapper type * Simplify mingw_w64.nix * Fix using hix `--command` and `--projectArgs` together * Move libsodium fix into test/overlay.nix * Fix iserv-proxy in dev shells * Bump head.hackage * Bump head.hackage * Fix for musl * Fix for ghcjs * Better way to disable macOS * Fix eval checks --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent e774cf6 commit 1590e5c

File tree

14 files changed

+96
-79
lines changed

14 files changed

+96
-79
lines changed

.github/workflows/pipeline.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,18 @@ jobs:
223223
steps:
224224
- uses: actions/checkout@v4
225225
- name: "Check that evaluation of hydra jobs works without using remote builders for GHC 9.6.7"
226-
run: nix path-info --derivation .#requiredJobs.x86_64-darwin.required-unstable-ghc967-native --show-trace --builders ''
226+
run: |
227+
sed -i 's/runningHydraEvalTest = true;/runningHydraEvalTest = false;/' flake.nix
228+
nix path-info --derivation .#requiredJobs.x86_64-darwin.required-unstable-ghc967-native --show-trace --builders ''
227229
228230
hydra-without-remote-builders-ghc9102:
229231
runs-on: [self-hosted, linux]
230232
steps:
231233
- uses: actions/checkout@v4
232234
- name: "Check that evaluation of hydra jobs works without using remote builders for GHC 9.10.2"
233-
run: nix path-info --derivation .#requiredJobs.x86_64-darwin.required-unstable-ghc9102-native --show-trace --builders ''
235+
run: |
236+
sed -i 's/runningHydraEvalTest = true;/runningHydraEvalTest = false;/' flake.nix
237+
nix path-info --derivation .#requiredJobs.x86_64-darwin.required-unstable-ghc9102-native --show-trace --builders ''
234238
235239
hix-cabal:
236240
runs-on: [self-hosted, linux]

builder/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ let
4141
# component builder and for nix-shells.
4242
ghcForComponent = import ./ghc-for-component-wrapper.nix {
4343
inherit lib ghc haskellLib;
44-
inherit (buildPackages) stdenv;
44+
inherit (pkgs) stdenv;
4545
inherit (buildPackages.buildPackages) runCommand makeWrapper;
4646
inherit (buildPackages.buildPackages.xorg) lndir;
4747
};

builder/ghc-for-component-wrapper.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
, postInstall ? ""
1515
, enableDWARF
1616
, plugins
17+
, ghcOptions ? []
1718
}:
1819

1920
let
@@ -23,7 +24,7 @@ let
2324
libDir = "$wrappedGhc/${configFiles.libDir}";
2425
docDir = "$wrappedGhc/share/doc/ghc/html";
2526
# For musl we can use haddock from the buildGHC
26-
haddock = if stdenv.targetPlatform.isMusl
27+
haddock = if stdenv.hostPlatform.isMusl
2728
then ghc.buildGHC
2829
else ghc;
2930

@@ -107,7 +108,7 @@ let
107108
--set "NIX_${ghcCommandCaps}PKG" "$wrappedGhc/bin/${ghcCommand}-pkg" \
108109
--set "NIX_${ghcCommandCaps}_DOCDIR" "${docDir}" \
109110
--set "GHC_PLUGINS" "$GHC_PLUGINS" \
110-
--set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}"
111+
--set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}"${lib.concatMapStrings (o: " --add-flags ${o}") ghcOptions}
111112
fi
112113
done
113114
@@ -159,8 +160,7 @@ let
159160
inherit script targetPrefix;
160161
inherit (ghc) version meta;
161162
};
162-
propagatedBuildInputs = configFiles.libDeps;
163-
nativeBuildInputs = [ghc];
163+
propagatedBuildInputs = configFiles.libDeps ++ lib.optional stdenv.hasCC stdenv.cc ++ [ghc];
164164
} (''
165165
mkdir -p $out/configFiles
166166
configFiles=$out/configFiles

builder/shell-for.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ let
143143
'';
144144
inherit enableDWARF;
145145
plugins = [];
146+
ghcOptions = haskell-nix.templateHaskell.${compiler.nix-name}.ghcOptions or [];
146147
};
147148

148149
hoogleIndex = let
@@ -192,11 +193,16 @@ in
192193
''} $(builtin type -P "${ghcEnv.targetPrefix}pkg-config" &> /dev/null && echo "--with-pkg-config=${ghcEnv.targetPrefix}pkg-config") \
193194
"$@"
194195
'');
196+
propagatedBuildInputs = mkDrvArgs.propagateBuildInputs or [] ++ ghcEnv.drv.propagatedBuildInputs;
195197
phases = ["installPhase"];
196198
installPhase = ''
197199
echo "${"Shell for " + toString (builtins.map (p : p.identifier.name) selectedPackages)}"
198200
echo $nativeBuildInputs $buildInputs > $out
199201
'';
202+
shellHook = mkDrvArgs.shellHook or "" + lib.optionalString stdenv.hostPlatform.isWindows ''
203+
204+
export pkgsHostTargetAsString="''${pkgsHostTarget[@]}"
205+
'';
200206

201207
# This helps tools like `ghcide` (that use the ghc api) to find
202208
# the correct global package DB.

ci.nix

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,9 @@
2929
(final: prev: {
3030
haskell-nix = prev.haskell-nix // {
3131
inherit checkMaterialization;
32-
extraPkgconfigMappings = prev.haskell-nix.extraPkgconfigMappings or {} // {
33-
"libsodium" = [ "libsodium-18" ];
34-
};
3532
};
36-
libsodium-18 = (final.callPackage (inputs.nixpkgs-2311 + "/pkgs/development/libraries/libsodium") {}).overrideAttrs (_: { dontDisableStatic = true; });
3733
})
34+
(import ./test/overlay.nix)
3835
];
3936
# Needed for dwarf tests
4037
config = haskellNix.config // {

flake.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@
9191
callFlake = import flake-compat;
9292

9393
ifdLevel = 3;
94-
runningHydraEvalTest = false;
94+
# TODO set this to false when the macOS builders for ci.zw3rk.com are back online
95+
runningHydraEvalTest = true;
9596
defaultCompiler = "ghc967";
9697
config = import ./config.nix;
9798

hix/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ let
9292
--projectArgs)
9393
printf %s "$2" > "$HIX_TMPDIR/projectArgs.nix"
9494
shift
95+
args+=(--override-input projectArgs "$(realpath "$HIX_TMPDIR")")
9596
;;
9697
--supportedSystems)
9798
printf %s "$2" > "$HIX_TMPDIR/supportedSystems.nix"
@@ -166,7 +167,6 @@ let
166167
cp $HIX_FLAKE $FLAKE/flake.nix
167168
chmod +w $FLAKE/flake.nix
168169
fi
169-
args+=(--override-input projectArgs "$(realpath "$HIX_TMPDIR")")
170170
nix $cmd "''${args[@]}"
171171
;;
172172
esac

overlays/armv6l-linux.nix

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
11
final: prev:
2+
let
3+
isLinuxCross =
4+
prev.haskell-nix.haskellLib.isCrossHost
5+
&& prev.hostPlatform.isLinux
6+
&& (prev.hostPlatform.isAarch32
7+
|| prev.hostPlatform.isAarch64
8+
|| prev.hostPlatform.isi686);
9+
10+
in
211
{
3-
haskell-nix = prev.haskell-nix // ({
12+
haskell-nix = prev.haskell-nix // final.lib.optionalAttrs isLinuxCross ({
13+
templateHaskell = builtins.mapAttrs (_compiler-nix-name: iserv-proxy-exes:
14+
import ./linux-cross.nix {
15+
inherit (final.stdenv) hostPlatform buildPlatform;
16+
inherit (final) stdenv lib;
17+
inherit (final.pkgsBuildBuild) writeShellScriptBin symlinkJoin;
18+
inherit (final.haskell-nix) haskellLib;
19+
qemu = final.pkgsBuildBuild.qemu;
20+
inherit (final) gmp;
21+
inherit (iserv-proxy-exes) iserv-proxy iserv-proxy-interpreter iserv-proxy-interpreter-prof;
22+
}) final.haskell-nix.iserv-proxy-exes;
423
defaultModules = prev.haskell-nix.defaultModules ++ [
524
({ pkgs, buildModules, config, lib, ... }:
625
let
7-
withTH = import ./linux-cross.nix {
8-
inherit (pkgs.stdenv) hostPlatform buildPlatform;
9-
inherit (pkgs) stdenv lib;
10-
inherit (pkgs.pkgsBuildBuild) writeShellScriptBin symlinkJoin;
11-
inherit (pkgs.haskell-nix) haskellLib;
12-
# qemu for linux
13-
# Using `buildPackages.buildPackages` here fixes `python3Packages.pygobject3` issue.
14-
qemu = pkgs.buildPackages.buildPackages.qemu;
15-
16-
# wine = pkgs.buildPackages.winePackages.minimal;
17-
# inherit (pkgs.windows) mingw_w64_pthreads;
18-
inherit (pkgs) gmp;
19-
# iserv-proxy needs to come from the buildPackages, as it needs to run on the
20-
# build host.
21-
inherit (final.haskell-nix.iserv-proxy-exes.${config.compiler.nix-name}) iserv-proxy iserv-proxy-interpreter iserv-proxy-interpreter-prof;
22-
} // {
23-
# we can perform testing of cross compiled test-suites by using wine.
24-
# Therefore let's enable doCrossCheck here!
25-
doCrossCheck = pkgs.stdenv.hostPlatform.isWindows;
26-
};
26+
withTH = final.haskell-nix.templateHaskell.${config.compiler.nix-name};
2727
in prev.haskell-nix.haskellLib.addPackageKeys {
28+
inherit (withTH) configureFlags testWrapper;
29+
30+
setupBuildFlags = map (opt: "--ghc-option=" + opt) withTH.ghcOptions
31+
++ lib.optionals pkgs.stdenv.hostPlatform.isAarch32 (map (opt: "--gcc-option=" + opt) [ "-fno-pic" "-fno-plt" ])
32+
# Also for GHC #15275
33+
++ lib.optionals pkgs.stdenv.hostPlatform.isAarch64 ["--gcc-option=-fPIC"];
34+
35+
enableShared = lib.mkDefault false;
36+
37+
doCrossCheck = true;
38+
2839
packages = {
2940
# clock 0.7.2 needs to be patched to support cross compilation.
3041
clock.patches = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isAarch32 [ ({ version }: (if version == "0.7.2" then ./patches/clock-0.7.2.patch else null)) ];
31-
# nix calls this package crypto
32-
# cryptonite-openssl.patches = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isWindows [ ({ version }: if version == "0.7" then ./patches/cryptonite-openssl-0.7.patch else null) ];
33-
34-
# http-client.patches = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isWindows [ ({ version }: if version == "0.5.14" then ./patches/http-client-0.5.14.patch else null) ];
35-
36-
# conduit.patches = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isWindows [ ({ version }: if builtins.compareVersions version "1.3.1.1" < 0 then ./patches/conduit-1.3.0.2.patch else null) ];
37-
# streaming-commons.patches = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isWindows [ ./patches/streaming-commons-0.2.0.0.patch ];
38-
# x509-system.patches = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isWindows [ ./patches/x509-system-1.6.6.patch ];
39-
# file-embed-lzma.patches = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isWindows [ ./patches/file-embed-lzma-0.patch ];
4042

4143
# Set all of these to [], as these form the
4244
# dependency graph of the libiserv, iserv-proxy, and iserv-remote
@@ -59,7 +61,7 @@ final: prev:
5961
network.setupBuildFlags = [];
6062
unix.setupBuildFlags = [];
6163
};
62-
}// withTH
64+
}
6365
)
6466
];
6567
});

overlays/linux-cross.nix

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ let
3131
# ensure that we get a low pid < 65535 for android (If we run outside)
3232
# of nix build envs.
3333

34-
# we want this to hold only for arm (32 and 64bit) for now.
35-
isLinuxCross = haskellLib.isCrossHost && hostPlatform.isLinux && (hostPlatform.isAarch32 || hostPlatform.isAarch64 || hostPlatform.isi686);
3634
qemuIservWrapperScript = enableProfiling:
3735
let
3836
interpreter =
@@ -58,15 +56,12 @@ let
5856
'';
5957
qemuIservWrapper = symlinkJoin { name = "iserv-wrapper"; paths = [ (qemuIservWrapperScript false) (qemuIservWrapperScript true) ]; };
6058
configureFlags = lib.optional (hostPlatform.isAarch32 || hostPlatform.isAndroid) "--disable-split-sections";
61-
setupBuildFlags = map (opt: "--ghc-option=" + opt) ((lib.optionals isLinuxCross
59+
ghcOptions =
6260
[ "-fexternal-interpreter"
6361
"-pgmi" "${qemuIservWrapper}/bin/iserv-wrapper"
6462
"-L${gmp}/lib"
6563
# Required to work-around https://gitlab.haskell.org/ghc/ghc/issues/15275
66-
] ++ lib.optionals hostPlatform.isAarch64 ["-fPIC"]))
67-
++ lib.optionals hostPlatform.isAarch32 (map (opt: "--gcc-option=" + opt) [ "-fno-pic" "-fno-plt" ])
68-
# Also for GHC #15275
69-
++ lib.optionals hostPlatform.isAarch64 ["--gcc-option=-fPIC"];
64+
] ++ lib.optionals hostPlatform.isAarch64 ["-fPIC"];
7065

7166
# Wrapper for qemu testing
7267
qemuTestWrapper = writeShellScriptBin "test-wrapper" ''
@@ -75,8 +70,6 @@ let
7570
'';
7671

7772
# Choose the appropriate test wrapper
78-
testWrapper = lib.optional isLinuxCross "${qemuTestWrapper}/bin/test-wrapper";
73+
testWrapper = [ "${qemuTestWrapper}/bin/test-wrapper" ];
7974

80-
enableShared = lib.mkDefault (!isLinuxCross);
81-
82-
in { inherit configureFlags setupBuildFlags testWrapper enableShared; }
75+
in { inherit configureFlags ghcOptions testWrapper; }

overlays/mingw_w64.nix

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}:
1414
let
1515

16-
configureFlags = lib.optional hostPlatform.isWindows "--disable-split-sections";
16+
configureFlags = ["--disable-split-sections"];
1717

1818
wineIservWrapperScript = enableProfiling:
1919
let
@@ -73,14 +73,14 @@ let
7373
################################################################################
7474
# Build logic (TH support via remote iserv via wine)
7575
#
76-
setupBuildFlags = map (opt: "--ghc-option=" + opt) (lib.optionals hostPlatform.isWindows ([
76+
ghcOptions = [
7777
"-fexternal-interpreter"
7878
"-pgmi" "${wineIservWrapper}/bin/iserv-wrapper"
7979
# TODO: this should be automatically injected based on the extraLibrary.
8080
"-L${mingw_w64_pthreads}/lib"
8181
"-L${mingw_w64_pthreads}/bin"
8282
"-L${gmp}/lib"
83-
]));
83+
];
8484

8585
################################################################################
8686
# Test logic via wine
@@ -103,6 +103,6 @@ let
103103
export Path
104104
${wine}/bin/wine64 $@
105105
'';
106-
testWrapper = lib.optional hostPlatform.isWindows "${wineTestWrapper}/bin/test-wrapper";
106+
testWrapper = ["${wineTestWrapper}/bin/test-wrapper"];
107107

108-
in { inherit testWrapper setupBuildFlags configureFlags; }
108+
in { inherit testWrapper ghcOptions configureFlags; }

0 commit comments

Comments
 (0)