You are not logged in.

#1 2022-01-19 01:22:51

N3k0-san
Member
From: Elsweyr
Registered: 2021-08-14
Posts: 67

Compiling Wine with Clang and LLVM

I'm trying to compile Wine with Clang and LLVM with harder than average optimizations (also with -march=znver2) but I ran into some trouble. (For reference, I modified wine-git as a base.)
I managed to do it twice, in a chroot, but there's one version of the PKGBUILD that throws stack overflow errors and the other compiles fine, but when I run winecfg (which also seems to work fine), I get these messages in the terminal:

0070:err:virtual:virtual_setup_exception stack overflow 1872 bytes in thread 0070 addr 0x17005fbe8 stack 0xa208b0 (0xa20000-0xa21000-0xc20000)
003c:err:service:process_send_command service protocol error - failed to read pipe r = 0  count = 0!
003c:fixme:service:scmdatabase_autostart_services Auto-start service L"winebus" failed to start: 1053
0108:err:user:load_desktop_driver failed to load L"winex11.drv"

I'm not sure exactly why it throws these messages, but I thought maybe it might have been something I did wrong in the PKGBUILD?

Current PKGBUILD (Doesn't work):

# Maintainer : Daniel Bermond <dbermond@archlinux.org>
# Contributor: Sidney Crestani <sidneycrestani@archlinux.net>
# Contributor: sxe <sxxe@gmx.de>
# Edited / modified by: Neko-san <nekoNexus at protonmail dot ch>

pkgname=wine
_pkgver=7.0
pkgver=${_pkgver/-/}
pkgrel=1
pkgdesc='A compatibility layer for running Windows programs'
arch=('x86_64' 'x86_64_v3' 'znver2')
url='https://www.winehq.org/'
license=('LGPL')
depends=(
    'fontconfig'            'lib32-fontconfig'
    'lcms2'                 'lib32-lcms2'
    'libxml2'               'lib32-libxml2'
    'libxcursor'            'lib32-libxcursor'
    'libxrandr'             'lib32-libxrandr'
    'libxdamage'            'lib32-libxdamage'
    'libxi'                 'lib32-libxi'
    'gettext'               'lib32-gettext'
    'freetype2'             'lib32-freetype2'
    'glu'                   'lib32-glu'
    'libsm'                 'lib32-libsm'
    'gcc-libs'              'lib32-gcc-libs'
    'libpcap'               'lib32-libpcap'
    'faudio'                'lib32-faudio'
    'desktop-file-utils'
)
makedepends=('git' 'autoconf' 'bison' 'perl' 'fontforge' 'flex' 'mingw-w64-gcc' 'tar'
    'giflib'                'lib32-giflib'
    'libpng'                'lib32-libpng'
    'gnutls'                'lib32-gnutls'
    'libxinerama'           'lib32-libxinerama'
    'libxcomposite'         'lib32-libxcomposite'
    'libxmu'                'lib32-libxmu'
    'libxxf86vm'            'lib32-libxxf86vm'
    'libldap'               'lib32-libldap'
    'mpg123'                'lib32-mpg123'
    'openal'                'lib32-openal'
    'v4l-utils'             'lib32-v4l-utils'
    'libpulse'              'lib32-libpulse'
    'alsa-plugins'          'lib32-alsa-plugins'
    'libjpeg-turbo'         'lib32-libjpeg-turbo'
    'alsa-lib'              'lib32-alsa-lib'
    'libxcomposite'         'lib32-libxcomposite'
    'mesa'                  'lib32-mesa'
    'libgl'                 'lib32-libgl'
    'opencl-icd-loader'     'lib32-opencl-icd-loader'
    'libxslt'               'lib32-libxslt'
    'gst-plugins-base-libs' 'lib32-gst-plugins-base-libs'
    'vulkan-icd-loader'     'lib32-vulkan-icd-loader'
    'vkd3d'                 'lib32-vkd3d'
    'sdl2'                  'lib32-sdl2'
    'libcups'               'lib32-libcups'
    'libgphoto2'            'valgrind'
    'sane'
    'gsm'
    'cups'
    'samba'
    'dosbox'
    'vulkan-headers'
    'opencl-headers'
)
optdepends=(
    'giflib'                'lib32-giflib'
    'libpng'                'lib32-libpng'
    'libldap'               'lib32-libldap'
    'gnutls'                'lib32-gnutls'
    'mpg123'                'lib32-mpg123'
    'openal'                'lib32-openal'
    'v4l-utils'             'lib32-v4l-utils'
    'libpulse'              'lib32-libpulse'
    'alsa-plugins'          'lib32-alsa-plugins'
    'alsa-lib'              'lib32-alsa-lib'
    'libjpeg-turbo'         'lib32-libjpeg-turbo'
    'libxcomposite'         'lib32-libxcomposite'
    'libxinerama'           'lib32-libxinerama'
    'opencl-icd-loader'     'lib32-opencl-icd-loader'
    'libxslt'               'lib32-libxslt'
    'gst-plugins-base-libs' 'lib32-gst-plugins-base-libs'
    'vulkan-icd-loader'     'lib32-vulkan-icd-loader'
    'vkd3d'                 'lib32-vkd3d'
    'sdl2'                  'lib32-sdl2'
    'libgphoto2'
    'sane'
    'gsm'
    'cups'
    'samba'
    'dosbox'
)
# LTO has to be disabled for at least 7.0-rc4 or else the build will fail
options=('!strip' 'staticlibs' '!lto')
install="${pkgname}.install"
provides=("wine=${pkgver}" "bin32-wine=${pkgver}" "wine-wow64=${pkgver}")
conflicts=('wine-git' 'bin32-wine' 'wine-wow64' 'wine-staging')
replaces=('bin32-wine')
source=("${pkgname}-${_pkgver}.tar.gz::https://github.com/wine-mirror/wine/archive/refs/tags/${pkgname}-${_pkgver}.tar.gz"
        '30-win32-aliases.conf'
        'wine-binfmt.conf')
sha256sums=('SKIP'
            '9901a5ee619f24662b241672a7358364617227937d5f6d3126f70528ee5111e7'
            '6dfdefec305024ca11f35ad7536565f5551f09119dda2028f194aee8f77077a4')

prepare() {
    rm -rf build-{32,64}
    mkdir -p build-{32,64}
    tar xvf ${pkgname}-${_pkgver}.tar.gz
    mv ${pkgname}-${pkgname}-${_pkgver} wine
    
    # fix path of opencl headers
    sed 's|OpenCL/opencl.h|CL/opencl.h|g' -i wine/configure*
    
    # fix openldap 2.5+ detection
    sed 's/-lldap_r/-lldap/' -i wine/configure
}

## Leftover from wine-git PKGBUILD; commented out to prevent makepkg failure
#pkgver() {
#    git -C wine describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/^wine.//;s/^v//;s/\.rc/rc/'
#}

build() {
    ## workaround for FS#55128
    ## https://bugs.archlinux.org/task/55128
    ## https://bugs.winehq.org/show_bug.cgi?id=43530
    
    ## UPDATE: Bug was caused by Nvidia drivers below 415.XX - this fix is no longer necessary
    #export CFLAGS="${CFLAGS/-fno-plt/}"
    #export LDFLAGS="${LDFLAGS/,-z,now/}"
    
    # Enforce gcc and g++ and unset potential globally set Clang and any potentially globally set LLVM variables
    if [ "$CC" = 'gcc' ] && [ "$CXX" = 'g++' ] || [ "$CC" = 'gcc' ] || [ "$CXX" = 'g++' ]; then
		export CC=gcc
		export CXX=g++
		export OBJC=""
		export LD=""
		export AR=""
		export NM=""
		export AS=""
		export RANLIB=""
		export STRIP=""
		export OBJCOPY=""
		# Reset debug flags to makepkg.conf defaults, in case Clang is globally set
		export DEBUG_CFLAGS="-g -fvar-tracking-assignments"
		export DEBUG_CXXFLAGS="-g -fvar-tracking-assignments"
    fi
    
	if [ "$CC" = 'clang' ] && [ "$CXX" = 'clang++' ] || [ "$CC" = 'clang' ] || [ "$CXX" = 'clang++' ]; then
		export OBJC="/usr/bin/clang"
		export LD="/usr/bin/ld.lld"
		export AR="/usr/bin/llvm-ar"
		export NM="/usr/bin/llvm-nm"
		export AS="/usr/bin/llvm-as"
		export RANLIB="/usr/bin/llvm-ranlib"
		export STRIP="/usr/bin/llvm-strip"
		export OBJCOPY="/usr/bin/llvm-objcopy"
		export DEBUG_CFLAGS="-g"
		export DEBUG_CXXFLAGS="-g"
    fi
    
    export CFLAGS+=" -std=gnu89"
    export CXXFLAGS+=" -std=gnu89"
    
    # -O3 optimization because we can :p
    export CFLAGS+=" -O3"
    export LDFLAGS+=" -O3"
    export CROSSCFLAGS="$CFLAGS"
    export CROSSCXXFLAGS="$CXXFLAGS"
    export CROSSLDFLAGS="$LDFLAGS"
    
    # build wine 64-bit
    # (according to the wine wiki, this 64-bit/32-bit building order is mandatory)
    printf '%s\n' '  -> Building wine-64...'
    cd build-64
    ../wine/configure \
        --prefix='/usr' \
        --libdir='/usr/lib' \
        --with-x \
        --with-gstreamer \
        --without-mingw \
        --enable-win64
    make
    
    # build wine 32-bit
    printf '%s\n' '  -> Building wine-32...'
    cd "${srcdir}/build-32"
    export PKG_CONFIG_PATH='/usr/lib32/pkgconfig'
    ../wine/configure \
        --prefix='/usr' \
        --libdir='/usr/lib32' \
        --with-x \
        --with-gstreamer \
        --without-mingw \
        --with-wine64="${srcdir}/build-64"
    make
}

package() {
    # package wine 32-bit
    # (according to the wine wiki, this reverse 32-bit/64-bit packaging order is important)
    printf '%s\n' '  -> Packaging wine-32...'
    cd build-32
    make prefix="${pkgdir}/usr" \
         libdir="${pkgdir}/usr/lib32" \
         dlldir="${pkgdir}/usr/lib32/wine" \
         install
    
    # package wine 64-bit
    printf '%s\n' '  -> Packaging wine-64...'
    cd "${srcdir}/build-64"
    make prefix="${pkgdir}/usr" \
         libdir="${pkgdir}/usr/lib" \
         dlldir="${pkgdir}/usr/lib/wine" \
         install
    
    # font aliasing settings for win32 applications
    install -d -m755 "${pkgdir}/usr/share/fontconfig/conf.default"
    install -D -m644 "${srcdir}/30-win32-aliases.conf" -t "${pkgdir}/usr/share/fontconfig/conf.avail"
    ln -s ../conf.avail/30-win32-aliases.conf "${pkgdir}/usr/share/fontconfig/conf.default/30-win32-aliases.conf"
    
    # wine binfmt
    install -D -m644 "${srcdir}/wine-binfmt.conf" "${pkgdir}/usr/lib/binfmt.d/wine.conf"
    
    # strip native PE libraries
    #i686-w64-mingw32-strip --strip-unneeded "${pkgdir}/usr/lib32/wine/i386-windows"/*.dll
    #x86_64-w64-mingw32-strip --strip-unneeded "${pkgdir}/usr/lib/wine/x86_64-windows"/*.dll
    llvm-strip --strip-unneeded "${pkgdir}/usr/lib32/wine/i386-windows"/*.dll
    llvm-strip --strip-unneeded "${pkgdir}/usr/lib/wine/x86_64-windows"/*.dll
}

Old (Working) PKGBUILD:

# Maintainer : Daniel Bermond <dbermond@archlinux.org>
# Contributor: Sidney Crestani <sidneycrestani@archlinux.net>
# Contributor: sxe <sxxe@gmx.de>
# Edited / modified by: Neko-san <nekoNexus at protonmail dot ch>

pkgname=wine
_pkgver=7.0
pkgver=${_pkgver/-/}
pkgrel=1
pkgdesc='A compatibility layer for running Windows programs'
arch=('x86_64' 'x86_64_v3' 'znver2')
url='https://www.winehq.org/'
license=('LGPL')
depends=(
    'fontconfig'            'lib32-fontconfig'
    'lcms2'                 'lib32-lcms2'
    'libxml2'               'lib32-libxml2'
    'libxcursor'            'lib32-libxcursor'
    'libxrandr'             'lib32-libxrandr'
    'libxdamage'            'lib32-libxdamage'
    'libxi'                 'lib32-libxi'
    'gettext'               'lib32-gettext'
    'freetype2'             'lib32-freetype2'
    'glu'                   'lib32-glu'
    'libsm'                 'lib32-libsm'
    'gcc-libs'              'lib32-gcc-libs'
    'libpcap'               'lib32-libpcap'
    'faudio'                'lib32-faudio'
    'desktop-file-utils'
)
makedepends=('git' 'autoconf' 'bison' 'perl' 'fontforge' 'flex' 'mingw-w64-gcc' 'tar'
    'giflib'                'lib32-giflib'
    'libpng'                'lib32-libpng'
    'gnutls'                'lib32-gnutls'
    'libxinerama'           'lib32-libxinerama'
    'libxcomposite'         'lib32-libxcomposite'
    'libxmu'                'lib32-libxmu'
    'libxxf86vm'            'lib32-libxxf86vm'
    'libldap'               'lib32-libldap'
    'mpg123'                'lib32-mpg123'
    'openal'                'lib32-openal'
    'v4l-utils'             'lib32-v4l-utils'
    'libpulse'              'lib32-libpulse'
    'alsa-plugins'          'lib32-alsa-plugins'
    'libjpeg-turbo'         'lib32-libjpeg-turbo'
    'alsa-lib'              'lib32-alsa-lib'
    'libxcomposite'         'lib32-libxcomposite'
    'mesa'                  'lib32-mesa'
    'libgl'                 'lib32-libgl'
    'opencl-icd-loader'     'lib32-opencl-icd-loader'
    'libxslt'               'lib32-libxslt'
    'gst-plugins-base-libs' 'lib32-gst-plugins-base-libs'
    'vulkan-icd-loader'     'lib32-vulkan-icd-loader'
    'vkd3d'                 'lib32-vkd3d'
    'sdl2'                  'lib32-sdl2'
    'libcups'               'lib32-libcups'
    'libgphoto2'            'valgrind'
    'sane'
    'gsm'
    'cups'
    'samba'
    'dosbox'
    'vulkan-headers'
    'opencl-headers'
)
optdepends=(
    'giflib'                'lib32-giflib'
    'libpng'                'lib32-libpng'
    'libldap'               'lib32-libldap'
    'gnutls'                'lib32-gnutls'
    'mpg123'                'lib32-mpg123'
    'openal'                'lib32-openal'
    'v4l-utils'             'lib32-v4l-utils'
    'libpulse'              'lib32-libpulse'
    'alsa-plugins'          'lib32-alsa-plugins'
    'alsa-lib'              'lib32-alsa-lib'
    'libjpeg-turbo'         'lib32-libjpeg-turbo'
    'libxcomposite'         'lib32-libxcomposite'
    'libxinerama'           'lib32-libxinerama'
    'opencl-icd-loader'     'lib32-opencl-icd-loader'
    'libxslt'               'lib32-libxslt'
    'gst-plugins-base-libs' 'lib32-gst-plugins-base-libs'
    'vulkan-icd-loader'     'lib32-vulkan-icd-loader'
    'vkd3d'                 'lib32-vkd3d'
    'sdl2'                  'lib32-sdl2'
    'libgphoto2'
    'sane'
    'gsm'
    'cups'
    'samba'
    'dosbox'
)
# LTO has to be disabled for at least 7.0-rc4 or else the build will fail
options=('staticlibs' '!lto')
install="${pkgname}.install"
provides=("wine=${pkgver}" "bin32-wine=${pkgver}" "wine-wow64=${pkgver}")
conflicts=('wine-git' 'bin32-wine' 'wine-wow64' 'wine-staging')
replaces=('bin32-wine')
source=("${pkgname}-${_pkgver}.tar.gz::https://github.com/wine-mirror/wine/archive/refs/tags/${pkgname}-${_pkgver}.tar.gz"
        '30-win32-aliases.conf'
        'wine-binfmt.conf')
sha256sums=('SKIP'
            '9901a5ee619f24662b241672a7358364617227937d5f6d3126f70528ee5111e7'
            '6dfdefec305024ca11f35ad7536565f5551f09119dda2028f194aee8f77077a4')

prepare() {
    rm -rf build-{32,64}
    mkdir -p build-{32,64}
    tar xvf ${pkgname}-${_pkgver}.tar.gz
    mv ${pkgname}-${pkgname}-${_pkgver} wine
    
    # fix path of opencl headers
    sed 's|OpenCL/opencl.h|CL/opencl.h|g' -i wine/configure*
    
    # fix openldap 2.5+ detection
    sed 's/-lldap_r/-lldap/' -i wine/configure
}

## Leftover from wine-git PKGBUILD; commented out to prevent makepkg failure
#pkgver() {
#    git -C wine describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/^wine.//;s/^v//;s/\.rc/rc/'
#}

build() {
    ## workaround for FS#55128
    ## https://bugs.archlinux.org/task/55128
    ## https://bugs.winehq.org/show_bug.cgi?id=43530
    
    ## UPDATE: Bug was caused by Nvidia drivers below 415.XX - this fix is no longer necessary
    #export CFLAGS="${CFLAGS/-fno-plt/}"
    #export LDFLAGS="${LDFLAGS/,-z,now/}"
    
    # Enforce gcc and g++ and unset potential globally set Clang and any potentially globally set LLVM variables
    if [ "$CC" = 'gcc' ] && [ "$CXX" = 'g++' ] || [ "$CC" = 'gcc' ] || [ "$CXX" = 'g++' ] ; then
		export CC=gcc
		export CXX=g++
		export OBJC=""
		export LD=""
		export AR=""
		export NM=""
		export AS=""
		export RANLIB=""
		export STRIP=""
		export OBJCOPY=""
		# Reset debug flags to makepkg.conf defaults, in case Clang is globally set
		export DEBUG_CFLAGS="-g -fvar-tracking-assignments"
		export DEBUG_CXXFLAGS="-g -fvar-tracking-assignments"
    fi
    
	if [ "$CC" = 'clang' ] && [ "$CXX" = 'clang++' ] || [ "$CC" = 'clang' ] || [ "$CXX" = 'clang++' ] ; then
		export OBJC="/usr/bin/clang"
		export LD=""
		#export AR="/usr/bin/llvm-ar"
		#export NM="/usr/bin/llvm-nm"
		#export AS="/usr/bin/llvm-as"
		#export RANLIB="/usr/bin/llvm-ranlib"
		#export STRIP="/usr/bin/llvm-strip"
		#export OBJCOPY="/usr/bin/llvm-objcopy"
		export DEBUG_CFLAGS="-g"
		export DEBUG_CXXFLAGS="-g"
    fi
    
    export CFLAGS+=" -std=gnu89"
    
    # -O3 optimization because we can :p
    export CFLAGS+=" -O3"
    export LDFLAGS+=" -O3"
    export CROSSCFLAGS="-O3 -g"
    
    # build wine 64-bit
    # (according to the wine wiki, this 64-bit/32-bit building order is mandatory)
    printf '%s\n' '  -> Building wine-64...'
    cd build-64
    ../wine/configure \
        --prefix='/usr' \
        --libdir='/usr/lib' \
        --with-x \
        --with-gstreamer \
        --enable-win64
    make
    
    # build wine 32-bit
    printf '%s\n' '  -> Building wine-32...'
    cd "${srcdir}/build-32"
    export PKG_CONFIG_PATH='/usr/lib32/pkgconfig'
    ../wine/configure \
        --prefix='/usr' \
        --libdir='/usr/lib32' \
        --with-x \
        --with-gstreamer \
        --with-wine64="${srcdir}/build-64"
    make
}

package() {
    # package wine 32-bit
    # (according to the wine wiki, this reverse 32-bit/64-bit packaging order is important)
    printf '%s\n' '  -> Packaging wine-32...'
    cd build-32
    make prefix="${pkgdir}/usr" \
         libdir="${pkgdir}/usr/lib32" \
         dlldir="${pkgdir}/usr/lib32/wine" \
         install
    
    # package wine 64-bit
    printf '%s\n' '  -> Packaging wine-64...'
    cd "${srcdir}/build-64"
    make prefix="${pkgdir}/usr" \
         libdir="${pkgdir}/usr/lib" \
         dlldir="${pkgdir}/usr/lib/wine" \
         install
    
    # font aliasing settings for win32 applications
    install -d -m755 "${pkgdir}/usr/share/fontconfig/conf.default"
    install -D -m644 "${srcdir}/30-win32-aliases.conf" -t "${pkgdir}/usr/share/fontconfig/conf.avail"
    ln -s ../conf.avail/30-win32-aliases.conf "${pkgdir}/usr/share/fontconfig/conf.default/30-win32-aliases.conf"
    
    # wine binfmt
    install -D -m644 "${srcdir}/wine-binfmt.conf" "${pkgdir}/usr/lib/binfmt.d/wine.conf"
    
    # strip native PE libraries
    i686-w64-mingw32-strip --strip-unneeded "${pkgdir}/usr/lib32/wine/i386-windows"/*.dll
    "x86_64-w64-mingw32-strip" --strip-unneeded "${pkgdir}/usr/lib/wine/x86_64-windows"/*.dll
}

Last edited by N3k0-san (2022-01-19 05:06:17)

Offline

#2 2022-01-19 14:30:43

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,919

Re: Compiling Wine with Clang and LLVM

not working

export LD="/usr/bin/ld.lld"

working

export LD=""

There are some things the gnu linker and the llvm one handle differently , are you sure you want to use lld ?


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#3 2022-01-19 17:51:46

N3k0-san
Member
From: Elsweyr
Registered: 2021-08-14
Posts: 67

Re: Compiling Wine with Clang and LLVM

Lone_Wolf wrote:

not working

export LD="/usr/bin/ld.lld"

working

export LD=""

There are some things the gnu linker and the llvm one handle differently , are you sure you want to use lld ?

Just leaving the linker alone (without using mingw) leaves me with a build that just doesn't work (throws three the stack overflow errors and doesn't run winecfg); it's the same result if I do use lld

Offline

#4 2022-01-23 11:51:16

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,919

Re: Compiling Wine with Clang and LLVM

Another possibile cause is difference between znver2 on gcc & clang, but there are more .


I suggest to start with replacing -march=x86-64 -mtune=generic with -march=znver2 .

Test, if that works try -O3 .
again test and if things work try removing mingw


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#5 2022-01-24 02:42:53

N3k0-san
Member
From: Elsweyr
Registered: 2021-08-14
Posts: 67

Re: Compiling Wine with Clang and LLVM

Lone_Wolf wrote:

Another possibile cause is difference between znver2 on gcc & clang, but there are more .


I suggest to start with replacing -march=x86-64 -mtune=generic with -march=znver2 .

Test, if that works try -O3 .
again test and if things work try removing mingw

I've already tried removing mingw (by itself) and it produces a build that can't even run winecfg
I'll try to use those flags as a test though.

Also, I updated the PKGBUILD quite a bit since then with what I was able together based on issues I was having:

# Original Maintainer of Wine-git : Daniel Bermond <dbermond@archlinux.org>
# Contributor: Sidney Crestani <sidneycrestani@archlinux.net>
# Contributor: sxe <sxxe@gmx.de>
# Edited / modified by: Neko-san <nekoNexus at protonmail dot ch>

pkgname=wine
_pkgver=7.0
pkgver=${_pkgver/-/}
pkgrel=2
pkgdesc='A compatibility layer for running Windows programs'
arch=('x86_64' 'x86_64_v3' 'znver2')
url='https://www.winehq.org/'
license=('LGPL')
depends=(
    'fontconfig'            'lib32-fontconfig'
    'lcms2'                 'lib32-lcms2'
    'libxml2'               'lib32-libxml2'
    'libxcursor'            'lib32-libxcursor'
    'libxrandr'             'lib32-libxrandr'
    'libxdamage'            'lib32-libxdamage'
    'libxi'                 'lib32-libxi'
    'gettext'               'lib32-gettext'
    'freetype2'             'lib32-freetype2'
    'glu'                   'lib32-glu'
    'libsm'                 'lib32-libsm'
    'gcc-libs'              'lib32-gcc-libs'
    'libpcap'               'lib32-libpcap'
    'faudio'                'lib32-faudio'
    'desktop-file-utils'
)
makedepends=('git' 'autoconf' 'bison' 'perl' 'fontforge' 'flex' 'mingw-w64-gcc' 'tar' 'clang' 'llvm' 'lld' 'lib32-llvm' 'lib32-clang'
    'giflib'                'lib32-giflib'
    'libpng'                'lib32-libpng'
    'gnutls'                'lib32-gnutls'
    'libxinerama'           'lib32-libxinerama'
    'libxcomposite'         'lib32-libxcomposite'
    'libxmu'                'lib32-libxmu'
    'libxxf86vm'            'lib32-libxxf86vm'
    'libldap'               'lib32-libldap'
    'mpg123'                'lib32-mpg123'
    'openal'                'lib32-openal'
    'v4l-utils'             'lib32-v4l-utils'
    'libpulse'              'lib32-libpulse'
    'alsa-plugins'          'lib32-alsa-plugins'
    'libjpeg-turbo'         'lib32-libjpeg-turbo'
    'alsa-lib'              'lib32-alsa-lib'
    'libxcomposite'         'lib32-libxcomposite'
    'mesa'                  'lib32-mesa'
    'libgl'                 'lib32-libgl'
    'opencl-icd-loader'     'lib32-opencl-icd-loader'
    'libxslt'               'lib32-libxslt'
    'gst-plugins-base-libs' 'lib32-gst-plugins-base-libs'
    'vulkan-icd-loader'     'lib32-vulkan-icd-loader'
    'vkd3d'                 'lib32-vkd3d'
    'sdl2'                  'lib32-sdl2'
    'libcups'               'lib32-libcups'
    'libgphoto2'            'valgrind'
    'sane'
    'gsm'
    'cups'
    'samba'
    'dosbox'
    'vulkan-headers'
    'opencl-headers'
)
optdepends=(
    'giflib'                'lib32-giflib'
    'libpng'                'lib32-libpng'
    'libldap'               'lib32-libldap'
    'gnutls'                'lib32-gnutls'
    'mpg123'                'lib32-mpg123'
    'openal'                'lib32-openal'
    'v4l-utils'             'lib32-v4l-utils'
    'libpulse'              'lib32-libpulse'
    'alsa-plugins'          'lib32-alsa-plugins'
    'alsa-lib'              'lib32-alsa-lib'
    'libjpeg-turbo'         'lib32-libjpeg-turbo'
    'libxcomposite'         'lib32-libxcomposite'
    'libxinerama'           'lib32-libxinerama'
    'opencl-icd-loader'     'lib32-opencl-icd-loader'
    'libxslt'               'lib32-libxslt'
    'gst-plugins-base-libs' 'lib32-gst-plugins-base-libs'
    'vulkan-icd-loader'     'lib32-vulkan-icd-loader'
    'vkd3d'                 'lib32-vkd3d'
    'sdl2'                  'lib32-sdl2'
    'libgphoto2'
    'sane'
    'gsm'
    'cups'
    'samba'
    'dosbox'
)
# LTO has to be disabled for at least 7.0-rc4 or else the build will fail
options=('!strip' 'staticlibs' '!lto')
install="${pkgname}.install"
provides=("wine=${pkgver}" "bin32-wine=${pkgver}" "wine-wow64=${pkgver}")
conflicts=('wine-git' 'bin32-wine' 'wine-wow64' 'wine-staging')
replaces=('bin32-wine')
source=("${pkgname}-${_pkgver}.tar.gz::https://github.com/wine-mirror/wine/archive/refs/tags/${pkgname}-${_pkgver}.tar.gz"
        '30-win32-aliases.conf'
        'wine-binfmt.conf')
sha256sums=('SKIP'
            '9901a5ee619f24662b241672a7358364617227937d5f6d3126f70528ee5111e7'
            '6dfdefec305024ca11f35ad7536565f5551f09119dda2028f194aee8f77077a4')

## Set these if a specific build type is desired    
export CC=gcc
export CXX=g++

prepare() {
    rm -rf build-{32,64}
    mkdir -p build-{32,64}
    if [ -d wine ]; then
        rm -rf wine
    fi
    tar xvf ${pkgname}-${_pkgver}.tar.gz
    mv ${pkgname}-${pkgname}-${_pkgver} wine
    
    # fix path of opencl headers
    sed 's|OpenCL/opencl.h|CL/opencl.h|g' -i wine/configure*
    
    # fix openldap 2.5+ detection
    sed 's/-lldap_r/-lldap/' -i wine/configure
    
    ## Apply the "Steam 'CrossOver' hack" to permit Windows Steam to render properly"
    ## Grabbing from wine-tkg-git because it gets kept up to date here
    ## UPDATE: IT DOESN'T WORK
    #cd wine
    #wget --output-document steam-crossover-hack-patch.diff "https://raw.githubusercontent.com/Frogging-Family/wine-tkg-git/master/wine-tkg-git/wine-tkg-patches/misc/steam.patch"
    #patch -Np1 -i steam-crossover-hack-patch.diff
    #rm steam-crossover-hack-patch.diff
    #cd ..
}

## Leftover from wine-git PKGBUILD; commented out to prevent makepkg failure
#pkgver() {
#    git -C wine describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/^wine.//;s/^v//;s/\.rc/rc/'
#}

build() {
    ## workaround for FS#55128
    ## https://bugs.archlinux.org/task/55128
    ## https://bugs.winehq.org/show_bug.cgi?id=43530
    
    ## UPDATE: Bug was caused by Nvidia drivers below 415.XX - this fix is no longer necessary
    #export CFLAGS="${CFLAGS/-fno-plt/}"
    #export LDFLAGS="${LDFLAGS/,-z,now/}"
    
    ## Prevents packages (such as cuda) from interjecting their own packaged compiler(s) (for whatever reason[s] they do so) into our process, which should not use theirs
    ## Credit goes to https://stackoverflow.com/a/370192
    export PATH=$(echo ${PATH} | awk -v RS=: -v ORS=: '/cuda/ {next} {print}' | sed 's/:*$//')
    
    
    ## Configure and use this if you want a build tuned to your CPU architecture - set this HERE if compiling with GCC
    ## WARNING: USING THIS IMPROPERLY WILL CAUSE WINE NOT TO RUN ON YOUR MACHINE
    #export CFLAGS+=" -march= -mtune="
    
    export CFLAGS+=" -std=gnu89"
    export CFLAGS="${CFLAGS/-Wall/}"
    
    # -O3 optimization because we can :p
    export CFLAGS+=" -O3"
    export LDFLAGS="-Wl,-O3,--sort-common,--as-needed,-z,relro,-z,now"
    
    export CXXFLAGS="${CFLAGS}"
    export CXXFLAGS="${CXXFLAGS} -Wp,-D_GLIBCXX_ASSERTIONS"
    
    export CROSSCFLAGS="${CFLAGS}"
    export CROSSCXXFLAGS="${CXXFLAGS}"
    export CROSSLDFLAGS="${LDFLAGS}"

    if [ "$CC" = 'clang' ] && [ "$CXX" = 'clang++' ] || [ "$CC" = 'clang' ] || [ "$CXX" = 'clang++' ]; then
        export CC=clang
        export CXX=clang++
        export OBJC=""
        export LD=""
        export AR=""
        export NM=""
        export AS=""
        export RANLIB=""
        export STRIP=""
        export OBJCOPY=""
        export DEBUG_CFLAGS="-g"
        export DEBUG_CXXFLAGS="-g"
        
        ## Re-setting these because Clang builds (for at least 7.0) need more sparse CFLAGS and LDFLAGS
        export CFLAGS="-O3 -pipe -std=gnu89"
        export CPPFLAGS="-D_FORTIFY_SOURCE=2"
        
        ## Configure and use this if you want a build tuned to your CPU architecture - this has to be set HERE if doing a Clang build
        ## WARNING: USING THIS IMPROPERLY WILL CAUSE WINE NOT TO RUN ON YOUR MACHINE
        export CFLAGS+=" -march=znver2 -mtune=znver2"
        
        export CXXFLAGS="${CFLAGS}"
        export CXXFLAGS="${CXXFLAGS} -Wp,-D_GLIBCXX_ASSERTIONS"
        
        export CROSSCFLAGS="${CFLAGS}"
        export CROSSCXXFLAGS="${CXXFLAGS}"
        
        ## Clang + mingw builds using ld don't seem to accept relro as an arguement and using lld instead with mingw builds causes compilation to fail
        ## Using mingw because using pure clang (for at least 7.0) produces unbootable Wine builds
        export LDFLAGS="-Wl,-O3,--sort-common,--as-needed"
        export CROSSLDFLAGS="${LDFLAGS}"
        
        # build wine 64-bit
        # (according to the wine wiki, this 64-bit/32-bit building order is mandatory)
        printf '%s\n' '  -> Building wine-64...'
        cd build-64
        ../wine/configure \
            --prefix='/usr' \
            --libdir='/usr/lib' \
            --with-x \
            --with-gstreamer \
            --enable-win64
        make
        
        ## Wine for i386 (32-bit) doesn't support the no-plt flag
        export CFLAGS="${CFLAGS/-fno-plt/}"
        export CXXFLAGS="${CXXFLAGS/-fno-plt/}"
        export CROSSCFLAGS="${CFLAGS}"
        export CROSSCXXFLAGS="${CXXFLAGS}"
        
        # build wine 32-bit
        printf '%s\n' '  -> Building wine-32...'
        cd "${srcdir}/build-32"
        export PKG_CONFIG_PATH='/usr/lib32/pkgconfig'
        ../wine/configure \
            --prefix='/usr' \
            --libdir='/usr/lib32' \
            --with-x \
            --with-gstreamer \
            --with-wine64="${srcdir}/build-64"
        make
    
    else
    
        export CC=gcc
        export CXX=g++
        export OBJC=""
        export LD=""
        export AR=""
        export NM=""
        export AS=""
        export RANLIB=""
        export STRIP=""
        export OBJCOPY=""
        # Reset debug flags to makepkg.conf defaults, in case Clang is globally set
        export DEBUG_CFLAGS="-g -fvar-tracking-assignments"
        export DEBUG_CXXFLAGS="-g -fvar-tracking-assignments"
        
        # build wine 64-bit
        # (according to the wine wiki, this 64-bit/32-bit building order is mandatory)
        printf '%s\n' '  -> Building wine-64...'
        cd build-64
        ../wine/configure \
            --prefix='/usr' \
            --libdir='/usr/lib' \
            --with-x \
            --with-gstreamer \
            --without-mingw \
            --enable-win64
        make
        
        ## Wine for i386 (32-bit) doesn't support the no-plt flag
        export CFLAGS="${CFLAGS/-fno-plt/}"
        export CXXFLAGS="${CXXFLAGS/-fno-plt/}"
        export CROSSCFLAGS="$CFLAGS"
        export CROSSCXXFLAGS="$CXXFLAGS"
        
        # build wine 32-bit
        printf '%s\n' '  -> Building wine-32...'
        cd "${srcdir}/build-32"
        export PKG_CONFIG_PATH='/usr/lib32/pkgconfig'
        ../wine/configure \
            --prefix='/usr' \
            --libdir='/usr/lib32' \
            --with-x \
            --with-gstreamer \
            --without-mingw \
            --with-wine64="${srcdir}/build-64"
        make
    fi
    
}

package() {
    # package wine 32-bit
    # (according to the wine wiki, this reverse 32-bit/64-bit packaging order is important)
    printf '%s\n' '  -> Packaging wine-32...'
    cd build-32
    make prefix="${pkgdir}/usr" \
         libdir="${pkgdir}/usr/lib32" \
         dlldir="${pkgdir}/usr/lib32/wine" \
         install
    
    # package wine 64-bit
    printf '%s\n' '  -> Packaging wine-64...'
    cd "${srcdir}/build-64"
    make prefix="${pkgdir}/usr" \
         libdir="${pkgdir}/usr/lib" \
         dlldir="${pkgdir}/usr/lib/wine" \
         install
    
    # font aliasing settings for win32 applications
    install -d -m755 "${pkgdir}/usr/share/fontconfig/conf.default"
    install -D -m644 "${srcdir}/30-win32-aliases.conf" -t "${pkgdir}/usr/share/fontconfig/conf.avail"
    ln -s ../conf.avail/30-win32-aliases.conf "${pkgdir}/usr/share/fontconfig/conf.default/30-win32-aliases.conf"
    
    # wine binfmt
    install -D -m644 "${srcdir}/wine-binfmt.conf" "${pkgdir}/usr/lib/binfmt.d/wine.conf"
    
    # strip native PE libraries
    if [ "$CC" = 'clang' ] || [ "$CXX" = 'clang++' ]; then
        i686-w64-mingw32-strip --strip-unneeded "${pkgdir}/usr/lib32/wine/i386-windows"/*.dll
        x86_64-w64-mingw32-strip --strip-unneeded "${pkgdir}/usr/lib/wine/x86_64-windows"/*.dll
        #llvm-strip --strip-unneeded "${pkgdir}/usr/lib32/wine/i386-windows"/*.dll
        #llvm-strip --strip-unneeded "${pkgdir}/usr/lib/wine/x86_64-windows"/*.dll
    else
        strip --strip-unneeded "${pkgdir}/usr/lib32/wine/i386-windows"/*.dll
        strip --strip-unneeded "${pkgdir}/usr/lib/wine/x86_64-windows"/*.dll
    fi
}

Offline

#6 2022-01-24 03:03:22

N3k0-san
Member
From: Elsweyr
Registered: 2021-08-14
Posts: 67

Re: Compiling Wine with Clang and LLVM

And this was a result of the build with -march=x86-64 -mtune=generic build:

neko-san@ARCH ~> winecfg
wine: Unhandled page fault on execute access to 00007EFC00000000 at address 00007EFC00000000 (thread 0070), starting debugger...
0078:err:wineusb:event_thread_proc Error handling events: System call interrupted (perhaps due to signal)
0078:err:wineusb:event_thread_proc Error handling events: System call interrupted (perhaps due to signal)
0070:err:seh:call_stack_handlers invalid frame 0000000000A20DB0 (0000000000922000-0000000000A20000)
003c:err:service:process_send_command service protocol error - failed to read pipe r = 0  count = 0!
003c:fixme:service:scmdatabase_autostart_services Auto-start service L"winebus" failed to start: 1053
0080:fixme:imm:ImeSetActiveContext (0x17bd20, 0): stub
0080:fixme:imm:ImmReleaseContext (0000000000010020, 000000000017BD20): stub
002c:fixme:imm:ImeSetActiveContext (0x180d40, 1): stub
002c:fixme:imm:ImmReleaseContext (000000000001004E, 0000000000180D40): stub
wine: configuration in L"/home/neko-san/.wine" has been updated.
014c:fixme:imm:ImeSetActiveContext (0x27f630, 1): stub
014c:fixme:imm:ImmReleaseContext (0000000000050054, 000000000027F630): stub

It ran but something's definitely wrong (the errors don't happen with a GCC build).
I'll try again with the no-mingw build next.

Last edited by N3k0-san (2022-01-24 03:06:50)

Offline

#7 2022-01-24 03:13:08

loqs
Member
Registered: 2014-03-06
Posts: 17,364

Re: Compiling Wine with Clang and LLVM

makedepends=('git' 'autoconf' 'bison' 'perl' 'fontforge' 'flex' 'mingw-w64-gcc' 'tar' 'clang' 'llvm' 'lld' 'lib32-llvm' 'lib32-clang'

'autoconf' 'bison' 'flex' are in base-devel.  'tar' is a dependancy of libtool is which also in base-devel.

    tar xvf ${pkgname}-${_pkgver}.tar.gz

???

    if [ "$CC" = 'clang' ] && [ "$CXX" = 'clang++' ] || [ "$CC" = 'clang' ] || [ "$CXX" = 'clang++' ]; then

Redundant first test.

You can avoid having the build in both parts of the if by assigning the configure arguments to a variable then add or subtract from it in the if else block.

        # Reset debug flags to makepkg.conf defaults, in case Clang is globally set
        export DEBUG_CFLAGS="-g -fvar-tracking-assignments"
        export DEBUG_CXXFLAGS="-g -fvar-tracking-assignments"

???

Offline

#8 2022-01-24 03:24:05

N3k0-san
Member
From: Elsweyr
Registered: 2021-08-14
Posts: 67

Re: Compiling Wine with Clang and LLVM

And this is the result of the no-mingw / pure clang build (which apparently still can't run winecfg and also throws errors to the shell there - which didn't happen to me with the znver2 version of this build):

neko-san@ARCH ~> winecfg
002c:err:seh:call_stack_handlers invalid frame 0000000067FE0020 (0000000000022000-0000000000220000)
002c:err:seh:NtRaiseException Exception frame is not in stack limits => unable to dispatch exception.
0034:err:virtual:virtual_setup_exception stack overflow 1104 bytes in thread 0034 addr 0x170052b38 stack 0x20bb0 (0x20000-0x21000-0x220000)
0044:err:seh:call_stack_handlers invalid frame 0000000067FE0020 (0000000000022000-0000000000220000)
0044:err:seh:NtRaiseException Exception frame is not in stack limits => unable to dispatch exception.
004c:err:seh:call_stack_handlers invalid frame 0000000067FE0020 (0000000000022000-0000000000220000)
004c:err:seh:NtRaiseException Exception frame is not in stack limits => unable to dispatch exception.
neko-san@ARCH ~ [5]> 

(The znver2 version of this just silently exited for me, as long as I refrain from using certain flags; otherwise it would additionally throw stack overflow errors)

Last edited by N3k0-san (2022-01-24 03:25:39)

Offline

#9 2022-01-24 03:28:17

N3k0-san
Member
From: Elsweyr
Registered: 2021-08-14
Posts: 67

Re: Compiling Wine with Clang and LLVM

loqs wrote:
makedepends=('git' 'autoconf' 'bison' 'perl' 'fontforge' 'flex' 'mingw-w64-gcc' 'tar' 'clang' 'llvm' 'lld' 'lib32-llvm' 'lib32-clang'

'autoconf' 'bison' 'flex' are in base-devel.  'tar' is a dependancy of libtool is which also in base-devel.

    tar xvf ${pkgname}-${_pkgver}.tar.gz

???

    if [ "$CC" = 'clang' ] && [ "$CXX" = 'clang++' ] || [ "$CC" = 'clang' ] || [ "$CXX" = 'clang++' ]; then

https://bbs.archlinux.org/post.php?tid=273313&qid=2017797
Redundant first test.

You can avoid having the build in both parts of the if by assigning the configure arguments to a variable then add or subtract from it in the if else block.

        # Reset debug flags to makepkg.conf defaults, in case Clang is globally set
        export DEBUG_CFLAGS="-g -fvar-tracking-assignments"
        export DEBUG_CXXFLAGS="-g -fvar-tracking-assignments"

???

Whether or not specific checks are redundant is entirely besides the point and entirely off-topic
@Loqs , if you don't understand why I set those specific GCC debug flags, it's because those are the default for makepkg and -fvar-tracking-assignments isn't a valid Clang debug flag

Last edited by N3k0-san (2022-01-24 03:30:12)

Offline

#10 2022-01-24 04:11:21

loqs
Member
Registered: 2014-03-06
Posts: 17,364

Re: Compiling Wine with Clang and LLVM

What is going to use DEBUG_CFLAGS or DEBUG_CXXFLAGS in the build function?

The debug flags are already added to CFLAGS and CXXFLAGS by makepkg.

        export CFLAGS="-O3 -pipe -std=gnu89"
        export CPPFLAGS="-D_FORTIFY_SOURCE=2"

You already ensure -fvar-tracking-assignments will not be passed to clang with the above.

    # -O3 optimization because we can :p

Really does sum it up.  You do it because you can irrespective of if it is required or makes the PKGBUILD harder for others to parse.

Offline

#11 2022-01-24 04:28:58

N3k0-san
Member
From: Elsweyr
Registered: 2021-08-14
Posts: 67

Re: Compiling Wine with Clang and LLVM

loqs wrote:

What is going to use DEBUG_CFLAGS or DEBUG_CXXFLAGS in the build function?

The debug flags are already added to CFLAGS and CXXFLAGS by makepkg.

        export CFLAGS="-O3 -pipe -std=gnu89"
        export CPPFLAGS="-D_FORTIFY_SOURCE=2"

You already ensure -fvar-tracking-assignments will not be passed to clang with the above.

    # -O3 optimization because we can :p

Really does sum it up.  You do it because you can irrespective of if it is required or makes the PKGBUILD harder for others to parse.

The PKGBUILD isn't hard to understand; you're making this a big deal when it isn't at all.
First of all, what you pointed out for the debug flags is irrelevant to the clang if-check; there's no reason to even be bringing this up.
Second, I already mentioned this but: pay attention to the if-checks.
Third, there isn't a reason to complain about the optimization level flag used; it's completely irrelevant to the entirety of this conversation.

At this point I'm almost convinced you're trolling.

Last edited by N3k0-san (2022-01-24 04:36:50)

Offline

Board footer

Powered by FluxBB