Skip to content

Commit

Permalink
fixed AS passing pointers using correct runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
konsumer committed Oct 19, 2024
1 parent 8424a38 commit 73ea5ac
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
8 changes: 3 additions & 5 deletions cart/as/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ await writeFile('build/tmp.ts', (await readFile('null0.ts')) + '\n// user-code:\

const { error, stdout, stderr, stats } = await asc.main([
'build/tmp.ts',
// '--lowMemoryLimit',
'--stackSize', '2097152',
'--runtime', 'stub',
'--runtime', 'minimal',
'--config', './node_modules/@assemblyscript/wasi-shim/asconfig.json',
'--optimizeLevel', '3',
'--shrinkLevel', '2',
Expand All @@ -33,12 +31,12 @@ await unlink('build/tmp.ts')

if (error) {
console.error(stderr.toString())
}else {
} else {
console.log(`Creating build/${npm_package_name}.null0`)
await copy('src/assets', `build/${npm_package_name}/assets`)
const output = createWriteStream(`build/${npm_package_name}.null0`)
archive.pipe(output)
archive.directory(`build/${npm_package_name}`, false)
await archive.finalize()
await copy(`build/${npm_package_name}.null0`, `../../build/cart/${npm_package_name}.null0`)
}
}
2 changes: 1 addition & 1 deletion cart/as/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function load(): void {

const t = file_read("assets/cyber.txt")
trace(`WASM ArrayBuffer size: ${t.byteLength.toString()}`)
trace(String.UTF8.decode(t))
trace(String.UTF8.decode(t, false))
}

// called on every frame
Expand Down
10 changes: 4 additions & 6 deletions null0_api/src/null0_api_wamr.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@ void params_from_sfx_to_wasm(SfxParams* s, SfxParams* sOut) {
}

// Read a file from cart (or local persistant)
// currently having issues in AS, so maybe try https://github.com/bytecodealliance/wasm-micro-runtime/issues/2751
static void wamr_null0_file_read(wasm_exec_env_t exec_env, char* filename, uint32_t* bytesRead, char* retBytes) {
char* bytesHost = null0_file_read(filename, bytesRead);
memcpy(retBytes, bytesHost, *bytesRead);
printf("HOST bytesRead: %u\n", *bytesRead);
free(bytesHost);
// ($**)
static void wamr_null0_file_read(wasm_exec_env_t exec_env, char* filename, uint32_t* wasmBytesRead, char* wasmRetBytes) {
char* hostBytes = null0_file_read(filename, wasmBytesRead);
memcpy(wasmRetBytes, hostBytes, *wasmBytesRead);
}

// Get the user's writable dir (where file writes or appends go)
Expand Down

0 comments on commit 73ea5ac

Please sign in to comment.