Skip to content

Instantly share code, notes, and snippets.

@bjfish
Created February 24, 2019 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjfish/99138121bf91a82331aa5a24a696cd62 to your computer and use it in GitHub Desktop.
Save bjfish/99138121bf91a82331aa5a24a696cd62 to your computer and use it in GitHub Desktop.
Hello World Rust Wasm Sample App
// Define a function that is imported into the module.
// By default, the "env" namespace is used.
extern "C" {
fn print_str(ptr: *const u8, len: usize);
}
// Define a string that is accessible within the wasm
// linear memory.
static HELLO: &'static str = "Hello, World!";
// Export a function named "hello_wasm". This can be called
// from the embedder!
#[no_mangle]
pub extern fn hello_wasm() {
// Call the function we just imported and pass in
// the offset of our string and its length as parameters.
unsafe {
print_str(HELLO.as_ptr(), HELLO.len());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment