Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add wasi imports to wasm #36

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@picovoice/web-utils",
"version": "1.4.1",
"version": "1.4.2",
"description": "Picovoice web utility functions",
"author": "Picovoice",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function arrayBufferToStringAtIndex(
indexEnd++;
}
const utf8decoder = new TextDecoder('utf-8');
return utf8decoder.decode(arrayBuffer.subarray(indexStart, indexEnd));
return utf8decoder.decode(arrayBuffer.slice(indexStart, indexEnd));
mrrostam marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ export type pv_free_type = (ptr: number) => Promise<void>;
* @param wasm The wasm file in base64 string or stream to public path (i.e. fetch("file.wasm")) to initialize.
* @param pvError The PvError object to store error details.
* @param additionalImports Extra WASM imports.
* @param wasiImports Additional WASI imports.
* @returns An object containing the exported functions from WASM.
*/
export async function buildWasm(
memory: WebAssembly.Memory,
wasm: string | Promise<Response>,
pvError?: PvError,
additionalImports: Record<string, any> = {},
wasiImports: Record<string, any> = {}
): Promise<any> {
const setInt = (address: number, value: number) => {
const memoryBufferInt32 = new Int32Array(memory.buffer);
Expand Down Expand Up @@ -404,8 +406,11 @@ export async function buildWasm(
pv_file_seek_wasm: pvFileSeekWasm,
pv_file_tell_wasm: pvFileTellWasm,
pv_file_remove_wasm: pvFileRemoveWasm,
...additionalImports
...additionalImports,
},
wasi: {
...wasiImports,
}
};

let instance: WebAssembly.Instance;
Expand Down
Loading