Skip to content

Commit

Permalink
Fix ghc 9 windows cross compilation (input-output-hk#1450)
Browse files Browse the repository at this point in the history
Fixes Windows cross compilation for GHC 9.0 and 9.2.

Updates wine to use the version that is included with the chosen Nixpkgs (it used to be pinned to an older version).

Moves the configuration of the GHC source into the GHC derivation.  This should make adding Hadrian support easier.

Propagates library dependences (not just pkgconfig ones) on windows so that any DLLs in those libraries can be copied for TH evaluation and to the `/bin` directory of executable components.

Adds gcc and mfcgthreads as library dependencies on Windows so that the DLLs they include will be found.

Use `$pkgsHostTarget` (instead of `ghc-pkg`) to find all the DLLs can copy them to the `/bin` directory of executable components.

Adds support for __int128_t and __uint128_t to language-c to fix aarch64-darwin builds.

Fixed reinstalling packages that come with patched versions in ghcjs.
  • Loading branch information
hamishmack authored May 19, 2022
1 parent e00ff65 commit 82bc945
Show file tree
Hide file tree
Showing 382 changed files with 53,539 additions and 1,066 deletions.
32 changes: 21 additions & 11 deletions builder/comp-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ let
"--ghc-option=-fPIC" "--gcc-option=-fPIC"
]
++ map (o: ''--ghc${lib.optionalString (stdenv.hostPlatform.isGhcjs) "js"}-options="${o}"'') ghcOptions
++ lib.optional (
# GHC 9.2 cross compiler built with older versions of GHC seem to have problems
# with unique conters. Perhaps because the name changed for the counters.
# TODO This work around to use `-j1` should be removed once we are able to build 9.2 with 9.2.
haskellLib.isCrossHost
&& builtins.compareVersions defaults.ghc.version "9.2.1" >= 0
&& builtins.compareVersions defaults.ghc.version "9.3" < 0)
"--ghc-options=-j1"
);

executableToolDepends =
Expand Down Expand Up @@ -346,10 +354,14 @@ let
frameworks # Frameworks will be needed at link time
# Not sure why pkgconfig needs to be propagatedBuildInputs but
# for gi-gtk-hs it seems to help.
++ builtins.concatLists pkgconfig;
++ builtins.concatLists pkgconfig
++ lib.optionals (stdenv.hostPlatform.isWindows)
(lib.flatten component.libs
++ map haskellLib.dependToLib component.depends);

buildInputs = component.libs
++ map haskellLib.dependToLib component.depends;
buildInputs = lib.optionals (!stdenv.hostPlatform.isWindows)
(lib.flatten component.libs
++ map haskellLib.dependToLib component.depends);

nativeBuildInputs =
[shellWrappers buildPackages.removeReferencesTo]
Expand Down Expand Up @@ -482,22 +494,20 @@ let
fi
'')
# In case `setup copy` did not create this
+ (lib.optionalString enableSeparateDataOutput "mkdir -p $data")
+ (lib.optionalString enableSeparateDataOutput ''
mkdir -p $data
'')
+ (lib.optionalString (stdenv.hostPlatform.isWindows && (haskellLib.mayHaveExecutable componentId)) (''
echo "Symlink libffi and gmp .dlls ..."
for p in ${lib.concatStringsSep " " [ libffi gmp ]}; do
find "$p" -iname '*.dll' -exec ln -s {} $out/bin \;
done
''
# symlink all .dlls into the local directory.
# we ask ghc-pkg for *all* dynamic-library-dirs and then iterate over the unique set
# to symlink over dlls as needed.
+ ''
echo "Symlink library dependencies..."
for libdir in $(${stdenv.hostPlatform.config}-ghc-pkg field "*" dynamic-library-dirs --simple-output|xargs|sed 's/ /\n/g'|sort -u); do
if [ -d "$libdir" ]; then
find "$libdir" -iname '*.dll' -exec ln -s {} $out/bin \;
fi
for p in $pkgsHostTargetAsString; do
find "$p" -iname '*.dll' -exec ln -s {} $out/bin \;
find "$p" -iname '*.dll.a' -exec ln -s {} $out/bin \;
done
''))
+ (lib.optionalString doCoverage ''
Expand Down
6 changes: 3 additions & 3 deletions builder/make-config-files.nix
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ let
${target-pkg} init $out/${packageCfgDir}
${lib.concatStringsSep "\n" (lib.mapAttrsToList flagsAndConfig {
"extra-lib-dirs" = map (p: "${lib.getLib p}/lib") component.libs
"extra-lib-dirs" = map (p: "${lib.getLib p}/lib") (lib.flatten component.libs)
# On windows also include `bin` directories that may contain DLLs
++ lib.optionals (stdenv.hostPlatform.isWindows)
(map (p: "${lib.getBin p}/bin")
(component.libs ++ lib.concatLists component.pkgconfig));
"extra-include-dirs" = map (p: "${lib.getDev p}/include") component.libs;
(lib.flatten component.libs ++ lib.concatLists component.pkgconfig));
"extra-include-dirs" = map (p: "${lib.getDev p}/include") (lib.flatten component.libs);
"extra-framework-dirs" = map (p: "${p}/Library/Frameworks") component.frameworks;
})}
Expand Down
11 changes: 8 additions & 3 deletions ci.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@
# aarch64-darwin requires ghc 8.10.7 and does not work on older nixpkgs
(v != "aarch64-darwin" || (
!__elem compiler-nix-name ["ghc865" "ghc884" "ghc8104" "ghc810420210212" "ghc8105" "ghc8106" "ghc901" "ghc921"]
&& !__elem nixpkgsName ["R2105"]))) supportedSystems) (v: v);
&& !__elem nixpkgsName ["R2105"]))
&&
# aarch64-linux requires ghc 8.8.4
(v != "aarch64-linux" || (
!__elem compiler-nix-name ["ghc865" "ghc8104" "ghc810420210212" "ghc8105" "ghc8106" "ghc901" "ghc921"]
))) supportedSystems) (v: v);
crossSystems = nixpkgsName: nixpkgs: compiler-nix-name: system:
# We need to use the actual nixpkgs version we're working with here, since the values
# of 'lib.systems.examples' are not understood between all versions
Expand All @@ -63,10 +68,10 @@
|| (system == "x86_64-darwin" && __elem compiler-nix-name ["ghc8107"]))) {
inherit (lib.systems.examples) ghcjs;
} // lib.optionalAttrs (system == "x86_64-linux" &&
nixpkgsName == "unstable" && (__elem compiler-nix-name ["ghc810420210212" "ghc8107"])) {
nixpkgsName == "unstable" && (__elem compiler-nix-name ["ghc810420210212" "ghc8107" "ghc902" "ghc922"])) {
# Windows cross compilation is currently broken on macOS
inherit (lib.systems.examples) mingwW64;
} // lib.optionalAttrs (system == "x86_64-linux" && nixpkgsName == "unstable" && compiler-nix-name == "ghc8107") {
} // lib.optionalAttrs (system == "x86_64-linux" && nixpkgsName == "unstable" && __elem compiler-nix-name ["ghc8107" "ghc902" "ghc922"]) {
# Musl cross only works on linux
# aarch64 cross only works on linux
inherit (lib.systems.examples) musl64 aarch64-multiplatform;
Expand Down
132 changes: 0 additions & 132 deletions compiler/ghc/configured-src.nix

This file was deleted.

Loading

0 comments on commit 82bc945

Please sign in to comment.