How to set up WASM Rust


#1

I want to try both Haxe and wasm Rust but I am having some trouble setting up wasm Rust.

I have alreayd installead wasm via cargo cargo install wasm-pack on cmd (using Windows), I have already created a trait for the object and I have linked a wasm file to the object as shown.

Now what do I do from here?

By the way please don’t tell me I have to type this much stuff.

extern {
  fn notify_on_update(f: extern fn() -> ()) -> ();
  fn get_object(name: *const i8) -> i32;
  fn set_transform(object: i32, x: f32, y: f32, z: f32, rx: f32, ry: f32, rz: f32, sx: f32, sy: f32, sz: f32) -> ();
}

#[no_mangle]
pub extern "C" fn update() -> () {
  unsafe {
    let name = std::ffi::CString::new("Cube").unwrap();
    let object = get_object(name.as_ptr());
    static mut rot: f32 = 0.1;
    rot += 0.01;
    set_transform(object, 0.0, 0.0, 0.0, 0.0, 0.0, rot, 1.0, 1.0, 1.0);
  }
}

#[no_mangle]
pub extern "C" fn main() -> i32 {
  unsafe {
    notify_on_update(update);
  }
  return 0;
}

just to rotated the cube?


WebAssembly Rust
#2

Yes you have. There are not Native rust bindings, so your actually are calling C++ from rust, and the requires wiring external bindings. With more includes and internal stuff usage, even more. Rust bindgen lib can a bit automate that, but it does really work well only with pure C. And if you will need to return an object from C++ it will be become a nightmare (in some situations have to do garbage cleaning on your side). Also this way you have to use unsafe blocks, so you lose the Rust safety super-powers. And this is not the END :D. I know this, as I have been using Rust for years…, working also with ex-tern C bindings and it’s not a fun ride. Right now this Rust usage, in my opinion, is more like a neat experiment. Do not plan big things with it :stuck_out_tongue:


#3

If you really love Rust and game is aimed for HTML5, you can write some STATIC calculating that needs to be fast, otherwise stay away from it :stuck_out_tongue:


#4

Damn, is it possible to be as simplified as Haxe in terms of the programming curve?


#5

Short answer is no. Unless someone create haxe backend for rust.