Skip to content

Fix cross compilation TH in devShells #2415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@
systems = [
"x86_64-linux"
] ++ (if runningHydraEvalTest then [ ] else [
"x86_64-darwin"
"aarch64-darwin"
# TODO put these back when the macOS builders for ci.zw3rk.com are back online
# "x86_64-darwin"
# "aarch64-darwin"
]);

nixpkgsArgs = {
Expand Down Expand Up @@ -296,10 +297,11 @@
hydraJobs.nix-tools = pkgs.releaseTools.aggregate {
name = "nix-tools";
constituents = (if runningHydraEvalTest then [ ] else [
"aarch64-darwin.nix-tools.static.zipped.nix-tools-static"
"x86_64-darwin.nix-tools.static.zipped.nix-tools-static"
"aarch64-darwin.nix-tools.static.zipped.nix-tools-static-no-ifd"
"x86_64-darwin.nix-tools.static.zipped.nix-tools-static-no-ifd"
# TODO put these back when the macOS builders for ci.zw3rk.com are back online
# "aarch64-darwin.nix-tools.static.zipped.nix-tools-static"
# "x86_64-darwin.nix-tools.static.zipped.nix-tools-static"
# "aarch64-darwin.nix-tools.static.zipped.nix-tools-static-no-ifd"
# "x86_64-darwin.nix-tools.static.zipped.nix-tools-static-no-ifd"
]) ++ [
"x86_64-linux.nix-tools.static.zipped.nix-tools-static"
"x86_64-linux.nix-tools.static.zipped.nix-tools-static-arm64"
Expand Down
64 changes: 33 additions & 31 deletions overlays/armv6l-linux.nix
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
final: prev:
let
isLinuxCross =
prev.haskell-nix.haskellLib.isCrossHost
&& prev.hostPlatform.isLinux
&& (prev.hostPlatform.isAarch32
|| prev.hostPlatform.isAarch64
|| prev.hostPlatform.isi686);

in
{
haskell-nix = prev.haskell-nix // ({
haskell-nix = prev.haskell-nix // final.lib.optionalAttrs isLinuxCross ({
templateHaskell = builtins.mapAttrs (_compiler-nix-name: iserv-proxy-exes:
import ./linux-cross.nix {
inherit (final.stdenv) hostPlatform buildPlatform;
inherit (final) stdenv lib;
inherit (final.pkgsBuildBuild) writeShellScriptBin symlinkJoin;
inherit (final.haskell-nix) haskellLib;
qemu = final.pkgsBuildBuild.qemu;
inherit (final) gmp;
inherit (iserv-proxy-exes) iserv-proxy iserv-proxy-interpreter iserv-proxy-interpreter-prof;
}) final.haskell-nix.iserv-proxy-exes;
defaultModules = prev.haskell-nix.defaultModules ++ [
({ pkgs, buildModules, config, lib, ... }:
let
withTH = import ./linux-cross.nix {
inherit (pkgs.stdenv) hostPlatform buildPlatform;
inherit (pkgs) stdenv lib;
inherit (pkgs.pkgsBuildBuild) writeShellScriptBin symlinkJoin;
inherit (pkgs.haskell-nix) haskellLib;
# qemu for linux
# Using `buildPackages.buildPackages` here fixes `python3Packages.pygobject3` issue.
qemu = pkgs.buildPackages.buildPackages.qemu;

# wine = pkgs.buildPackages.winePackages.minimal;
# inherit (pkgs.windows) mingw_w64_pthreads;
inherit (pkgs) gmp;
# iserv-proxy needs to come from the buildPackages, as it needs to run on the
# build host.
inherit (final.haskell-nix.iserv-proxy-exes.${config.compiler.nix-name}) iserv-proxy iserv-proxy-interpreter iserv-proxy-interpreter-prof;
} // {
# we can perform testing of cross compiled test-suites by using wine.
# Therefore let's enable doCrossCheck here!
doCrossCheck = pkgs.stdenv.hostPlatform.isWindows;
};
withTH = final.haskell-nix.templateHaskell.${config.compiler.nix-name};
in prev.haskell-nix.haskellLib.addPackageKeys {
inherit (withTH) configureFlags testWrapper;

setupBuildFlags = map (opt: "--ghc-option=" + opt) withTH.ghcOptions
++ lib.optionals pkgs.stdenv.hostPlatform.isAarch32 (map (opt: "--gcc-option=" + opt) [ "-fno-pic" "-fno-plt" ])
# Also for GHC #15275
++ lib.optionals pkgs.stdenv.hostPlatform.isAarch64 ["--gcc-option=-fPIC"];

enableShared = lib.mkDefault false;

doCrossCheck = true;

packages = {
# clock 0.7.2 needs to be patched to support cross compilation.
clock.patches = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isAarch32 [ ({ version }: (if version == "0.7.2" then ./patches/clock-0.7.2.patch else null)) ];
# nix calls this package crypto
# cryptonite-openssl.patches = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isWindows [ ({ version }: if version == "0.7" then ./patches/cryptonite-openssl-0.7.patch else null) ];

# 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) ];

# 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) ];
# streaming-commons.patches = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isWindows [ ./patches/streaming-commons-0.2.0.0.patch ];
# x509-system.patches = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isWindows [ ./patches/x509-system-1.6.6.patch ];
# file-embed-lzma.patches = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isWindows [ ./patches/file-embed-lzma-0.patch ];

# Set all of these to [], as these form the
# dependency graph of the libiserv, iserv-proxy, and iserv-remote
Expand All @@ -59,7 +61,7 @@ final: prev:
network.setupBuildFlags = [];
unix.setupBuildFlags = [];
};
}// withTH
}
)
];
});
Expand Down
15 changes: 4 additions & 11 deletions overlays/linux-cross.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ let
# ensure that we get a low pid < 65535 for android (If we run outside)
# of nix build envs.

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

