Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: DFHack plugin written in Rust  (Read 1263 times)

Ralpha

  • Bay Watcher
    • View Profile
DFHack plugin written in Rust
« on: May 12, 2020, 09:36:07 am »

A week ago I made a small proof of concept to see if Rust can be used to create a DFHack plugin.
And the short answer is yes, maybe...
You can check it out here: https://github.com/ralpha/DFHack_Rust_plugin
I don't have plans right now to use it, but it is here for the taking if someone want to use it.

Rust has support for C++ binding. It took me some doing to get cmake to handle the build process.
It is not the best implementation and DF values might not be the easiest to export to Rust.
But I'm not so familiar with DFHack and its plugin build system.
If someone could help with the build system that would be cool!
So Rust might not be the right tool to use, but you can if you want.

I'm currently working on another new standalone application (it is a nice tool for legends ;) ) that is written is Rust ❤️.
That should be out in a month I hope. (most of it is working already)
Logged

bloop_bleep

  • Bay Watcher
    • View Profile
Re: DFHack plugin written in Rust
« Reply #1 on: May 12, 2020, 12:11:02 pm »

This is interesting. I will say, since compiled plugins in DFHack are just shared library files that expose plugin_init, plugin_shutdown, and maybe some other functions, you may be able to remove the explicit C++ glue code and compile the Rust plugin to a C shared library directly.
Logged
Quote from: KittyTac
The closest thing Bay12 has to a flamewar is an argument over philosophy that slowly transitioned to an argument about quantum mechanics.
Quote from: thefriendlyhacker
The trick is to only make predictions semi-seriously.  That way, I don't have a 98% failure rate. I have a 98% sarcasm rate.

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: DFHack plugin written in Rust
« Reply #2 on: May 13, 2020, 12:08:51 am »

This is interesting. I will say, since compiled plugins in DFHack are just shared library files that expose plugin_init, plugin_shutdown, and maybe some other functions, you may be able to remove the explicit C++ glue code and compile the Rust plugin to a C shared library directly.

That is not whole truth. Yes you could do a "c" library with few functions but that would be next to useless as all of the structures depend on alignment being the same - i.e. using same compiler and same std libraries. That being said there is a clang version that is C++ ABI compatible with msvc. As for the Rust part i don't know enough to say definitely but you can always experiment, though it will probably be a hard battle against the world. Probably easier to do on linux.

Edit: looked over the plugin - that could also work. Imho let's leave the dfhack core (i.e. the library and plugins) as is - less languages the better - and interface over RPC.
« Last Edit: May 13, 2020, 12:15:07 am by Warmist »
Logged