diff --git a/dev-cli/container/src/aolibc/aostdio.c b/dev-cli/container/src/aolibc/aostdio.c index 39f162981..8625bd62e 100644 --- a/dev-cli/container/src/aolibc/aostdio.c +++ b/dev-cli/container/src/aolibc/aostdio.c @@ -15,6 +15,10 @@ // async JS code from C. EM_ASYNC_JS(int, weavedrive_open, (const char* c_filename, const char* mode), { const filename = UTF8ToString(Number(c_filename)); + if (!Module.WeaveDrive) { + return Promise.resolve(null) + } + const drive = Module.WeaveDrive(Module, FS); return await drive.open(filename); }); @@ -24,6 +28,11 @@ EM_ASYNC_JS(int, weavedrive_read, (int fd, int *dst_ptr, size_t length), { return Promise.resolve(await drive.read(fd, dst_ptr, length)); }); +EM_ASYNC_JS(int, weavedrive_close, (int fd), { + const drive = Module.WeaveDrive(Module, FS); + return drive.close(fd); +}); + FILE* fopen(const char* filename, const char* mode) { AO_LOG( "AO: Called fopen: %s, %s\n", filename, mode); int fd = weavedrive_open(filename, mode); @@ -43,6 +52,8 @@ size_t fread(void* ptr, size_t size, size_t nmemb, FILE* stream) { int fclose(FILE* stream) { AO_LOG( "AO: fclose called\n"); + int fd = fileno(stream); + weavedrive_close(fd); return 0; // Returning success, adjust as necessary } @@ -81,4 +92,4 @@ int munmap(void* addr, size_t length) { AO_LOG("AO: munmap called with addr: %p, length: %zu\n", addr, length); return 0; } -*/ \ No newline at end of file +*/ diff --git a/dev-cli/container/src/aolibc/aostdio_old.c b/dev-cli/container/src/aolibc/aostdio_old.c deleted file mode 100644 index 8625bd62e..000000000 --- a/dev-cli/container/src/aolibc/aostdio_old.c +++ /dev/null @@ -1,95 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#if 0 -#define AO_LOG(...) fprintf(stderr, __VA_ARGS__) -#else -#define AO_LOG(...) -#endif - -// WeaveDrive async wrapper functions. These allow us to call the WeaveDrive -// async JS code from C. -EM_ASYNC_JS(int, weavedrive_open, (const char* c_filename, const char* mode), { - const filename = UTF8ToString(Number(c_filename)); - if (!Module.WeaveDrive) { - return Promise.resolve(null) - } - - const drive = Module.WeaveDrive(Module, FS); - return await drive.open(filename); -}); - -EM_ASYNC_JS(int, weavedrive_read, (int fd, int *dst_ptr, size_t length), { - const drive = Module.WeaveDrive(Module, FS); - return Promise.resolve(await drive.read(fd, dst_ptr, length)); -}); - -EM_ASYNC_JS(int, weavedrive_close, (int fd), { - const drive = Module.WeaveDrive(Module, FS); - return drive.close(fd); -}); - -FILE* fopen(const char* filename, const char* mode) { - AO_LOG( "AO: Called fopen: %s, %s\n", filename, mode); - int fd = weavedrive_open(filename, mode); - AO_LOG( "AO: weavedrive_open returned fd: %d\n", fd); - // If we get a file desciptor, we return a FILE*, else 0. - if (!fd) { - return 0; - } - return fdopen(fd, mode); -} - -size_t fread(void* ptr, size_t size, size_t nmemb, FILE* stream) { - int fd = fileno(stream); - weavedrive_read(fd, ptr, size * nmemb); - return nmemb; -} - -int fclose(FILE* stream) { - AO_LOG( "AO: fclose called\n"); - int fd = fileno(stream); - weavedrive_close(fd); - return 0; // Returning success, adjust as necessary -} - -void* realloc(void* ptr, size_t size) { - void* new_ptr = memalign(16, size); - memcpy(new_ptr, ptr, size); - free(ptr); - //AO_LOG("DBG: Realloc called: %p -> %p, size: %zu\n", ptr, new_ptr, size); - return new_ptr; -} - -// Emscripten malloc does not align to 16 bytes correctly, which causes some -// programs that use aligned memory (for example, those that use SIMD...) to -// crash. So we need to use the aligned allocator. -void* malloc(size_t size) { - return memalign(16, size); -} - -int madvise(void* addr, size_t length, int advice) { - AO_LOG("AO: madvise called with addr: %p, length: %zu, advice: %d\n", addr, length, advice); - return 0; -} - -void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset) { - AO_LOG("AO: mmap called with addr: %p, length: %zu, prot: %d, flags: %d, fd: %d, offset: %d\n", addr, length, prot, flags, fd, offset); - // Allocate a buffer that fits with emscripten's normal allignments - void* buffer = memalign(65536, length); - AO_LOG("AO: mmap: Reading from arweave to: %p, length: %zu\n", buffer, length); - weavedrive_read(fd, buffer, length); - AO_LOG("AO: mmap returned: %p\n", buffer); - return buffer; -} - -/* -int munmap(void* addr, size_t length) { - AO_LOG("AO: munmap called with addr: %p, length: %zu\n", addr, length); - return 0; -} -*/ diff --git a/dev-cli/deno.json b/dev-cli/deno.json index eeef2b9f7..e32ef346a 100644 --- a/dev-cli/deno.json +++ b/dev-cli/deno.json @@ -1,5 +1,5 @@ { - "version": "0.1.2", + "version": "0.1.3", "tasks": { "cache": "deno cache --lock=deno.lock --lock-write ./src/mod.js", "build-binaries": "./tools/build.sh", diff --git a/dev-cli/src/commands/exec.js b/dev-cli/src/commands/exec.js new file mode 100644 index 000000000..a77e1646a --- /dev/null +++ b/dev-cli/src/commands/exec.js @@ -0,0 +1,26 @@ +/* global Deno */ + +import { Command } from '../deps.js' +import { VERSION } from '../versions.js' + +export async function build (_, command) { + const pwd = Deno.cwd() + const p = Deno.run({ + cmd: [ + 'docker', + 'run', + '--platform', + 'linux/amd64', + '-v', + `${pwd}:/src`, + `p3rmaw3b/ao:${VERSION.IMAGE}`, + command + ] + }) + await p.status() +} + +export const command = new Command() + .description('Build the Lua Project into WASM') + .arguments('') + .action(build) diff --git a/dev-cli/src/mod.js b/dev-cli/src/mod.js index eedd901d0..f183cd0b9 100644 --- a/dev-cli/src/mod.js +++ b/dev-cli/src/mod.js @@ -11,6 +11,7 @@ import { command as Build } from './commands/build.js' import { command as Publish } from './commands/publish.js' import { command as Spawn } from './commands/spawn.js' import { command as Bundler } from './commands/bundler.js' +import { command as Exec } from './commands/exec.js' const cli = new Command() .name('ao') @@ -24,5 +25,6 @@ const cli = new Command() .command('publish', Publish) .command('spawn', Spawn) .command('bundler', Bundler) + .command('exec', Exec) await cli.parse(Deno.args) diff --git a/dev-cli/src/versions.js b/dev-cli/src/versions.js index f535d4a46..877604b94 100644 --- a/dev-cli/src/versions.js +++ b/dev-cli/src/versions.js @@ -1,5 +1,5 @@ /* eslint-disable */ export const VERSION = { - "CLI": "0.1.2", - "IMAGE": "0.1.1" + "CLI": "0.1.3", + "IMAGE": "0.1.2" } \ No newline at end of file