Creating custom nodes with Rust

Hi,
I recently learned Rust and want to re-write my old custom nodes using Rust. I know that Rust compiler can output LLVM bitcode and I believe I could investigate more on that topic but I’d need a little help with some Vuo-specific requirement for the output bitcode:

  • what LLVM bitcode symbols should be exposed?
  • what should be the names of them?
  • which parts of the attached *.c source code are needed by Vuo to open & use a custom node?

EDIT: I managed to compile example node in Rust to bitcode with exported symbols just to mimic some SDK example node bitcode, with these symbols exported:

---------------- T _VuoLog_initModuleName
---------------- D _VuoLog_moduleName
---------------- D _dumski_rust_simple__moduleDetails
---------------- T _dumski_rust_simple__nodeEvent

But trying to install this bitcode in Vuo results with this error:

readModuleFromFile():1759  Error: Couldn't load module 'dumski.rust.simple' into arm64 environment: Couldn't parse bitcode file: Invalid record.

… and no further info. Native Vuo nodes have these symbols exposed:

---------------- t _VuoLog_initModuleName
---------------- d _VuoLog_moduleName
---------------- t _VuoPoint2d_distance            # this is output port
                 w _basename_r
                 U _dladdr
                 U _malloc
                 U _sqrtf
                 U _strlen
                 U _strncmp
                 U _strrchr
---------------- D _vuo_point_distance__moduleDetails
---------------- T _vuo_point_distance__nodeEvent      # this is input port

Which ones are mandatory to export from custom node? Or maybe there’s somthing else I should export to allow Vuo accept my bitcode?

Cheers, Teo

But trying to install this bitcode in Vuo results with this error:

That failure is actually happening before Vuo even gets to the point where it’s looking for exposed symbols. The “Invalid record” error comes from LLVM (llvm::parseBitcodeFile). The problem is that recent versions of the Rust compiler generate LLVM bitcode that can only be read by recent versions of LLVM. Since we hadn’t had any particular reason to update the LLVM version in Vuo (and updating is time-consuming), it’s still on LLVM 5.0.2.

You might be able to work around the problem by using an older version of the Rust compiler. Based on when Rust updated from LLVM 5 to 6, maybe try Rust 1.32 or earlier.

what LLVM bitcode symbols should be exposed?

The node class would need to expose moduleDetails (global variable) to indicate that it’s a Vuo module and nodeEvent or nodeInstanceEvent (function) to indicate that it’s a node class. Optionally, these can be prefixed with the node class name (vuo_point_distance__ in your example).

VuoInputData, VuoOutputData, and other macros on function parameters use attribute((annotate(…))), which gets compiled down to @llvm.var.annotation calls in the bitcode. So you’d somehow need to do the same for your Rust node classes.

which parts of the attached *.c source code are needed by Vuo to open & use a custom node?

I’m not seeing an attachment, but vuo.event.share.c would be pretty close to a minimal node class.

One other suggestion: you might want to look at the flags that the Vuo compiler passes to Clang when compiling a module.