Rust support

I’m trying to understand in what extend Rust (programming language) can be used for add-ons with the current SDK.

SDK says: Out-of-process add-on components for Microsoft Flight Simulator can be written in C, C++, or, if the managed API calls are being used, any .NET language such as C#.net or VB.net. In-process modules are written in C++ and compiled into WebAssembly modules.

Rust can also be compiled to WebAssembly. So can Rust have full access to the SDK… or C++ is irreplaceable?

In this stream rust is used Rust FFI: Microsoft Flight Simulator SDK Part 1 - YouTube but can this be extended for all SDK features / scenarios?

Based on the Rust advantages of memory safety, thread safety, zero cost abstractions etc over C++. it would be nice to see it used for add-ons (and maybe by Asobo for core components also ?) :slight_smile:

thanks

2 Likes

I have already asked them about rust https://forums.flightsimulator.com/t/rust-language/83072

If you don’t have an access to that topic they said

Although we are not planning to provide an official Rust version of the SDK at this stage, this may be something we will consider later on.

But actually it seems it should be possible to build and run some Rust binaries on top of the low level WASI api. I had some experiments without any luck but the problem was in the unstable WASI in the sim itself (for example sometimes their own WASM built with the c++ did not work), perhaps they have fixed some important things by this moment and everything works well now, I have to check it but I am busy on another task right now.

3 Likes

check out https://github.com/devsnek/msfs-rs :slight_smile:. note that there’s currently a bug in the wasm simconnect api in msfs but the library itself works fine.

5 Likes

very interesting job @devsnek, I’m digging into it :+1:

@devsnek I managed to run msfs examples successfully, great job!

Now I have problems adding up functions and code to your examples
I’m using Log example (Lib version) as a start, but now I’m getting this error in simulator console:

WASM: ERR_VALIDATION_ERROR (-4095 / fffff001)
Cannot have more than 1 table defined.
Table element type is -17: only funcref allowed.

Do you have any idea about this? it seems LLVM .wasm output is not compatible to what inNative is expecting…

@raxter78 could you open a bug on my repo or hit me up in the msfs or a32nx discord (devsnek#0001) so as not to hijack this thread :slight_smile:. also as a side-note, the official sdk is using clang (llvm) as well, although it uses a tool called clang-cl.exe, which is basically clang but it uses msvc-compatible flags so you can drop it into legacy codebases.

Update: previous error was caused by cargo-wasi tool that did unsupported optimizations to .wasm

Now the .wasm seems correctly formed (wasmer can validate it)
BUT simulator simply hangs hogging all the memory before crashing :slight_smile:

Zig support https://ziglang.org/ could also probably be considered. It has less features than Rust but is said to be much easier to learn (like C vs C++). Need A New Programming Language? Try Zig | Hackaday
Zig can compile to WASM Getting Zig compiling to WASM · GitHub

LOL I get the Computer Science enthusiasm (I am a CS researcher) but I’m wondering what gauge is going to be built in Rust or Zig? All the interaction with the sim is via a complex layer of API calls and class libraries in HTML/JS. So whoever thinks Rust or Zig is a good idea for general gauge programming first has to write a huge amount of code to interface to the sim - my guess is this will never be done well and Rust gauges will be limited to the most basic ‘read a variable’ - ‘write a variable’ with neglible UI, which could easily be done in the basic sim.

I’ve just released a SimConnect SDK in Rust that encapsulates the C API fully and optimizes for developer experience. I’d love to get feedback on the DX and on what features I should add next.

I can’t post links yet, but you can find it on GitHub under mihai-dinculescu/simconnect-sdk and on cratesio as simconnect-sdk.

1 Like