HolyBlackCat / quasi-msys2

Cross-compile C/C++ from Linux to Windows using MSYS2 packages
zlib License
94 stars 4 forks source link

Setup a GEGL plugin cross compilation workflow with quasi-mysys2 #17

Closed LinuxBeaver closed 5 days ago

LinuxBeaver commented 1 week ago

I have meson and ninja, where do I begin for GEGL? https://packages.msys2.org/base/mingw-w64-gegl

LinuxBeaver commented 1 week ago

Normally GEGL is compiled via

meson setup --buildtype=release build && ninja -C build then ninja install but how do I get it to compile within quasi-mysys2 UCRT64

LinuxBeaver commented 1 week ago

`contrast@cosmos UCRT64 ~/Desktop/quasi-msys2-master/gegl $ meson setup --buildtype=release build && ninja -C build The Meson build system Version: 1.3.2 Source dir: /home/contrast/Desktop/quasi-msys2-master/gegl Build dir: /home/contrast/Desktop/quasi-msys2-master/gegl/build Build type: native build Project name: gegl Project version: 0.4.49

`

It just gets stuck here indefinitely

HolyBlackCat commented 1 week ago

First, I'm assuming you don't want a prebuilt gegl, and want to build from source? There's a package with a prebuilt one.

I tried a few things and couldn't get it to compile. But I'm not too familiar with meson, and I didn't spend too much time on this.

But in my attempts it never hang. Make sure your Wine is working, because it might try to run some test executables in it during configration.

Try both native linux meson and the one installed in quasi-msys2. Native meson might need a toolchain file: https://mesonbuild.com/Cross-compilation.html

LinuxBeaver commented 1 week ago

I can go for prebuilt GEGL that is ok. How do I install prebuilt GEGL?

pacmake install gegl pacmake install mingw-w64-gegl

LinuxBeaver commented 1 week ago

I got it with pacmake install _gegl

I did not gues the _, I found it looking at other questions here.

LinuxBeaver commented 1 week ago

I renamed this thread to my ultimate goal. To Cross compile GEGL .dll files on Linux without the need for a Windows 10 virtual box. I installed GEGL successfully, and I go to compile but get this error

`Build dir: Z:/home/contrast/ExternalCodeApps/quasi-msys2-master/GEGL-GIMP-PLUGIN_Pixel_Text/build Build type: native build Project name: pixel_text Project version: 0.1 0124:fixme:file:server_get_file_info Unsupported info class e 0124:fixme:file:server_get_file_info Unsupported info class e

meson.build:1:0: ERROR: Unknown compiler(s): [['win-clang']] The following exception(s) were encountered: Running win-clang --version gave "[WinError 2] File not found"

A full log can be found at Z:/home/contrast/ExternalCodeApps/quasi-msys2-master/GEGL-GIMP-PLUGIN_Pixel_Text/build/meson-logs/meson-log.txt `

I tried installing clang and that did not solve it. No win-clang winclang package exist.

The goal is to compile my GEGL plugins as .dll's on Linux.

LinuxBeaver commented 1 week ago

I confirmed my systems wine (not flatpak) works by clicking on a 1997 paint shop pro exe file. I never use wine but I confirmed it works.

LinuxBeaver commented 1 week ago

It appears win-clang is installed because win-clang --version works when I run i manually. I ran meson.exe setup --buildtype=release build && ninja.exe -C build inside the correct folder and the GEGL plugin would still not compile and it gives the error .

image

HolyBlackCat commented 1 week ago

Okay, I've added some minimal Meson support, try again with the latest version. Tried compiling your repo, seems to work now. Here's what I did:

git clone https://github.com/holyblackcat/quasi-msys2
cd quasi-msys2

# This step is optional. I'm assuming you want MINGW64 (instead of the default UCRT64)
# from the package names you're using, but consult https://www.msys2.org/docs/environments/ if not.
# Also https://stackoverflow.com/q/76552264/2752075
echo MINGW64 >msystem.txt

make install _gcc _gegl
sudo ln -nfs /path/to/quasi-msys2/root/mingw64 /mingw64
env/shell.sh

cd ..
git clone https://github.com/LinuxBeaver/GEGL-GIMP-PLUGIN_Pixel_Text
cd GEGL-GIMP-PLUGIN_Pixel_Text

meson setup --buildtype=release build && ninja -C build
LinuxBeaver commented 1 week ago

Now it is trying to compile but I still get ../pixel_text.c:35:10: fatal error: 'glib/gi18n-lib.h' file not found

I installed gcc, gegl, ninja, and meson

LinuxBeaver commented 1 week ago

I installed libvirt-glib but the problem still exist.

HolyBlackCat commented 1 week ago

Now it is trying to compile but I still get ../pixel_text.c:35:10: fatal error: 'glib/gi18n-lib.h' file not found

I had this error until I created a symlink in /. When you run env/shell.sh, it warns you to create the symlink if it's missing.

LinuxBeaver commented 1 week ago

