I’m developing a Windows app with Kotlin/Native on macOS, and everything works well, including the linking process. However, my runDebugExecutableMingwX64 task doesn’t do anything, which I assume is running the resulting executable without Wine. Is there any way to launch my program with Wine?
There should be, you can do pretty much anything in Gradle, for better or for worse. Gradle just uses Groovy (or Kotlin) code, so look up how to invoke applications from Java code, then make a custom Gradle task that invokes the Wine executable. From that point, it’s basically just “how do I run Wine via command line and tell it to run a specific executable?”
Yes, I can access the link task via mingwX64().binaries.executable.linkTask
, and make a new task that depends on that link task. But I have to check whether the current host is Windows (because on Windows the executable can run natively). Though that can be easily implemented using APIs like DefaultNativePlatform, I thought that’s what the Kotlin multiplatform plugin should do for the user, and I actually expected some answers in that kind of view. Sorry for the confusing question.
Oh, sorry, I don’t know much about Kotlin Multiplatform. I know roughly what it’s meant to do, but I haven’t used it myself.
I think, if I’m understanding your question… you want to configure your project so that it always builds and runs for Windows, but if you’re not on a Windows OS, it’ll instead try to use Wine? I think that’s probably outside the scope of what the Multiplatform plugin/compiler/whatever does… it just compiles the code down to machine code for the targeted OS, but if you want to run Windows code on Mac, that’s outside the scope of what the Multiplatform plugin does.
When you configure mingwX64() with KMP, the plugin makes two tasks: linkDebugExecutableMingwX64
and runDebugExecutableMingwX64
.
linkDebugExecutableMingwX64
generates the .exe file. runDebugExecutableMingwX64
should run the .exe
file. runDebugExecutableMingwX64
is the task run by the IDE when you click the play button.
Even on macOS, I can run the .exe
file using Wine: wine app.exe
runs the K/N app very well. But when I launch runDebugExecuableMingwX64
via the IDE or the terminal (the ./gradlew
command), it does nothing, which I assume that runDebugExecuableMingwX64
just exec
s the .exe file without checking the current OS, and I think that’s why it seems to do nothing.
So my question was about how I can configure runDebugExecuableMingwX64
via something like gradle properties so it knows that I’m running a Windows app on macOS.