# Wrapper for qemu testing
qemuTestWrapper = writeShellScriptBin "test-wrapper" ''
Expand All @@ -75,8 +70,6 @@ let
'';

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

enableShared = lib.mkDefault (!isLinuxCross);

in { inherit configureFlags setupBuildFlags testWrapper enableShared; }
in { inherit configureFlags ghcOptions testWrapper; }
10 changes: 5 additions & 5 deletions overlays/mingw_w64.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}:
let

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

wineIservWrapperScript = enableProfiling:
let
Expand Down Expand Up @@ -73,14 +73,14 @@ let
################################################################################
# Build logic (TH support via remote iserv via wine)
#
setupBuildFlags = map (opt: "--ghc-option=" + opt) (lib.optionals hostPlatform.isWindows ([
ghcOptions = [
"-fexternal-interpreter"
"-pgmi" "${wineIservWrapper}/bin/iserv-wrapper"
# TODO: this should be automatically injected based on the extraLibrary.
"-L${mingw_w64_pthreads}/lib"
"-L${mingw_w64_pthreads}/bin"
"-L${gmp}/lib"
]));
];

################################################################################
# Test logic via wine
Expand All @@ -103,6 +103,6 @@ let
export Path
${wine}/bin/wine64 $@
'';
testWrapper = lib.optional hostPlatform.isWindows "${wineTestWrapper}/bin/test-wrapper";
testWrapper = ["${wineTestWrapper}/bin/test-wrapper"];

in { inherit testWrapper setupBuildFlags configureFlags; }
in { inherit testWrapper ghcOptions configureFlags; }
40 changes: 23 additions & 17 deletions overlays/windows.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,32 @@ final: prev:
configureFlags = (drv.configureFlags or []) ++ [ "--enable-static --disable-shared" ];
});

haskell-nix = prev.haskell-nix // ({
haskell-nix = prev.haskell-nix // final.lib.optionalAttrs final.stdenv.hostPlatform.isWindows ({
templateHaskell = builtins.mapAttrs (_compiler-nix-name: iserv-proxy-exes:
import ./mingw_w64.nix {
inherit (final.stdenv) hostPlatform;
inherit (final.pkgsBuildBuild) lib writeShellScriptBin;
wine = final.pkgsBuildBuild.winePackages.minimal;
inherit (final.windows) mingw_w64_pthreads;
inherit (final) gmp;
inherit (final.pkgsBuildBuild) symlinkJoin;
# iserv-proxy needs to come from the buildPackages, as it needs to run on the
# build host.
inherit (iserv-proxy-exes) iserv-proxy iserv-proxy-interpreter iserv-proxy-interpreter-prof;
}) final.haskell-nix.iserv-proxy-exes;
defaultModules = prev.haskell-nix.defaultModules ++ [
({ pkgs, buildModules, config, lib, ... }:
let
withTH = import ./mingw_w64.nix {
inherit (pkgs.stdenv) hostPlatform;
inherit (pkgs.pkgsBuildBuild) lib writeShellScriptBin;
wine = pkgs.pkgsBuildBuild.winePackages.minimal;
inherit (pkgs.windows) mingw_w64_pthreads;
inherit (pkgs) gmp;
inherit (pkgs.pkgsBuildBuild) symlinkJoin;
# iserv-proxy needs to come from the buildPackages, as it needs to run on the
# build host.
inherit (final.haskell-nix.iserv-proxy-exes.${config.compiler.nix-name}) iserv-proxy iserv-proxy-interpreter iserv-proxy-interpreter-prof;
} // {
# we can perform testing of cross compiled test-suites by using wine.
# Therefore let's enable doCrossCheck here!
doCrossCheck = pkgs.stdenv.hostPlatform.isWindows;
};
withTH = final.haskell-nix.templateHaskell.${config.compiler.nix-name};
in prev.haskell-nix.haskellLib.addPackageKeys {
inherit (withTH) configureFlags testWrapper;

setupBuildFlags = map (opt: "--ghc-option=" + opt) withTH.ghcOptions;

# we can perform testing of cross compiled test-suites by using wine.
# Therefore let's enable doCrossCheck here!
doCrossCheck = pkgs.stdenv.hostPlatform.isWindows;

packages = {

# Apply https://github.com/haskell/cabal/pull/6055
Expand Down Expand Up @@ -115,7 +121,7 @@ final: prev:
unix-time.components.library.libs = [ pkgs.windows.mingw_w64_pthreads ];
unix-time.postUnpack = "substituteInPlace */cbits/win_patch.h --replace Windows.h windows.h";
};
} // withTH
}
)
];
});
Expand Down
2 changes: 1 addition & 1 deletion test/cabal.project.local
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repository head.hackage.ghc.haskell.org
f76d08be13e9a61a377a85e2fb63f4c5435d40f8feb3e12eb05905edb8cdea89
26021a13b401500c8eb2761ca95c61f2d625bfef951b939a8124ed12ecf07329
7541f32a4ccca4f97aea3b22f5e593ba2c0267546016b992dfadcd2fe944e55d
--sha256: sha256-V7cPUrMNDXF+LDrNKUE+co1MEmOquGUQ19Z6dJP8bFA=
--sha256: sha256-njXNb4OInAsW0Nfyslum+Kw8X5HDYDXnaXBsW8hUUCU=

repository ghcjs-overlay
url: https://raw.githubusercontent.com/input-output-hk/hackage-overlay-ghcjs/ffb32dce467b9a4d27be759fdd2740a6edd09d0b
Expand Down
Loading