I ran sudo ln -nfs /path/to/quasi-msys2/root/mingw64 /mingw64 and the error went away. Now I have a new error

[1/2] Compiling C object pixel_text.dll.p/pixel_text.c.obj FAILED: pixel_text.dll.p/pixel_text.c.obj win-clang -Ipixel_text.dll.p -I. -I.. -I/home/contrast/ExternalCodeApps/quasi-msys2/root/mingw64/mingw64/include/gegl-0.4 -I/home/contrast/ExternalCodeApps/quasi-msys2/root/mingw64/mingw64/include -I/home/contrast/ExternalCodeApps/quasi- msys2/root/mingw64/mingw64/include/gio-win32-2.0 -I/home/contrast/ExternalCodeApps/quasi-msys2/root/mingw64/mingw64/include/json-glib-1.0 -I/home/contrast/ExternalCodeApps/quasi-msys2/root/mingw64/mingw64/include/babl-0.1 -I/home/contras t/ExternalCodeApps/quasi-msys2/root/mingw64/mingw64/include/glib-2.0 -I/home/contrast/ExternalCodeApps/quasi-msys2/root/mingw64/mingw64/lib/glib-2.0/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O3 -DBUIL DING_GEGLFILTER -MD -MQ pixel_text.dll.p/pixel_text.c.obj -MF pixel_text.dll.p/pixel_text.c.obj.d -o pixel_text.dll.p/pixel_text.c.obj -c ../pixel_text.c CreateProcess failed: The system cannot find the file specified. ninja: build stopped: subcommand failed.

CreateProcess failed: The system cannot find the file specified

I assume the file that needs specifying is pixel_text.c and it is present.

HolyBlackCat commented 1 week ago

Uninstall meson and ninja in quasi-msys2, use the native linux ones.

I've also just blacklisted ninja so that it always will prefer the native one even if you install one in quasi-msys2.

LinuxBeaver commented 6 days ago

I ran pacmake remove _ninja and pacmake remove _meson and successfully removed the two packages now it is doing something more confusing, it appears to compile successful but there is no .dll generated in the build folder. Did you make sure it generated a .dll in the build folder?

`Version: 1.3.2 Source dir: /home/contrast/DevelopingGEGL/Final_Filters_here/aura Build dir: /home/contrast/DevelopingGEGL/Final_Filters_here/aura/build Build type: cross build Project name: outerglow Project version: 0.1 C compiler for the host machine: win-clang (clang 17.0.6 "clang version 17.0.6 (Fedora 17.0.6-2.fc39)") C linker for the host machine: win-clang ld.lld 17.0.6 C compiler for the build machine: ccache cc (gcc 14.2.0 "cc.exe (Rev1, Built by MSYS2 project) 14.2.0") C linker for the build machine: cc ld.bfd 2.43.1 Build machine cpu family: x86_64 Build machine cpu: x86_64 Host machine cpu family: x86_64 Host machine cpu: x86_64 Target machine cpu family: x86_64 Target machine cpu: x86_64 Found pkg-config: YES (/usr/bin/pkg-config) 1.9.5 Found CMake: /home/contrast/ExternalCodeApps/quasi-msys2/env/wrappers/cmake (3.30.2) Run-time dependency gegl-0.3 found: NO (tried pkgconfig and cmake) Run-time dependency gegl-0.4 found: YES 0.4.48 Build targets in project: 1

outerglow 0.1

User defined options Cross files: /home/contrast/ExternalCodeApps/quasi-msys2/env/config/meson_cross_file.ini buildtype : release

Found ninja-1.11.1 at /usr/bin/ninja bash: /home/contrast/ExternalCodeApps/quasi-msys2/env/fake_bin/ninja: No such file or directory`

It says no file and directory found for fake ninja. Also its trivial rather the plugin is pixel text or something else. They all compile exactly the same.

LinuxBeaver commented 6 days ago

its suppose to generate a .dll file

image

LinuxBeaver commented 6 days ago

I removed ninja and meson with pacmake remove and when I run

