Hi all!
I didn't post anything here for a long time - didn't had much time for nim. But I was recently able to create a tauri app using nim code in the backend and I just wanted to share it with you. I needed to use python, a tauri python plugin and nimterop to finally get what I wanted. The main downside is that you would need to export all exposed Nim functions to python via nimpy.
I'm still kind of new to tauri, so there are probably steps that could be performed easier.
Steps that were performed:
Then, I started with the nim part:
import nimporter
import nimtest
print(nimtest.greet("Nim started")) # just to be sure that nim works fine
import nimpy
proc greet(name: string): string {.exportpy.} =
return "Hello, " & name & "!"
tauri.python.registerFunction("greet_python", 1); to
tauri.python.registerFunction("nimtest.greet", -1, "greet_python");
To make it look nicer, I could also have changed all greet_python to greet_nim and rename the python button to "nim", but it wouldn't be necessary to just run it like this.
And in the end: I could click on the "Python" button and got a nice greeting from Nim. Changing the .nim file also automatically restarted the Tauri application with the new code. I only tested it on MacOS and Windows, but it should also work fine on Linux. It will probably not work on Android / IOS yet.
Thx for reading, I wish you all happy Xmas and a happy new year :)
Disclaimer: I'm the author of tauri_plugin_python
Yap - if it would just be nim, I probably would have used the FFI of rust. Maybe export nim as clib. This would be less overhead, less unnecessary dependency and a far better end result.
My first goal was just not to use nim but python. It was just a nice side effect that I could immediately use nim with nimterop without rewriting any of the rust code. I know - this is not the best possible solution for nim. But I just wanted to share this as the solution was pretty simple and already available. Maybe someone likes this, has time and will make a native nim plugin for tauri.