Skip to content

Commit aa85e06

Browse files
hamishmackangerman
andauthored
Fix cross compilers (#1886)
* Update flake-utils so cross compile works runs CI * While it's technically true that we are building a cross compiler, we don't care, and want to build a full stage2 compiler, _if_ the architecture is the same. --------- Co-authored-by: Moritz Angermann <moritz.angermann@gmail.com>
1 parent 5c1276b commit aa85e06

File tree

6 files changed

+31
-6
lines changed

6 files changed

+31
-6
lines changed

builder/comp-builder.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ let
170170
"--with-ghc-pkg=${ghc.targetPrefix}ghc-pkg"
171171
"--with-hsc2hs=${ghc.targetPrefix}hsc2hs"
172172
] ++ lib.optional (pkgconfig != [])
173-
"--with-pkg-config=${ghc.targetPrefix}pkg-config"
173+
"--with-pkg-config=${buildPackages.cabalPkgConfigWrapper.targetPrefix}pkg-config"
174174
++ lib.optionals (stdenv.hasCC or (stdenv.cc != null))
175175
( # CC
176176
[ "--with-gcc=${stdenv.cc.targetPrefix}cc"

builder/ghc-for-component-wrapper.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ let
3939
''
4040
# ... but retain the lib/ghc/bin directory. This contains `unlit' and friends.
4141
+ ''
42-
ln -s $unwrappedGhc/lib/${ghcCommand}-${ghc.version}/bin ${libDir}
42+
if [ -d $unwrappedGhc/lib/${ghcCommand}-${ghc.version}/bin ]; then
43+
ln -s $unwrappedGhc/lib/${ghcCommand}-${ghc.version}/bin ${libDir}
44+
else
45+
ln -s $unwrappedGhc/lib/bin ${libDir}
46+
fi
4347
''
4448
# ... and the ghcjs shim's if they are available ...
4549
+ ''

compiler/ghc/default.nix

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ let
220220

221221
useHadrian = builtins.compareVersions ghc-version "9.4" >= 0;
222222
# Indicates if we are installing by copying the hadrian stage1 output
223-
installStage1 = useHadrian && (haskell-nix.haskellLib.isCrossTarget || targetPlatform.isMusl);
223+
# I think we want to _always_ just install stage1. For now let's do this
224+
# for musl only; but I'd like to stay far away from the unnecessary
225+
# bindist logic as we can. It's slow, and buggy, and doesn't provide any
226+
# value for us.
227+
installStage1 = useHadrian && (haskell-nix.haskellLib.isCrossTarget || stdenv.targetPlatform.isMusl);
224228

225229
inherit ((buildPackages.haskell-nix.cabalProject {
226230
compiler-nix-name = "ghc8107";
@@ -586,6 +590,10 @@ stdenv.mkDerivation (rec {
586590
--replace 'dynamic-library-dirs:' 'dynamic-library-dirs: ${libcxx}/lib ${libcxxabi}/lib'
587591
find . -name 'system*.conf*'
588592
cat mk/system-cxx-std-lib-1.0.conf
593+
'' + lib.optionalString (installStage1 && stdenv.targetPlatform.isMusl) ''
594+
substituteInPlace hadrian/cfg/system.config \
595+
--replace 'cross-compiling = YES' \
596+
'cross-compiling = NO'
589597
'';
590598
});
591599

@@ -651,13 +659,24 @@ stdenv.mkDerivation (rec {
651659
--replace 'dynamic-library-dirs:' 'dynamic-library-dirs: ${libcxx}/lib ${libcxxabi}/lib'
652660
find . -name 'system*.conf*'
653661
cat mk/system-cxx-std-lib-1.0.conf
662+
'' + lib.optionalString (installStage1 && stdenv.targetPlatform.isMusl) ''
663+
substituteInPlace hadrian/cfg/system.config \
664+
--replace 'cross-compiling = YES' \
665+
'cross-compiling = NO'
654666
'';
655667
buildPhase = ''
656668
${hadrian}/bin/hadrian ${hadrianArgs}
657669
'' + lib.optionalString installStage1 ''
658670
${hadrian}/bin/hadrian ${hadrianArgs} stage1:lib:libiserv
659671
'' + lib.optionalString targetPlatform.isMusl ''
660672
${hadrian}/bin/hadrian ${hadrianArgs} stage1:lib:terminfo
673+
'' + lib.optionalString (installStage1 && !haskell-nix.haskellLib.isCrossTarget) ''
674+
${hadrian}/bin/hadrian ${hadrianArgs} stage2:exe:iserv
675+
pushd _build/stage1/bin
676+
for exe in *; do
677+
mv $exe ${targetPrefix}$exe
678+
done
679+
popd
661680
'';
662681

663682
# Hadrian's installation only works for native compilers, and is broken for cross compilers.

compiler/windows/include/windows.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
typedef unsigned long DWORD;
99
typedef void * PVOID;
10+
typedef PVOID HANDLE;
11+
typedef void CRITICAL_SECTION;
1012

1113
typedef struct _RTL_CONDITION_VARIABLE { PVOID Ptr; } RTL_CONDITION_VARIABLE;
1214
typedef RTL_CONDITION_VARIABLE CONDITION_VARIABLE;

overlays/bootstrap.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ in {
184184
++ fromUntil "8.6.5" "9.5" ./patches/ghc/ghc-hpc-response-files.patch # https://gitlab.haskell.org/ghc/ghc/-/merge_requests/8194
185185
++ final.lib.optionals (final.stdenv.targetPlatform.isWindows) (fromUntil "9.4.1" "9.5" ./patches/ghc/ghc-9.4-hadrian-win-cross.patch)
186186
++ fromUntil "9.6.1" "9.8" ./patches/ghc/MR10116.patch
187-
++ fromUntil "9.4.1" "9.6" ./patches/ghc/hadrian-build-deriveConstants-genprimopcode-ghc94.patch
188-
++ fromUntil "9.6.1" "9.8" ./patches/ghc/hadrian-build-deriveConstants-genprimopcode.patch
187+
++ final.lib.optionals (final.stdenv.buildPlatform == final.stdenv.targetPlatform) (fromUntil "9.4.1" "9.6" ./patches/ghc/hadrian-build-deriveConstants-genprimopcode-ghc94.patch)
188+
++ final.lib.optionals (final.stdenv.buildPlatform == final.stdenv.targetPlatform) (fromUntil "9.6.1" "9.8" ./patches/ghc/hadrian-build-deriveConstants-genprimopcode.patch)
189189

190190
# the following is a partial reversal of https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4391, to address haskell.nix#1227
191191
++ final.lib.optional (versionAtLeast "8.10.6" && versionLessThan "9.0" && final.stdenv.targetPlatform.isAarch64) ./patches/ghc/mmap-next.patch

scripts/check-compiler-materialization/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ in builtins.listToAttrs (builtins.concatMap (system: builtins.concatMap (compile
4040
# In some cased you may need comment out one or more of these if the GHC version needed cannot be built.
4141
{ name = "${prefix}-musl"; value = (pkgs.pkgsCross.musl64.haskell-nix.roots' compiler-nix-name).ghc-extra-projects-nix or {}; }
4242
{ name = "${prefix}-hello-musl"; value = pkgs.pkgsCross.musl64.haskell-nix.tool compiler-nix-name "hello" {}; }
43-
] ++ eval.lib.optionals (system == "x86_64-linux" && __elem compiler-nix-name ["ghc884" "ghc8105" "ghc8106" "ghc8107" "ghc902" "ghc922" "ghc923" "ghc924" "ghc925" "ghc926" "ghc927" "ghc944"]) [
43+
] ++ eval.lib.optionals (system == "x86_64-linux" && !__elem compiler-nix-name ["ghc865" "ghc881" "ghc882" "ghc883" "ghc8101" "ghc8102" "ghc8103" "ghc8104" "ghc901" "ghc921" "ghc941" "ghc942" "ghc943"]) [
4444
{ name = "${prefix}-arm"; value = (pkgs.pkgsCross.aarch64-multiplatform.haskell-nix.roots' compiler-nix-name).ghc-extra-projects-nix or {}; }
4545
{ name = "${prefix}-hello-arm"; value = pkgs.pkgsCross.aarch64-multiplatform.haskell-nix.tool compiler-nix-name "hello" {}; }
4646
] ++ eval.lib.optionals (

0 commit comments

Comments
 (0)