commit:     08cadeb6ad138ce9d610f34312558f2f7a5ba154
Author:     James Le Cuirot <chewi <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 25 22:26:30 2026 +0000
Commit:     James Le Cuirot <chewi <AT> gentoo <DOT> org>
CommitDate: Sun Feb  1 11:42:11 2026 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=08cadeb6

sysroot.eclass: Add support for running Windows binaries via Wine

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 <chewi <AT> gentoo.org>

 eclass/sysroot.eclass | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/eclass/sysroot.eclass b/eclass/sysroot.eclass
index 0fae642bf593..3d710f491741 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

Reply via email to