diff --git a/deno_test_wasm/test_wasm/Cargo.lock b/deno_test_wasm/test_wasm/Cargo.lock new file mode 100644 index 0000000..746709d --- /dev/null +++ b/deno_test_wasm/test_wasm/Cargo.lock @@ -0,0 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "test_wasm" +version = "0.1.0" diff --git a/deno_test_wasm/test_wasm/Cargo.toml b/deno_test_wasm/test_wasm/Cargo.toml new file mode 100644 index 0000000..5c9cc93 --- /dev/null +++ b/deno_test_wasm/test_wasm/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "test_wasm" +version = "0.1.0" +authors = ["Hatter Jiang "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type =["cdylib"] + +[dependencies] + +[profile.release] +lto = true diff --git a/deno_test_wasm/test_wasm/src/lib.rs b/deno_test_wasm/test_wasm/src/lib.rs new file mode 100644 index 0000000..74ef50e --- /dev/null +++ b/deno_test_wasm/test_wasm/src/lib.rs @@ -0,0 +1,14 @@ +use std::ffi::CString; +use std::os::raw::c_char; + +#[no_mangle] +pub extern "C" fn malloc(len: usize) -> *mut c_char { + let s = unsafe { CString::from_vec_unchecked(Vec::with_capacity(len)) }; + s.into_raw() +} + +pub extern "C" fn to_uppercase(ptr: *mut c_char) -> *mut c_char { + let s = unsafe { CString::from_raw(ptr) }; + let s2 = CString::new(s.to_string_lossy().to_uppercase()).unwrap(); + s2.into_raw() +} \ No newline at end of file