Skip to content

Commit d07c42c

Browse files
angermanhamishmack
andauthored
Properly transcode absolute LoadDLL paths for WINE (#1974)
* Properly transcode absolute LoadDLL paths for WINE We have this sub-protocol in the iserv-proxy (which follows the sub-TH protocol). The design is horrendous, and needs to be rethought. The issue we were seeing is that we started the sub-protocol, because a path looked like it was absolute, however on the receiving end (windows), the path /foo/bar/baz, is _not_ an absolute windows path. Thus the corresponding branch dealing with the sub-protocol was not taken and we were stuck with messages sent for the primary protocol, and not understood by the sub-protocol. This change transcodes unix paths to windows paths, _IF_ the ISERV_TARGET environment var is set to WINE. In this case we know we can use Z:\\ as / and share the same file system. This is good enough for haskell.nix, but a massive hack generally. --------- Co-authored-by: Hamish Mackenzie <[email protected]>
1 parent 0809f5c commit d07c42c

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

overlays/ghc-packages.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,10 @@ in rec {
250250
+ "/${ghc-extra-projects-type proj.ghc}/${ghcName}";
251251
compiler-nix-name = ghcName;
252252
configureArgs = "--disable-tests --disable-benchmarks --allow-newer='terminfo:base'"; # avoid failures satisfying bytestring package tests dependencies
253-
modules = [{ reinstallableLibGhc = false; }];
253+
modules = [{
254+
packages.iserv-proxy.patches = [./patches/ghc/ghc-8.10.7-iserv-proxy-load-dlls.patch];
255+
reinstallableLibGhc = false;
256+
}];
254257
}))
255258
ghc-extra-pkgs-cabal-projects;
256259

overlays/mingw_w64.nix

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ let
2828
writeScriptBin ("iserv-wrapper" + lib.optionalString enableProfiling "-prof") ''
2929
#!${stdenv.shell}
3030
set -euo pipefail
31+
ISERV_ARGS=''${ISERV_ARGS:-}
32+
PROXY_ARGS=''${PROXY_ARGS:-}
3133
# unset the configureFlags.
3234
# configure should have run already
3335
# without restting it, wine might fail
@@ -36,7 +38,7 @@ let
3638
PORT=$((5000 + $RANDOM % 5000))
3739
(>&2 echo "---> Starting ${interpreter.exeName} on port $PORT")
3840
REMOTE_ISERV=$(mktemp -d)
39-
ln -s ${interpreter}/bin/* $REMOTE_ISERV
41+
ln -s ${interpreter.override { enableDebugRTS = true; }}/bin/* $REMOTE_ISERV
4042
# See coment in comp-builder.nix for where this comes from and why it's here
4143
for p in $pkgsHostTargetAsString; do
4244
find "$p" -iname '*.dll' -exec ln -sf {} $REMOTE_ISERV \;
@@ -53,10 +55,10 @@ let
5355
)
5456
# Not sure why this `unset` helps. It might avoids some kind of overflow issue. We see `wine` fail to start when building `cardano-wallet-cli` test `unit`.
5557
unset pkgsHostTargetAsString
56-
WINEDLLOVERRIDES="winemac.drv=d" WINEDEBUG=warn-all,fixme-all,-menubuilder,-mscoree,-ole,-secur32,-winediag WINEPREFIX=$TMP ${wine}/bin/wine64 $REMOTE_ISERV/${interpreter.exeName} tmp $PORT &
58+
WINEDLLOVERRIDES="winemac.drv=d" WINEDEBUG=warn-all,fixme-all,-menubuilder,-mscoree,-ole,-secur32,-winediag WINEPREFIX=$TMP ${wine}/bin/wine64 $REMOTE_ISERV/${interpreter.exeName} tmp $PORT $ISERV_ARGS &
5759
(>&2 echo "---| ${interpreter.exeName} should have started on $PORT")
5860
RISERV_PID="$!"
59-
${iserv-proxy}/bin/iserv-proxy $@ 127.0.0.1 "$PORT"
61+
ISERV_TARGET=WINE ${iserv-proxy}/bin/iserv-proxy $@ 127.0.0.1 "$PORT" $PROXY_ARGS
6062
(>&2 echo "---> killing ${interpreter.exeName}...")
6163
kill $RISERV_PID
6264
'';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/utils/iserv-proxy/src/Main.hs b/utils/iserv-proxy/src/Main.hs
2+
index 364a2af..68d7307 100644
3+
--- a/src/Main.hs
4+
+++ b/src/Main.hs
5+
@@ -283,8 +283,15 @@ proxy verbose local remote = loop
6+
LoadDLL path@('C':':':_) -> do
7+
fwdCall msg' >>= reply >> loop
8+
LoadDLL path | isAbsolute path -> do
9+
- resp <- fwdLoadCall verbose local remote msg'
10+
- reply resp
11+
+ target <- lookupEnv "ISERV_TARGET"
12+
+ case target of
13+
+ Just "WINE" -> do
14+
+ let path' = 'Z':':':'\\':map (\c -> if c == '/' then '\\' else c) path
15+
+ resp <- fwdCall (LoadDLL path')
16+
+ reply resp
17+
+ Nothing -> do
18+
+ resp <- fwdLoadCall verbose local remote msg'
19+
+ reply resp
20+
loop
21+
Shutdown{} -> fwdCall msg' >> return ()
22+
_other -> fwdCall msg' >>= reply >> loop

0 commit comments

Comments
 (0)