build_plugin_windows.sh `#!/bin/bash

mkdir WindowsBinaries

TOP=$(pwd)

chmod +x build_linux.sh

./build_linux.sh

cp $(find . -name '*.dll') $TOP/WindowsBinaries

build_linux.sh meson setup --buildtype=release build && ninja -C build

I get the previous error.

../outerglow.c:35:10: fatal error: 'glib/gi18n-lib.h' file not found

I am using my system's ninja and meson now and I still get it but only when I call a script with a script.

LinuxBeaver commented 6 days ago

I did a clean install with the version from one hour ago that blacklist ninja. I copied and pasted code on https://github.com/HolyBlackCat/quasi-msys2/issues/17#issuecomment-2336570481 and I still get the 'glib/gi18n-lib.h' file not found and this time the clean install won't let me uninstall meson and ninja because they were never installed.

LinuxBeaver commented 6 days ago

The problem has to do with it not being able to find glib.h I ran a

locate glib.h and only found /usr/x86_64-w64-mingw32/sys-root/mingw/include/jpeglib.h which is unrelated. I read online that installing gtk2 packages and glade would give me glib.h but it failled. It should come with glib2 I don't know why its missing.

HolyBlackCat commented 6 days ago

locate isn't reliable, it uses a database that can get stale. Check with find.

After make install _gegl I do get glib.h:

$ find . -name glib.h
./root/mingw64/include/glib-2.0/glib.h

I do get the .dll after the build too. After the exact commands in this post, I end up with this:

$ ls build
build.ninja  compile_commands.json  meson-info  meson-logs  meson-private  pixel_text.dll  pixel_text.dll.a  pixel_text.dll.p
LinuxBeaver commented 6 days ago

I got the same find result as you.

Here is what happens when I login to shell.sh, maybe something is wrong there

contrast@cosmos:~/ExternalCodeApps/quasi-msys2$ env/shell.sh

--- binfmt.mk
`binfmt_misc` mounted? YES
`binfmt_misc` enabled? YES
Executable format registered? NO
Trying to configure your kernel to transparently run Windows executables using Wine. 
All changes will be undone on a reboot. Ctrl+C to skip.
Running `sudo bash -c 'echo ":DOSWin:M::MZ::/usr/bin/wine:" >/proc/sys/fs/binfmt_misc/register'`.
[sudo] password for contrast: 
Success.
Executable format enabled? YES
Running `sudo -k` to forget the sudo password.

--- fakebin.mk
Nothing to do.

--- vars.src
[WARNING] Didn't find symlink `/mingw64` -> `/home/contrast/ExternalCodeApps/quasi-msys2/root/mingw64`.
It can improve compatibility in some cases. Consider creating it using following command:
    sudo ln -nfs "/home/contrast/ExternalCodeApps/quasi-msys2/root/mingw64" /mingw64

MSYSTEM_PREFIX = /home/contrast/ExternalCodeApps/quasi-msys2/root/mingw64

Guessing a compiler... To override, set `MINGW_CC` and `MINGW_CXX` and restart.
Trying native Clang + LLD...
  Guessed Clang version suffix: WIN_CLANG_VER = NONE
  You can override it by setting it to a number or to `NONE` for no suffix.
Success! Will use wrappers for the native Clang.
WIN_NATIVE_CLANG_CC = clang
WIN_NATIVE_CLANG_CXX = clang++
WIN_CLANG_FLAGS = --target=x86_64-w64-mingw32 --sysroot=/home/contrast/ExternalCodeApps/quasi-msys2/root/mingw64 -fuse-ld=lld -pthread -stdlib=libstdc++ -femulated-tls -rtlib=libgcc -unwindlib=libgcc
CC  = win-clang
CXX = win-clang++ 
HolyBlackCat commented 5 days ago

It says the symlink is missing, and shows a command to create it. Close and restart env/shell.sh after creating it.

LinuxBeaver commented 5 days ago

--- binfmt.mk
`binfmt_misc` mounted? YES
`binfmt_misc` enabled? YES
Executable format registered? YES
Executable format enabled? YES

--- fakebin.mk
Nothing to do.

--- vars.src
Found symlink `/mingw64` -> `/home/contrast/ExternalCodeApps/quasi-msys2/root/mingw64`, will use it.
MSYSTEM_PREFIX = /mingw64

Guessing a compiler... To override, set `MINGW_CC` and `MINGW_CXX` and restart.
Trying native Clang + LLD...
  Guessed Clang version suffix: WIN_CLANG_VER = NONE
  You can override it by setting it to a number or to `NONE` for no suffix.
Success! Will use wrappers for the native Clang.
WIN_NATIVE_CLANG_CC = clang
WIN_NATIVE_CLANG_CXX = clang++
WIN_CLANG_FLAGS = --target=x86_64-w64-mingw32 --sysroot=/mingw64 -fuse-ld=lld -pthread -stdlib=libstdc++ -femulated-tls -rtlib=libgcc -unwindlib=libgcc
CC  = win-clang

I just reran it and for some reason its working now

image

I'm going to do a few more test then close.

LinuxBeaver commented 5 days ago

It wasn't working before because I sudo commanded it after logging into the shell. The trick was to run this first.

sudo ln -nfs "/home/contrast/Applications/quasi-msys2/root/mingw64" /mingw64 && /home/contrast/Applications/quasi-msys2/env/shell.sh and I have it set to a macro winbuild Everything is working and the plugins work on Windows 10.

I am going to close with a big thank you because this saves me 33 gigs of disk space that the Windows 10 virtual box was occupying. I no longer need it. btw I am a GIMP plugin developer so I took a few minutes to make this using my plugins

image

image

https://github.com/LinuxBeaver/Gimp_Layer_Effects_Text_Styler_Plugin_GEGL_Effects/ https://github.com/LinuxBeaver/GEGL-GIMP-PLUGIN_rock_surface