We do not support installing Wine for other architectures, so we assume
that Wine can do its own CPU emulation.

The sandbox cannot handle Wine and emits a warning even if you allow all
writes, so it needs to be disabled.

Unlike Linux shared libraries, Windows DLLs are placed in bin rather
than lib, so we need to include that in WINEPATH. lib has been included
too, just in case.

binfmt_misc supports Windows binaries, but there is no point in
supporting that combination here, as Wine would need to be installed
locally regardless. This cannot be extended into a container like it can
with QEMU.

This has been tested with i686-w64-mingw32 from crossdev against
dev-vcs/git[iconv] after dropping the iconv cross patch.

Signed-off-by: James Le Cuirot <[email protected]>
---
 eclass/sysroot.eclass | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

I was quite surprised to find that winepath itself runs under Wine. I don't
like that much and thought it was reasonable to convert these particular paths
by hand.

I also realised that libgcc is important here after finding that zstd.exe would
not run without it in the WINEPATH.

diff --git a/eclass/sysroot.eclass b/eclass/sysroot.eclass
index 0fae642bf593c..3d710f4917419 100644
--- a/eclass/sysroot.eclass
+++ b/eclass/sysroot.eclass
@@ -80,7 +80,21 @@ sysroot_make_run_prefixed() {
                fi
        fi

-       if [[ ${QEMU_ARCH} == $(qemu_arch "${CBUILD}") ]]; then
+       if [[ ${CHOST} = *-mingw32 ]]; then
+               if ! type -P wine >/dev/null; then
+                       einfo "Wine not found. Continuing without ${SCRIPT##*/} 
wrapper."
+                       return 1
+               fi
+
+               # UNIX paths can work, but programs will not expect this in 
%PATH%.
+               local 
winepath="Z:${LIBGCC};Z:${MYEROOT}/bin;Z:${MYEROOT}/usr/bin;Z:${MYEROOT}/$(get_libdir);Z:${MYEROOT}/usr/$(get_libdir)"
+
+               # Assume that Wine can do its own CPU emulation.
+               install -m0755 /dev/stdin "${SCRIPT}" <<-EOF || die
+                       #!/bin/sh
+                       SANDBOX_ON=0 LD_PRELOAD= 
WINEPATH="\${WINEPATH}\${WINEPATH+;};${winepath//\//\\}" exec wine "\${@}"
+               EOF
+       elif [[ ${QEMU_ARCH} == $(qemu_arch "${CBUILD}") ]]; then
                # glibc: ld.so is a symlink, ldd is a binary.
                # musl: ld.so doesn't exist, ldd is a symlink.
                local DLINKER candidate
--
2.52.0

Reply via email to