Last active
January 2, 2022 07:35
-
-
Save pojntfx/166c1976935dd05b9919888eac8eab93 to your computer and use it in GitHub Desktop.
Install GTK3/GTK4 in MSYS2 on WINE on Linux to Cross-Compile to Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Be sure to run in a fresh WINEPREFIX! | |
# Install native dependencies | |
dnf update -y | |
dnf install -y curl wine | |
# Install MSYS2 | |
curl -L -o /tmp/msys2.exe 'https://github.com/msys2/msys2-installer/releases/download/2021-11-30/msys2-base-x86_64-20211130.sfx.exe' | |
wine64 /tmp/msys2.exe x -y -oC:/ | |
# Fix MSYS2 | |
sed -i ~/.wine/drive_c/msys64/etc/pacman.conf -e 's/SigLevel = Required/SigLevel = Never/g' | |
cat /etc/pki/tls/certs/ca-bundle.crt >~/.wine/drive_c/msys64/usr/ssl/certs/ca-bundle.crt | |
cat /etc/pki/tls/certs/ca-bundle.trust.crt >~/.wine/drive_c/msys64/usr/ssl/certs/ca-bundle.trust.crt | |
export WINEPATH='c:\msys64\usr\bin' | |
# Install GCC, Go and GTK | |
rm -f ~/.wine/drive_c/msys64/var/lib/pacman/db.lck | |
wine64 bash.exe -c 'pacman --verbose --debug --noconfirm --ignore pacman --needed -S mingw-w64-x86_64-gcc mingw-w64-x86_64-go mingw-w64-x86_64-pkg-config mingw-w64-x86_64-gtk4 mingw-w64-x86_64-gtk3 mingw-w64-x86_64-gobject-introspection mingw-w64-x86_64-gobject-introspection-runtime mingw-w64-x86_64-glib2' | |
sed -i ~/.wine/drive_c/msys64/mingw64/lib/pkgconfig/* -e 's/-Wl,-luuid/-luuid/g' # See https://github.com/gotk3/gotk3/wiki/Installing-on-Windows#chocolatey, fails with invalid flag in pkg-config --libs: -Wl,-luuid otherwise | |
# GTK3 (gotk3) | |
# Build | |
git clone https://github.com/gotk3/gotk3-examples.git /tmp/gotk3-examples | |
cd /tmp/gotk3-examples/ || exit | |
go mod init github.com/gotk3/gotk3-examples | |
wine64 bash.exe -c 'export PATH="$PATH:/mingw64/bin" && export GOPATH="/c/users/root/go" && export GOROOT="/mingw64/lib/go" && export GOARCH=amd64 && go get -v -x github.com/gotk3/gotk3/gtk/...@latest' | |
wine64 bash.exe -c 'export PATH="$PATH:/mingw64/bin" && export GOPATH="/c/users/root/go" && export GOROOT="/mingw64/lib/go" && export GOARCH=amd64 && go build -x -v -o out/gtk3-simple.exe ./gtk-examples/simple' | |
# Package (you can distribute the resulting .zip) | |
cp ~/.wine/drive_c/msys64/mingw64/bin/{libwinpthread-1.dll,libpcre-1.dll,libiconv-2.dll,libintl-8.dll,libglib-2.0-0.dll,libcairo-gobject-2.dll,libffi-7.dll,libgobject-2.0-0.dll,libgcc_s_seh-1.dll,libcairo-2.dll,libfontconfig-1.dll,libexpat-1.dll,libfreetype-6.dll,libpixman-1-0.dll,libpng16-16.dll,zlib1.dll,libgdk-3-0.dll,libepoxy-0.dll,libfribidi-0.dll,libgio-2.0-0.dll,libgmodule-2.0-0.dll,libgdk_pixbuf-2.0-0.dll,libpango-1.0-0.dll,libharfbuzz-0.dll,libthai-0.dll,libpangocairo-1.0-0.dll,libpangoft2-1.0-0.dll,libpangowin32-1.0-0.dll,libatk-1.0-0.dll,libgtk-3-0.dll,libbz2-1.dll,libbrotlidec.dll,libstdc++-6.dll,libgraphite2.dll,libdatrie-1.dll,libbrotlicommon.dll} out | |
cd out || exit | |
zip -FSr ../gtk3-simple.exe.zip . | |
# Run | |
WINEPATH="${PWD}" wine64 ./gtk3-simple.exe # Or try on a real Windows machine if it doesn't work here | |
# GTK3 & GTK4 (gotk4) | |
# Copy source code to directory on C drive | |
rm -rf ~/.wine/drive_c/users/root/Documents/gotk4-examples | |
mkdir -p ~/.wine/drive_c/users/root/Documents/gotk4-examples | |
git clone https://github.com/diamondburned/gotk4-examples.git ~/.wine/drive_c/users/root/Documents/gotk4-examples | |
mkdir -p ~/.wine/drive_c/users/root/go | |
# Build | |
# For GTK4 | |
wine64 bash.exe -c 'export PATH="$PATH:/mingw64/bin" && export GOPATH="/c/users/root/go" && export GOROOT="/mingw64/lib/go" && export GOARCH=amd64 && rm go.* && go mod init github.com/diamondburned/gotk4-examples && cd /c/users/root/Documents/gotk4-examples && go get -v -x github.com/diamondburned/gotk4/pkg/gtk/v4@bab1b33bc5950af05801ea710e17470192b9c058' | |
wine64 bash.exe -c 'export PATH="$PATH:/mingw64/bin" && export GOPATH="/c/users/root/go" && export GOROOT="/mingw64/lib/go" && export GOARCH=amd64 && cd /c/users/root/Documents/gotk4-examples && go build -ldflags="-extld=clang -linkmode=external" -x -v -o out/gtk4-simple.exe ./gtk4/simple' | |
# For GTK3 (this does not work yet, see https://github.com/diamondburned/gotk4/issues/43) | |
wine64 bash.exe -c 'export PATH="$PATH:/mingw64/bin" && export GOPATH="/c/users/root/go" && export GOROOT="/mingw64/lib/go" && export GOARCH=amd64 && rm go.* && go mod init github.com/diamondburned/gotk4-examples && cd /c/users/root/Documents/gotk4-examples && go get -v -x github.com/diamondburned/gotk4/pkg/gtk/v3@bab1b33bc5950af05801ea710e17470192b9c058' | |
wine64 bash.exe -c 'export PATH="$PATH:/mingw64/bin" && export GOPATH="/c/users/root/go" && export GOROOT="/mingw64/lib/go" && export GOARCH=amd64 && cd /c/users/root/Documents/gotk4-examples && go build -ldflags="-extld=clang -linkmode=external" -x -v -o out/gtk3-simple.exe ./gtk3/simple' | |
# Copy binaries to staging directory | |
mkdir -p out | |
yes | cp -f ~/.wine/drive_c/users/root/Documents/gotk4-examples/out/* out | |
# Package (you can distribute the resulting .zip) | |
# For GTK4 | |
cp ~/.wine/drive_c/msys64/mingw64/bin/{libwinpthread-1.dll,libpcre-1.dll,libiconv-2.dll,libintl-8.dll,libglib-2.0-0.dll,libcairo-gobject-2.dll,libffi-7.dll,libgobject-2.0-0.dll,libgcc_s_seh-1.dll,libcairo-2.dll,libfontconfig-1.dll,libexpat-1.dll,libfreetype-6.dll,libpixman-1-0.dll,libpng16-16.dll,zlib1.dll,libepoxy-0.dll,libfribidi-0.dll,libgio-2.0-0.dll,libgmodule-2.0-0.dll,libgdk_pixbuf-2.0-0.dll,libpango-1.0-0.dll,libharfbuzz-0.dll,libthai-0.dll,libpangocairo-1.0-0.dll,libpangoft2-1.0-0.dll,libpangowin32-1.0-0.dll,libatk-1.0-0.dll,libbz2-1.dll,libbrotlidec.dll,libstdc++-6.dll,libgraphite2.dll,libdatrie-1.dll,libbrotlicommon.dll,liblzo2-2.dll,libcairo-script-interpreter-2.dll,libvulkan-1.dll,libgraphene-1.0-0.dll,libgtk-4-1.dll} out | |
cp out/libvulkan-1.dll out/vulkan-1.dll | |
cd out || exit | |
zip -FSr ../gtk4-simple.exe.zip . | |
# For GTK3 | |
cp ~/.wine/drive_c/msys64/mingw64/bin/{libwinpthread-1.dll,libpcre-1.dll,libiconv-2.dll,libintl-8.dll,libglib-2.0-0.dll,libcairo-gobject-2.dll,libffi-7.dll,libgobject-2.0-0.dll,libgcc_s_seh-1.dll,libcairo-2.dll,libfontconfig-1.dll,libexpat-1.dll,libfreetype-6.dll,libpixman-1-0.dll,libpng16-16.dll,zlib1.dll,libgdk-3-0.dll,libepoxy-0.dll,libfribidi-0.dll,libgio-2.0-0.dll,libgmodule-2.0-0.dll,libgdk_pixbuf-2.0-0.dll,libpango-1.0-0.dll,libharfbuzz-0.dll,libthai-0.dll,libpangocairo-1.0-0.dll,libpangoft2-1.0-0.dll,libpangowin32-1.0-0.dll,libatk-1.0-0.dll,libgtk-3-0.dll,libbz2-1.dll,libbrotlidec.dll,libstdc++-6.dll,libgraphite2.dll,libdatrie-1.dll,libbrotlicommon.dll} out | |
cd out || exit | |
zip -FSr ../gtk3-simple.exe.zip . | |
# Run | |
# For GTK4 | |
WINEPATH="${PWD}" wine64 /gtk4-simple.exe # Or try on a real Windows machine if it doesn't work here | |
# For GTK3 | |
WINEPATH="${PWD}" wine64 ./gtk3-simple.exe # Or try on a real Windows machine if it doesn't work here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment