Hi everyone, I’m trying to get `libui` working wit...
# kotlin-native
u
Hi everyone, I’m trying to get
libui
working with Kotlin Native. I forked an existing project of @Dominaezzz , but it was using an older Kotlin version (1.7.20). I managed to update it to Kotlin 1.9.10, but moving to Kotlin 1.9.20 causes binding errors. There’s also an attempt to create a Compose-based version, which worked fine with Kotlin 1.7.20, but now crashes after the update. I’ve documented the issues and opened GitHub issues here: https://github.com/kdroidFilter/kotlin-libui-compose/issues Would anyone be willing to help or share ideas to resolve these issues? 🙏🏻 Thank you so much!
👀 2
t
I am using libui-ng on windows, macos, and linux. Building like this:
Copy code
meson setup build --default-library=static --buildtype=release -Db_ndebug=true
ninja -C build
I am using static linking for my project My def file looks like this
Copy code
package = libui
headers = ui.h
headers.mingw = windows.h ui_windows.h
headerFilter = ui.h ui_windows.h
noStringConversion = uiFreeInitError

linkerOpts.osx = -lobjc -framework Foundation -framework AppKit

linkerOpts.linux = -L/usr/lib/x86_64-linux-gnu -L/usr/lib64 -L/usr/lib \
    -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 \
    -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0 -lm -ldl

linkerOpts.mingw = -luser32 -lkernel32 -lgdi32 -lcomctl32 -luxtheme \
    -lmsimg32 -lcomdlg32 -ld2d1 -ldwrite -lole32 -loleaut32 -loleacc -luuid -lwindowscodecs

# libraryPaths is set in build.gradle.kts
staticLibraries = build/meson-out/libui.a

---
struct ktAreaHandler {
    uiAreaHandler ui;
    void *ref;
};

struct ktTableHandler {
    uiTableModelHandler ui;
    void *ref;
};

// Avoid types ending up in cnames.structs.* <https://youtrack.jetbrains.com/issue/KT-49034>
typedef struct uiArea {} uiArea;
typedef struct uiWindow {} uiWindow;

#ifdef _WIN32
struct uiWindowForIcon {
	uiWindowsControl c;
	HWND hwnd;
};
#endif
Remember that for mingw you need to run the build script using MINGW64 instead of a normal commandLine, which I am doing like this:
Copy code
commandLine(
            "C:\\msys64\\usr\\bin\\env",
            "MSYSTEM=MINGW64",
            "/usr/bin/bash",
            "-lc",
            "cd ${workingDir.absolutePath.fixPath()} && $cmdWithArgs"
        )


fun String.fixPath(): String {
    return if (isWindows) {
        replace("\\", "/")
            .replace("C:/", "/c/")
            .replace("D:/", "/d/")
    } else {
        this
    }
}
Copy code
cinterops.create("libui") {
                val dir = libuiDir.get().dir("libui-ng-$libuiCommit")
                includeDirs(dir)
                extraOpts("-libraryPath", dir)
            }
Hope this helps you figure out the issue.
Also when changing def file I often need to disable kotlin native caches for it to detect changes