Skip to content

Commit

Permalink
Try #1405:
Browse files Browse the repository at this point in the history
  • Loading branch information
iohk-bors[bot] authored Mar 18, 2022
2 parents f3f2c08 + 3567478 commit 613e68f
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 34 deletions.
32 changes: 20 additions & 12 deletions builder/comp-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -382,18 +382,26 @@ let
runHook postConfigure
'';

buildPhase = if stdenv.hostPlatform.isGhcjs then ''
runHook preBuild
# https://gitlab.haskell.org/ghc/ghc/issues/9221
$SETUP_HS build ${haskellLib.componentTarget componentId} ${lib.concatStringsSep " " setupBuildFlags}
runHook postBuild
'' else ''
runHook preBuild
# https://gitlab.haskell.org/ghc/ghc/issues/9221
$SETUP_HS build ${haskellLib.componentTarget componentId} -j$(($NIX_BUILD_CORES > 4 ? 4 : $NIX_BUILD_CORES)) ${lib.concatStringsSep " " setupBuildFlags}
runHook postBuild
''
;
buildPhase =
# It seems that by the time the iserv wrapper specifiec by `--ghc-option=-pgmi` runs
# all the array environment variables are removed from the environment. To get a list
# of all the locations a DLLs might be present we need access to pkgsHostTarget.
# Adding a string version of the list array of nix store paths allows us to get that
# list when we need it.
(lib.optionalString stdenv.hostPlatform.isWindows ''
export pkgsHostTargetAsString="''${pkgsHostTarget[@]}"
'') +
(if stdenv.hostPlatform.isGhcjs then ''
runHook preBuild
# https://gitlab.haskell.org/ghc/ghc/issues/9221
$SETUP_HS build ${haskellLib.componentTarget componentId} ${lib.concatStringsSep " " setupBuildFlags}
runHook postBuild
'' else ''
runHook preBuild
# https://gitlab.haskell.org/ghc/ghc/issues/9221
$SETUP_HS build ${haskellLib.componentTarget componentId} -j$(($NIX_BUILD_CORES > 4 ? 4 : $NIX_BUILD_CORES)) ${lib.concatStringsSep " " setupBuildFlags}
runHook postBuild
'');

# Note: Cabal does *not* copy test executables during the `install` phase.
#
Expand Down
36 changes: 15 additions & 21 deletions overlays/mingw_w64.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let

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

wineIservWrapperVanilla = writeScriptBin "iserv-wrapper" ''
wineIservWrapperScript = enableProfiling: writeScriptBin ("iserv-wrapper" + lib.optionalString enableProfiling "-prof") ''
#!${stdenv.shell}
set -euo pipefail
# unset the configureFlags.
Expand All @@ -28,33 +28,27 @@ let
unset configureFlags
PORT=$((5000 + $RANDOM % 5000))
(>&2 echo "---> Starting remote-iserv on port $PORT")
WINEDLLOVERRIDES="winemac.drv=d" WINEDEBUG=warn-all,fixme-all,-menubuilder,-mscoree,-ole,-secur32,-winediag WINEPREFIX=$TMP ${wine}/bin/wine64 ${remote-iserv}/bin/remote-iserv.exe tmp $PORT &
(>&2 echo "---| remote-iserv should have started on $PORT")
RISERV_PID="$!"
${iserv-proxy}/bin/iserv-proxy $@ 127.0.0.1 "$PORT"
(>&2 echo "---> killing remote-iserv...")
kill $RISERV_PID
'';

