Roberto Leinardi
01/24/2025, 2:16 PMkotlin
block:
import org.gradle.internal.os.OperatingSystem
kotlin {
val hostOs = OperatingSystem.current()
val hostArch = System.getProperty("os.arch")
val isArm64 = hostArch == "aarch64"
when {
hostOs.isLinux && !isArm64 -> linuxX64()
hostOs.isMacOsX && isArm64 -> macosArm64()
else -> throw GradleException("Host OS '${hostOs}' is not supported by this project.")
}
}
I’ve tried the following so far:
1. Built the artifacts on Linux and published them to MavenLocal. The Linux bindings work fine when consumed.
2. Did the same for macOS (built on macOS and published to MavenLocal), and it also works fine on macOS.
3. Merged the artifacts by copying the macOS ones into the same directory as the Linux ones and overwriting the *.module
and *.pom
files. However, this breaks the Linux target when I try to consume it:
Could not resolve all files for configuration ':linuxX64CompileKlibraries'.
Could not resolve org.gtkkn:gtk4:0.0.1-SNAPSHOT.
No matching variant of org.gtkkn:gtk4:0.0.1-SNAPSHOT was found.
...
From what I understand, the problem arises because the *.module
file gets overwritten, and it no longer includes the linuxX64
variant when the macOS artifacts are added. This makes me worried that the same issue will occur if I publish to MavenCentral without resolving this.
Does anyone have experience with this kind of multiplatform publishing? Is there a way to merge or aggregate the *.module
metadata from the builds on Linux and macOS? Or should I take a different approach entirely?
Thanks in advance for any advice or insights!Roberto Leinardi
01/24/2025, 6:17 PMkotlin
block (e.g., linuxX64
and macosArm64
) simultaneously, instead of dynamically enabling one target based on the host OS.
Issues with Multiple Targets
1. CInterop Definitions Conflict:
• When enabling multiple targets, the nativeMain
source set no longer builds. This happens because cinterop .def
files are managed per specific target.
2. CInterop Commonization:
• Enabling kotlin.mpp.enableCInteropCommonization=true
results in missing native functions on Linux. For example, functions like g_module_build_path
and g_module_close
are no longer available in the generated bindings.
• I suspect this happen because Kotlin/Native parses headers in a "common" environment for all platforms. Platform-specific macros or conditional #ifdef
blocks (e.g., in gmodule.h
) might exclude these functions.
3. Why Duplicating Bindings Doesn’t Work:
• Moving away from nativeMain
and duplicating bindings for each target is not feasible due to the complexity of the library.
• A lot of shared code in nativeMain
depends on native functions (e.g., g_free
and g_type_interfaces
).
• It also uses type aliases (e.g., GType
) and generated bindings classes (e.g., GLib
and GObject
).
If I move away from nativeMain
, I would need to duplicate all this code for each platform, which is not maintainable.
What are my options for handling this scenario?ephemient
01/28/2025, 10:52 AM• I suspect this happen because Kotlin/Native parses headers in a "common" environment for all platforms.I suspect it's more likely that you don't have macos headers available on the linux runner, while the macos runner has the linux sysroot headers available
Roberto Leinardi
01/28/2025, 11:32 AMg_module_build_path
and g_module_close
are available on Linux, and they are found if I target only linux, why the missing macos headers would remove these 2 but not others from the same gmodule library?ephemient
01/28/2025, 11:33 AMRoberto Leinardi
01/28/2025, 11:40 AMRoberto Leinardi
01/28/2025, 11:43 AMRoberto Leinardi
01/28/2025, 11:44 AMephemient
01/28/2025, 11:50 AMephemient
01/28/2025, 11:51 AMRoberto Leinardi
01/28/2025, 11:56 AMephemient
01/28/2025, 11:58 AMBruno Medeiros
02/01/2025, 3:26 AMRoberto Leinardi
02/01/2025, 1:01 PM.gir
files. gtk-kt readme actively redirects to gtk-kn:
> NOTE It is suggested to look at gtk-kn a possible successor project.
https://gitlab.com/gtk-kt/gtk-kt#gtk-ktBruno Medeiros
02/01/2025, 1:06 PMRoberto Leinardi
02/01/2025, 1:11 PMRoberto Leinardi
02/02/2025, 4:17 PM-metadata.jar
file (e.g., adwaita-macosarm64-0.0.3a-SNAPSHOT-metadata.jar
), which is completely empty except for the META-INF directory. This file seems to be breaking IDEA’s dependency resolution: if I manually delete it, the IDE correctly recognizes the library again.
I've tried:
• Removing the metadata
publication from publishing.publications
• Disabling tasks that publish metadata
Both approaches result in Gradle failing during the publication process.
To publish the artifacts I'm specifically calling the task for macOS, and not the generic umbrella task: publishMacosArm64PublicationToMavenLocal
Do you have any advice on how to properly prevent this empty -metadata.jar
from being generated? Also, where would be the best place to report this as a bug?