Additionally export malloc & free #24446
-
Hey, I've first tried to extend the example by implementing loading a typeface. #[unsafe(no_mangle)]
pub extern "C" fn load_typeface(ptr: *const u8, len: usize) {
let data = unsafe { std::slice::from_raw_parts(ptr, len) };
println!("font buffer size: {} bytes", len);
println!("font first few bytes: {:?}", &data);
let typeface_bytes = skia_safe::Data::new_copy(data);
let font_manager = skia_safe::FontMgr::new();
let skia_typeface = font_manager.new_from_data(&typeface_bytes, None);
let typeface = skia_typeface.unwrap();
} The function call in JavaScript: const fontRes = await fetch("/web/comic-sans-ms.ttf");
const fontData = await fontRes.arrayBuffer();
const ptr = RustSkia._malloc(fontData.byteLength);
RustSkia.HEAPU8.set(new Uint8Array(fontData), ptr);
RustSkia._load_typeface(ptr, fontData.byteLength);
RustSkia._free(ptr); Here I hit my first roadblock, as
Now my typeface loading works but the init function of the example did break with the following error:
When explicitly exporting malloc and my functions using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
No, there is currently way to make settings like Are you claiming that when you don't specify your list of (Also FYI a simpler way to do EXPORTED_FUNCTIONS and EXPORTED_RUNTIME_METHODS is to just use a simple comma separated list: e.g. |
Beta Was this translation helpful? Give feedback.
-
As I said my test Project was based on the wasm-example of the skia-safe project. But I already found a workaround by simply implementing my own functions for allocating and freeing memory in rust. |
Beta Was this translation helpful? Give feedback.
As I said my test Project was based on the wasm-example of the skia-safe project.
The example does work but does not support malloc & free and does not have any entry in the
EXPORTED_FUNCTIONS
.When I add malloc and free to the
EXPORTED_FUNCTIONS
, theinit
function of the example fails with the error I posted.But I already found a workaround by simply implementing my own functions for allocating and freeing memory in rust.
Therefore I no longer need to add malloc & free to the
EXPORTED_FUNCTIONS
and everything works.