wineIservWrapperProf = writeScriptBin "iserv-wrapper-prof" ''
#!${stdenv.shell}
set -euo pipefail
# unset the configureFlags.
# configure should have run already
# without restting it, wine might fail
# due to a too large environment.
unset configureFlags
PORT=$((5000 + $RANDOM % 5000))
(>&2 echo "---> Starting remote-iserv on port $PORT")
WINEDLLOVERRIDES="winemac.drv=d" WINEDEBUG=warn-all,fixme-all,-menubuilder,-mscoree,-ole,-secur32,-winediag WINEPREFIX=$TMP ${wine}/bin/wine64 ${remote-iserv.override { enableProfiling = true; }}/bin/remote-iserv.exe tmp $PORT &
REMOTE_ISERV=$(mktemp -d)
ln -s ${remote-iserv.override { inherit enableProfiling; }}/bin/* $REMOTE_ISERV
for p in $pkgsHostTargetAsString; do
find "$p" -iname '*.dll' -exec ln -s {} $REMOTE_ISERV \;
find "$p" -iname '*.dll.a' -exec ln -s {} $REMOTE_ISERV \;
done
(
cd $REMOTE_ISERV
for l in lib*.dll; do
if [[ ! -e "''${l#lib}" ]]; then ln -s "$l" "''${l#lib}"; fi
done
)
WINEDLLOVERRIDES="winemac.drv=d" WINEDEBUG=warn-all,fixme-all,-menubuilder,-mscoree,-ole,-secur32,-winediag WINEPREFIX=$TMP ${wine}/bin/wine64 $REMOTE_ISERV/remote-iserv.exe tmp $PORT &
(>&2 echo "---| remote-iserv should have started on $PORT")
RISERV_PID="$!"
${iserv-proxy}/bin/iserv-proxy $@ 127.0.0.1 "$PORT"
(>&2 echo "---> killing remote-iserv...")
kill $RISERV_PID
'';

wineIservWrapper = symlinkJoin { name = "iserv-wrapper"; paths = [ wineIservWrapperVanilla wineIservWrapperProf ]; };
wineIservWrapper = symlinkJoin { name = "iserv-wrapper"; paths = [ (wineIservWrapperScript false) (wineIservWrapperScript true) ]; };

################################################################################
# Build logic (TH support via remote iserv via wine)
Expand Down
2 changes: 1 addition & 1 deletion overlays/windows.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ final: prev:
# dependencies) and then placing them somewhere where wine+remote-iserv
# will find them.
remote-iserv.postInstall = pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isWindows (
let extra-libs = [ pkgs.openssl.bin pkgs.libffi pkgs.gmp (pkgs.libsodium-vrf or pkgs.libsodium) pkgs.windows.mcfgthreads pkgs.buildPackages.gcc.cc pkgs.secp256k1 ]; in ''
let extra-libs = [ pkgs.libffi pkgs.gmp pkgs.windows.mcfgthreads pkgs.buildPackages.gcc.cc ]; in ''
for p in ${lib.concatStringsSep " "extra-libs}; do
find "$p" -iname '*.dll' -exec cp {} $out/bin/ \;
find "$p" -iname '*.dll.a' -exec cp {} $out/bin/ \;
Expand Down
1 change: 1 addition & 0 deletions test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ let
sublib-docs = callTest ./sublib-docs { inherit util compiler-nix-name; };
githash = haskell-nix.callPackage ./githash { inherit compiler-nix-name; testSrc = testSrcWithGitDir; };
c-ffi = callTest ./c-ffi { inherit util compiler-nix-name; };
th-dlls = callTest ./th-dlls { inherit util compiler-nix-name; };

unit = unitTests;
};
Expand Down
23 changes: 23 additions & 0 deletions test/th-dlls/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Test building TH code that needs DLLs when cross compiling for windows
{ stdenv, lib, util, project', haskellLib, recurseIntoAttrs, testSrc, compiler-nix-name }:

with lib;

let
project = project' {
inherit compiler-nix-name;
src = testSrc "th-dlls";
};

packages = project.hsPkgs;

in recurseIntoAttrs {
meta.disabled = stdenv.hostPlatform.isGhcjs;

ifdInputs = {
inherit (project) plan-nix;
};

build = packages.th-dlls.components.library;
build-profiled = packages.th-dlls.components.library.profiled;
}
11 changes: 11 additions & 0 deletions test/th-dlls/src/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{-# LANGUAGE TemplateHaskell #-}
module Lib where

import Control.Monad.IO.Class (liftIO)
import OpenSSL (withOpenSSL)
import OpenSSL.BN (withBN)
import Libsodium (sodium_init)
import Language.Haskell.TH.Syntax (Exp(..), Lit(..))

x = $(liftIO (withOpenSSL (withBN 0 (\_ -> return (LitE (IntegerL 0))))))
y = $(liftIO (sodium_init >> return (LitE (IntegerL 0))))
16 changes: 16 additions & 0 deletions test/th-dlls/th-dlls.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cabal-version: >=1.10
name: th-dlls
version: 0.1.0.0
license: PublicDomain
author: Hamish Mackenzie
maintainer: [email protected]
build-type: Simple

library
build-depends: base
, HsOpenSSL
, libsodium
, template-haskell
exposed-modules: Lib
hs-source-dirs: src
default-language: Haskell2010

0 comments on commit 613e68f

Please sign in to comment.